Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 new bots #43

Merged
merged 3 commits into from Jul 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bots/borg.py
Expand Up @@ -23,7 +23,7 @@ def get_bots_by_name():
if name == "ClientBase":
continue
elif getattr(value, 'name', None) is not None and \
inspect.isclass(value):
inspect.isclass(value) and not issubclass(value, BorgClient):
bots[value.name] = value()
return bots

Expand Down
27 changes: 27 additions & 0 deletions bots/cylon.py
@@ -0,0 +1,27 @@
from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor

import spacecraft

factory = ClientFactory()

class CylonClient(spacecraft.server.ClientBase):
name = 'cylon'

def __init__(self):
self.resurrected = False

def messageReceived(self, message):
health = message.get('status', {}).get('health', 100)
if health <= 0 and not self.resurrected:
self.resurrected = True
connect_bot()


def connect_bot():
factory.protocol = CylonClient
reactor.connectTCP('localhost', 11106, factory)

if __name__ == '__main__':
reactor.callWhenRunning(connect_bot)
reactor.run()
30 changes: 30 additions & 0 deletions bots/cylon_borg.py
@@ -0,0 +1,30 @@
from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor

from borg import BorgClient

factory = ClientFactory()

class CylonClient(BorgClient):
name = 'cylon borg'

def __init__(self):
BorgClient.__init__(self)
self.resurrected = False

def messageReceived(self, message):
health = message.get('status', {}).get('health', 100)
if health <= 0 and not self.resurrected:
self.resurrected = True
connect_bot()
else:
BorgClient.messageReceived(self, message)


def connect_bot():
factory.protocol = CylonClient
reactor.connectTCP('localhost', 11106, factory)

if __name__ == '__main__':
reactor.callWhenRunning(connect_bot)
reactor.run()