Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #43 from ricardokirkner/master

2 new bots
  • Loading branch information...
commit 7d79746f54695c8d9599e3881bc00a1280cb1254 2 parents 6bcb333 + 94cc4aa
Anthony Lenton elachuni authored
Showing with 58 additions and 1 deletion.
  1. +1 −1  bots/borg.py
  2. +27 −0 bots/cylon.py
  3. +30 −0 bots/cylon_borg.py
2  bots/borg.py
View
@@ -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
27 bots/cylon.py
View
@@ -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 bots/cylon_borg.py
View
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.