41 lines
1.2 KiB
Python
41 lines
1.2 KiB
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 not choices:
|
|
say(event.target if event.target.startswith("#") else event.hostmask.nick,("{}: ".format(event.hostmask.nick) if event.target.startswith("#") else " ".strip())+f"Usage: {BOT.prefix}choose <choices>; use double quotes if a choice has spaces")
|
|
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)
|