2020-05-11 20:00:46 +00:00
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 )
2021-05-13 18:32:14 +00:00
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 " )
2020-05-11 20:00:46 +00:00
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 )