Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

2 new bots #43

Merged
merged 3 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 8, 2012
  1. @ricardokirkner

    added cylon bot

    ricardokirkner authored
  2. @ricardokirkner
  3. @ricardokirkner

    added cylon borg bot

    ricardokirkner authored
This page is out of date. Refresh to see the latest.
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
View
2  bots/borg.py
@@ -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
View
27 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()
View
30 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()
Something went wrong with that request. Please try again.