Download:
child 18:7cf8ac0d3ebc
parent 16:767c4ae49fc0
17:20b47f01a71d
Anton Shestakov <av6@dwimlabs.net>, Sun, 22 May 2016 21:48:18 +0800
rollbot: flip command for flipping a coin

1 файлов изменено, 26 вставок(+), 0 удалений(-) [+]
rollbot.py file | annotate | diff | comparison | revisions
--- a/rollbot.py Thu May 19 21:08:43 2016 +0800
+++ b/rollbot.py Sun May 22 21:48:18 2016 +0800
@@ -56,6 +56,31 @@
return '(%s) = %d' % (' + '.join('%d' % r for r in rolls), total)
+class Flip(Command):
+ name = 'flip'
+
+ def usage(self):
+ return '%s or %s <1st-option>[ or] <2nd-option>' % (self.name, self.name)
+
+ def respond(self, words, message):
+ if len(words) == 1:
+ option = self.flip(('heads', 'tails'))
+ elif len(words) == 3:
+ option = self.flip(words[1:])
+ elif len(words) == 4 and words[2].lower() == 'or':
+ option = self.flip((words[1], words[3]))
+ else:
+ return '%s usage: %s' % (self.name, self.usage())
+
+ return self.format(option)
+
+ def flip(self, options):
+ return random.choice(options)
+
+ def format(self, option):
+ return option
+
+
class Help(Command):
name = 'help'
@@ -86,6 +111,7 @@
self.commands = {}
self.add_command(Roll)
+ self.add_command(Flip)
self.add_command(Help)
self.add_event_handler('session_start', self.start)