[rnd] New command to choice between cmd

This commit is contained in:
nemunaire 2015-10-14 06:47:01 +02:00
parent 7400957ac2
commit 089823d884

View File

@ -1,17 +1,20 @@
# coding=utf-8
"""Help to make choice""" """Help to make choice"""
import random # PYTHON STUFFS #######################################################
import random
import shlex
from nemubot import context
from nemubot.exception import IRCException from nemubot.exception import IRCException
from nemubot.hooks import hook from nemubot.hooks import hook
from nemubot.message import Command
nemubotversion = 3.4
from more import Response from more import Response
# MODULE INTERFACE ####################################################
@hook("cmd_hook", "choice") @hook("cmd_hook", "choice")
def cmd_choice(msg): def cmd_choice(msg):
if not len(msg.args): if not len(msg.args):
@ -20,3 +23,17 @@ def cmd_choice(msg):
return Response(random.choice(msg.args), return Response(random.choice(msg.args),
channel=msg.channel, channel=msg.channel,
nick=msg.nick) nick=msg.nick)
@hook("cmd_hook", "choicecmd")
def cmd_choice(msg):
if not len(msg.args):
raise IRCException("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))]