Skip to content

Commit

Permalink
Update dice.py and reload.py to the new decorator format.
Browse files Browse the repository at this point in the history
Dice.py is an example of how commands work. Rules work similarly.
Reload.py is an example of how the new the new nickname_command works.
  • Loading branch information
ari-koivula committed May 29, 2013
1 parent fe330cc commit 32538dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
15 changes: 11 additions & 4 deletions dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

from random import randint, seed, choice
from willie.modules.calc import calculate
import willie.module
import re

seed()


@willie.module.command("roll")
@willie.module.command("dice")
@willie.module.command("d")
@willie.module.priority("medium")
def dice(willie, trigger):
"""
.dice <formula> - Rolls dice using the XdY format, also does basic math and
Expand Down Expand Up @@ -74,8 +79,6 @@ def dice(willie, trigger):
else:
willie.reply('You roll ' + trigger.group(2) + ': ' + full_string + ' = '
+ result)
dice.commands = ['roll', 'dice', 'd']
dice.priority = 'medium'


def rollDice(diceroll):
Expand All @@ -91,6 +94,11 @@ def rollDice(diceroll):
randint(1, size))[randint(0, 9)])
return sorted(result) # returns a set of integers.


@willie.module.command("choice")
@willie.module.command("ch")
@willie.module.command("choose")
@willie.module.priority("medium")
def choose(willie, trigger):
"""
.choice option1|option2|option3 - Makes a difficult choice easy.
Expand All @@ -100,8 +108,7 @@ def choose(willie, trigger):
choices = re.split('[\|\\\\\/]', trigger.group(2))
pick = choice(choices)
return willie.reply('Your options: %s. My choice: %s' % (', '.join(choices), pick))
choose.commands = ['choice', 'ch', 'choose']
choose.priority = 'medium'


if __name__ == '__main__':
print __doc__.strip()
Expand Down
18 changes: 9 additions & 9 deletions reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import os.path
import time
import imp
import willie.irc
import willie.module
import subprocess


@willie.module.nickname_command("reload")
@willie.module.priority("low")
@willie.module.thread(False)
def f_reload(willie, trigger):
"""Reloads a module, for use by admins only."""
if not trigger.admin:
Expand Down Expand Up @@ -51,10 +54,7 @@ def f_reload(willie, trigger):
willie.bind_commands()

willie.reply('%r (version: %s)' % (module, modified))
f_reload.name = 'reload'
f_reload.rule = ('$nick', ['reload'], r'(.+)?')
f_reload.priority = 'low'
f_reload.thread = False


if sys.version_info >= (2, 7):
def update(willie, trigger):
Expand All @@ -74,6 +74,9 @@ def update(willie, trigger):
update.rule = ('$nick', ['update'], r'(.+)')


@willie.module.nickname_command("load")
@willie.module.priority("low")
@willie.module.thread(False)
def f_load(willie, trigger):
"""Loads a module, for use by admins only."""
if not trigger.admin:
Expand Down Expand Up @@ -107,10 +110,7 @@ def f_load(willie, trigger):
willie.bind_commands()

willie.reply('%r (version: %s)' % (module, modified))
f_load.name = 'load'
f_load.rule = ('$nick', ['load'], r'(.+)?')
f_load.priority = 'low'
f_load.thread = False


if __name__ == '__main__':
print __doc__.strip()

0 comments on commit 32538dc

Please sign in to comment.