Download:
child 31:c96a5bc0ffa3
parent 29:c04a4faec835
30:f21f5ee3e32c
Anton Shestakov <av6@dwimlabs.net>, Wed, 04 Apr 2018 00:09:27 +0800
rollbot: add another command: snack

1 файлов изменено, 18 вставок(+), 0 удалений(-) [+]
rollbot.py file | annotate | diff | comparison | revisions
--- a/rollbot.py Wed Jul 20 00:32:32 2016 +0800
+++ b/rollbot.py Wed Apr 04 00:09:27 2018 +0800
@@ -131,6 +131,23 @@
return '%s usage: %s' % (self.name, self.usage())
+class Snack(Command):
+ name = 'snack'
+ action = ('eats', 'devours', 'swallows', 'gorges on', 'feasts upon', 'gobbles up')
+ food = ('banana', 'cookie', 'durian', 'fig', 'garlic', 'kiwi', 'lemon', 'mango', 'pomegranate', 'tamarind')
+
+ def usage(self):
+ return '{t}%s{/t} {i}or{/i} {t}%s <snack>{/t}' % (self.name, self.name)
+
+ def respond(self, words, message):
+ if len(words) == 1:
+ return '/me %s a %s' % (random.choice(self.action), random.choice(self.food))
+ elif len(words) >= 2:
+ return '/me eats a %s' % ' '.join(words[1:])
+ else:
+ return '%s usage: %s' % (self.name, self.usage())
+
+
class RollBot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, nick, prefix):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
@@ -142,6 +159,7 @@
self.add_command(Roll)
self.add_command(Flip)
self.add_command(Help)
+ self.add_command(Snack)
self.add_event_handler('session_start', self.start)
self.add_event_handler('message', self.message)