<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> import random <EOL> from pyaib . plugins import keyword , plugin_class <EOL> @ plugin_class <EOL> class Jokes ( object ) : <EOL> def __init__ ( self , irc_context , config ) : <EOL> self . r = Roulette ( ) <EOL> self . ballresp = config . ballresp <EOL> print ( "<STR_LIT>" ) <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . nosubs <EOL> @ keyword . autohelp_noargs <EOL> def roulette_root ( self , irc_c , msg , trigger , args , kargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . sub ( '<STR_LIT>' ) <EOL> @ keyword . autohelp <EOL> def roulette_spin ( self , irc_c , msg , trigger , args , kargs ) : <EOL> '''<STR_LIT>''' <EOL> if self . r . fire ( msg . nick ) : <EOL> msg . reply ( "<STR_LIT>" % ( msg . nick , Roulette . unluckyMsg ( ) ) ) <EOL> else : <EOL> msg . reply ( "<STR_LIT>" % ( msg . nick , Roulette . luckyMsg ( ) ) ) <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . sub ( '<STR_LIT>' ) <EOL> @ keyword . autohelp <EOL> def roulette_reload ( self , irc_c , msg , trigger , args , kargs ) : <EOL> '''<STR_LIT>''' <EOL> self . r . reload ( ) <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . sub ( '<STR_LIT>' ) <EOL> @ keyword . autohelp <EOL> def roulette_stats ( self , irc_c , msg , trigger , args , kargs ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> stats = self . r . getGlobalStats ( ) <EOL> msg . reply ( "<STR_LIT>" <EOL> % ( stats [ '<STR_LIT>' ] , stats [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> stats = self . r . getStats ( args [ <NUM_LIT:0> ] ) <EOL> if stats : <EOL> msg . reply ( "<STR_LIT>" <EOL> % ( args [ <NUM_LIT:0> ] , stats [ '<STR_LIT>' ] , stats [ '<STR_LIT>' ] ) ) <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . sub ( '<STR_LIT>' ) <EOL> @ keyword . autohelp <EOL> def roulette_clearstats ( self , irc_c , msg , trigger , args , kargs ) : <EOL> '''<STR_LIT>''' <EOL> self . r . clear ( ) <EOL> @ keyword ( '<STR_LIT>' ) <EOL> @ keyword . autohelp_noargs <EOL> def magic_8ball ( self , irc_c , msg , trigger , args , kargs ) : <EOL> """<STR_LIT>""" <EOL> if not msg . message . endswith ( '<STR_LIT:?>' ) : <EOL> msg . reply ( "<STR_LIT>" % <EOL> msg . nick ) <EOL> return <EOL> msg . reply ( "<STR_LIT>" % ( msg . nick , random . choice ( self . ballresp ) ) ) <EOL> class Roulette ( object ) : <EOL> luckyQuotes = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> unluckyQuotes = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def __init__ ( self ) : <EOL> self . loaded = False <EOL> self . fired = False <EOL> self . chamber = None <EOL> self . position = <NUM_LIT:0> <EOL> self . stats = { } <EOL> @ staticmethod <EOL> def luckyMsg ( ) : <EOL> return random . choice ( Roulette . luckyQuotes ) <EOL> @ staticmethod <EOL> def unluckyMsg ( ) : <EOL> return random . choice ( Roulette . unluckyQuotes ) <EOL> def clear ( self ) : <EOL> self . stats = { } <EOL> def reload ( self ) : <EOL> self . chamber = random . choice ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> self . position = <NUM_LIT:0> <EOL> self . loaded = True <EOL> def getStats ( self , nick ) : <EOL> if nick in self . stats : <EOL> return self . stats [ nick ] <EOL> def getGlobalStats ( self ) : <EOL> stats = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> for name in self . stats . keys ( ) : <EOL> stats [ '<STR_LIT>' ] += self . stats [ name ] [ '<STR_LIT>' ] <EOL> stats [ '<STR_LIT>' ] += self . stats [ name ] [ '<STR_LIT>' ] <EOL> return stats <EOL> def fire ( self , nick ) : <EOL> if not self . loaded : <EOL> self . reload ( ) <EOL> if nick not in self . stats : <EOL> self . stats [ nick ] = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> if ( self . position == self . chamber ) : <EOL> self . loaded = False <EOL> self . fired = True <EOL> self . stats [ nick ] [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> return True <EOL> else : <EOL> self . position += <NUM_LIT:1> <EOL> self . stats [ nick ] [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> return False </s>
