39 lines
1016 B
Python
39 lines
1016 B
Python
|
import plugin, random
|
||
|
from bot import IRCLine
|
||
|
|
||
|
BOT = None
|
||
|
|
||
|
def say(target,msg):
|
||
|
BOT.socket.send(IRCLine("PRIVMSG",target,":"+msg))
|
||
|
|
||
|
RNG = random.SystemRandom()
|
||
|
|
||
|
RESPONSES = ["I dunno, I think I'll go with \"{}\".","Hmm, it's a hard choice, but \"{}\".","Hmm... \"{}\". Hands down."]
|
||
|
|
||
|
def choose(event):
|
||
|
choices = []
|
||
|
s = ""
|
||
|
quote = False
|
||
|
for choice in event.parts:
|
||
|
if quote:
|
||
|
s+=" "+choice
|
||
|
if choice.endswith('"'):
|
||
|
quote = False
|
||
|
choices.append(s.strip('"'))
|
||
|
s = ""
|
||
|
elif choice.startswith('"'):
|
||
|
quote = True
|
||
|
s+=choice
|
||
|
else:
|
||
|
choices.append(choice)
|
||
|
if sorted([x.lower() for x in choices])==list("dl"):
|
||
|
choice = "l" if "l" in choices else "L"
|
||
|
else:
|
||
|
choice = RNG.choice(choices)
|
||
|
say(event.target if event.target.startswith("#") else event.hostmask.nick,("{}: ".format(event.hostmask.nick) if event.target.startswith("#") else " ".strip())+"{}".format(RNG.choice(RESPONSES).format(choice)))
|
||
|
|
||
|
def register(bot):
|
||
|
global BOT
|
||
|
BOT=bot
|
||
|
bot.event_manager.on("command_choose",choose)
|