Skip to content

Commit

Permalink
add random heads or tails / dice command (close #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
RouxRC committed Jan 4, 2016
1 parent a8a9897 commit 59a8837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion LIST_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
# Other commands...
* Pad & Title available to anyone
* FuckOff/ComeBack & SetPad available only to GLOBAL_USERS and chan's USERS
* **Exclude regexp :** `'(fuckoff|comeback|.*pad|title)'`
* **Exclude regexp :** `'(fuckoff|comeback|.*pad|title|dice)'`
* **List :**

+ `fuckoff [<N>]`
Expand All @@ -278,6 +278,10 @@

> Prints the title of the webpage at &lt;url&gt;.
+ `dice [<N>]`

> Let me toss heads or tails, or give a random number between 1 and &lt;N&gt; if given.
# Admin commands
* AddAuth available only to GLOBAL_USERS and chan's USERS
* Restart available only to GLOBAL_USERS
Expand Down
15 changes: 11 additions & 4 deletions gazouilleur/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,15 @@ def command_showthread(self, rest, channel=None, nick=None):
tweets[curid]["text"] = yield self._format_tweet(tweet, light=True)
if not tweets:
returnD("[twitter] ERROR 404: Cannot find that tweet.")
returnD("\n".join(self.convtree(tweets, root)))
returnD("\n".join(self._convtree(tweets, root)))

def convtree(self, tree, root):
def _convtree(self, tree, root):
if "text" not in tree[root]:
return []
conv = [tree[root]['text']]
tree[root]['repls'].sort()
for repl in tree[root]['repls']:
conv += ["-> %s" % t for t in self.convtree(tree, repl)]
conv += ["-> %s" % t for t in self._convtree(tree, repl)]
return conv

def command_stats(self, rest, channel=None, nick=None):
Expand Down Expand Up @@ -1448,7 +1448,7 @@ def command_cancel(self, rest, channel=None, *args):
# -----------------
## Pad & Title available to anyone
## FuckOff/ComeBack & SetPad available only to GLOBAL_USERS and chan's USERS
## Exclude regexp : '(fuckoff|comeback|.*pad|title)'
## Exclude regexp : '(fuckoff|comeback|.*pad|title|dice)'

def command_fuckoff(self, minutes, channel=None, nick=None):
"""fuckoff [<N>] : Tells me to shut up for the next <N> minutes (defaults to 5)./AUTH"""
Expand Down Expand Up @@ -1502,6 +1502,13 @@ def _parse_pagetitle(self, page_contents, url):
title = title.encode('utf-8')
return '%s -- "%s"' % (url, title)

def command_dice(self, rest, *args):
"""dice [<N>] : Let me toss heads or tails, or give a random number between 1 and <N> if given."""
maxval = safeint(rest)
if not maxval:
return "Heads!" if random.randint(0, 1) else "Tails!"
return random.randint(1, maxval)


# Admin commands
# --------------
Expand Down

0 comments on commit 59a8837

Please sign in to comment.