nemubot/modules/rnd.py

40 lines
1.1 KiB
Python
Raw Normal View History

2014-08-27 23:39:31 +00:00
"""Help to make choice"""
# PYTHON STUFFS #######################################################
2013-01-07 11:22:07 +00:00
import random
import shlex
2013-01-07 11:22:07 +00:00
from nemubot import context
from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.message import Command
2013-01-07 11:22:07 +00:00
from more import Response
2014-11-13 01:51:49 +00:00
# MODULE INTERFACE ####################################################
@hook("cmd_hook", "choice")
2013-01-07 11:22:07 +00:00
def cmd_choice(msg):
2015-07-10 21:09:54 +00:00
if not len(msg.args):
raise IMException("indicate some terms to pick!")
2015-07-10 21:09:54 +00:00
return Response(random.choice(msg.args),
channel=msg.channel,
nick=msg.nick)
@hook("cmd_hook", "choicecmd")
2015-10-30 20:10:06 +00:00
def cmd_choicecmd(msg):
if not len(msg.args):
raise IMException("indicate some command to pick!")
choice = shlex.split(random.choice(msg.args))
return [x for x in context.subtreat(Command(choice[0][1:],
choice[1:],
to_response=msg.to_response,
frm=msg.frm,
server=msg.server))]