<s> """<STR_LIT>""" <EOL> import sys <EOL> import json <EOL> import inspect <EOL> import hashlib <EOL> import logging <EOL> import threading <EOL> import urllib . error <EOL> import urllib . parse <EOL> import urllib . request <EOL> try : <EOL> import sleekxmpp <EOL> except ImportError : <EOL> logging . getLogger ( __name__ ) . fatal ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> try : <EOL> import dns <EOL> except ImportError : <EOL> logging . getLogger ( __name__ ) . fatal ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . WARNING ) <EOL> def botcommand ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def decorate ( function , hidden = False , admin = False , name = None , need_arg = False ) : <EOL> function . _zxLoLBoT_command = True <EOL> function . _zxLoLBoT_command_name = name or function . __name__ <EOL> function . _zxLoLBoT_command_admin = admin <EOL> function . _zxLoLBoT_command_hidden = hidden <EOL> function . _zxLoLBoT_command_need_arg = need_arg <EOL> return function <EOL> if args : <EOL> return decorate ( args [ <NUM_LIT:0> ] , ** kwargs ) <EOL> else : <EOL> return lambda function : decorate ( function , ** kwargs ) <EOL> class zxLoLBoT ( ) : <EOL> def __init__ ( self , username , password , region = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> self . xmpp = sleekxmpp . ClientXMPP ( username + "<STR_LIT>" , "<STR_LIT>" + password ) <EOL> self . server = '<STR_LIT>' <EOL> self . regions = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> self . port = <NUM_LIT> <EOL> self . username = username <EOL> self . password = password <EOL> self . riot_api_key = None <EOL> self . region = region <EOL> self . recently_added = [ ] <EOL> self . friends = [ ] <EOL> self . friends_online = [ ] <EOL> self . status = { } <EOL> self . admins = [ ] <EOL> self . help_command = True <EOL> self . commands = { } <EOL> self . command_prefix = None <EOL> self . summoner_ids_to_name = { } <EOL> self . logger = logging . getLogger ( __name__ ) <EOL> self . not_admin_message = None <EOL> self . someone_added_message = "<STR_LIT>" <EOL> self . someone_online_message = None <EOL> self . invalid_command_message = None <EOL> self . need_arg_message = "<STR_LIT>" <EOL> self . room_invite_message = "<STR_LIT>" <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_presence_unsubscribe ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_presence_subscribe ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_failed_auth ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_got_offline ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_got_online ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_start ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_disconnected ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT:message>" , self . on_xmpp_message ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , self . on_xmpp_roster_update , disposable = True ) <EOL> self . xmpp . add_event_handler ( "<STR_LIT>" , None ) <EOL> if region . upper ( ) not in self . regions : <EOL> self . logger . critical ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( self . regions . keys ( ) ) + "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> for name , value in inspect . getmembers ( self ) : <EOL> if callable ( value ) and hasattr ( value , "<STR_LIT>" ) : <EOL> name = value . _zxLoLBoT_command_name <EOL> if self . command_prefix : <EOL> name = self . command_prefix + name <EOL> self . commands [ name ] = value <EOL> self . logger . debug ( "<STR_LIT>" + name ) <EOL> def on_xmpp_roster_update ( self , roster ) : <EOL> """<STR_LIT>""" <EOL> for item in roster [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> if item not in self . friends : <EOL> self . friends . append ( self . jid_to_summoner_id ( item ) ) <EOL> if self . friends : <EOL> self . fire_event ( "<STR_LIT>" , friends = self . friends ) <EOL> def on_xmpp_presence_subscribe ( self , presence ) : <EOL> """<STR_LIT>""" <EOL> self . recently_added . append ( str ( presence [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> summoner_id = self . jid_to_summoner_id ( presence [ "<STR_LIT>" ] ) <EOL> if self . riot_api_key : <EOL> if summoner_id not in self . summoner_ids_to_name : <EOL> self . summoner_ids_to_name [ summoner_id ] = self . summoner_id_to_name ( summoner_id ) <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) , summoner_name = self . summoner_ids_to_name [ summoner_id ] ) <EOL> self . logger . debug ( self . summoner_ids_to_name [ summoner_id ] + "<STR_LIT>" ) <EOL> else : <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) ) <EOL> self . logger . debug ( str ( presence [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> if summoner_id not in self . friends : <EOL> self . friends . append ( summoner_id ) <EOL> def on_xmpp_presence_unsubscribe ( self , presence ) : <EOL> """<STR_LIT>""" <EOL> summoner_id = self . jid_to_summoner_id ( presence [ "<STR_LIT>" ] ) <EOL> if self . riot_api_key and summoner_id in self . summoner_ids_to_name : <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) , summoner_name = self . summoner_ids_to_name [ summoner_id ] ) <EOL> self . logger . debug ( self . summoner_ids_to_name [ summoner_id ] + "<STR_LIT>" ) <EOL> self . summoner_ids_to_name . pop ( str ( summoner_id ) , None ) <EOL> else : <EOL> self . logger . debug ( str ( presence [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) ) <EOL> if summoner_id in self . friends : <EOL> self . friends . remove ( summoner_id ) <EOL> def on_xmpp_start ( self , e ) : <EOL> """<STR_LIT>""" <EOL> self . xmpp . get_roster ( ) <EOL> self . xmpp . send_presence ( ptype = "<STR_LIT>" , pstatus = self . get_status ( ) ) <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> self . fire_event ( "<STR_LIT>" ) <EOL> def on_xmpp_disconnected ( self , e ) : <EOL> """<STR_LIT>""" <EOL> self . fire_event ( "<STR_LIT>" ) <EOL> def on_xmpp_got_online ( self , presence ) : <EOL> """<STR_LIT>""" <EOL> if presence [ "<STR_LIT>" ] != self . xmpp . boundjid : <EOL> self . friends_online . append ( str ( presence [ "<STR_LIT>" ] ) ) <EOL> self . xmpp . send_presence ( pto = presence [ "<STR_LIT>" ] , ptype = "<STR_LIT>" , pstatus = self . get_status ( ) ) <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) ) <EOL> if presence [ "<STR_LIT>" ] in self . recently_added : <EOL> self . recently_added . remove ( presence [ "<STR_LIT>" ] ) <EOL> if self . someone_added_message : <EOL> self . message ( presence [ "<STR_LIT>" ] , self . someone_added_message ) <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) ) <EOL> else : <EOL> if self . someone_online_message : <EOL> self . message ( presence [ "<STR_LIT>" ] , self . someone_online_message ) <EOL> def on_xmpp_got_offline ( self , presence ) : <EOL> """<STR_LIT>""" <EOL> if str ( presence [ "<STR_LIT>" ] ) in self . friends_online : <EOL> self . friends_online . remove ( str ( presence [ "<STR_LIT>" ] ) ) <EOL> self . fire_event ( "<STR_LIT>" , who = str ( presence [ "<STR_LIT>" ] ) ) <EOL> def on_xmpp_message ( self , message ) : <EOL> """<STR_LIT>""" <EOL> sender = str ( message [ "<STR_LIT>" ] ) <EOL> if message [ "<STR_LIT:type>" ] == "<STR_LIT>" and sender [ <NUM_LIT:2> : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> inviter = message [ "<STR_LIT:body>" ] [ <NUM_LIT:0> : message [ "<STR_LIT:body>" ] . find ( "<STR_LIT:U+0020>" ) ] <EOL> if self . room_invite_message : <EOL> self . message ( inviter , self . room_invite_message ) <EOL> elif message [ "<STR_LIT:type>" ] in ( "<STR_LIT>" , "<STR_LIT>" ) and "<STR_LIT:/>" in sender : <EOL> msg = message [ "<STR_LIT:body>" ] <EOL> command = msg . split ( ) [ <NUM_LIT:0> ] <EOL> args = msg [ len ( command ) + <NUM_LIT:1> : ] . split ( "<STR_LIT:U+002CU+0020>" ) <EOL> if not args [ <NUM_LIT:0> ] : <EOL> args = [ ] <EOL> if command in self . commands : <EOL> adminCommand = getattr ( self . commands [ command ] , "<STR_LIT>" , False ) <EOL> if ( adminCommand and self . is_admin ( sender ) ) or not adminCommand : <EOL> if getattr ( self . commands [ command ] , "<STR_LIT>" , False ) and not args : <EOL> if self . need_arg_message : <EOL> self . message ( sender , self . need_arg_message . replace ( "<STR_LIT>" , command ) ) <EOL> else : <EOL> threading . Thread ( target = self . commands [ command ] , args = ( sender , args ) ) . start ( ) <EOL> elif self . not_admin_message : <EOL> self . message ( sender , self . not_admin_message ) <EOL> elif self . invalid_command_message : <EOL> self . message ( sender , self . invalid_command_message . replace ( "<STR_LIT>" , command ) ) <EOL> summoner_id = self . jid_to_summoner_id ( sender ) <EOL> if self . riot_api_key and sender [ <NUM_LIT:2> : <NUM_LIT:3> ] != "<STR_LIT>" : <EOL> if summoner_id not in self . summoner_ids_to_name : <EOL> self . summoner_ids_to_name [ summoner_id ] = self . summoner_id_to_name ( summoner_id ) <EOL> self . fire_event ( "<STR_LIT:message>" , sender = sender , message = msg , summoner_id = summoner_id , summoner_name = self . summoner_ids_to_name [ summoner_id ] ) <EOL> else : <EOL> self . fire_event ( "<STR_LIT:message>" , sender = sender , message = msg , summoner_id = summoner_id ) <EOL> elif message [ "<STR_LIT:type>" ] == "<STR_LIT>" and str ( message [ "<STR_LIT>" ] ) [ <NUM_LIT:2> : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> inviter = message [ "<STR_LIT:body>" ] [ <NUM_LIT:0> : message [ "<STR_LIT:body>" ] . find ( "<STR_LIT:U+0020>" ) ] <EOL> if self . room_invite_message : <EOL> self . message ( inviter , self . room_invite_message ) <EOL> def on_xmpp_failed_auth ( self , error ) : <EOL> """<STR_LIT>""" <EOL> self . logger . fatal ( "<STR_LIT>" ) <EOL> self . fire_event ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> def configure ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> admin = kwargs . get ( "<STR_LIT>" , None ) <EOL> admins = kwargs . get ( "<STR_LIT>" , None ) <EOL> newprefix = kwargs . get ( "<STR_LIT>" , False ) <EOL> self . help_command = kwargs . get ( "<STR_LIT>" , self . help_command ) <EOL> self . riot_api_key = kwargs . get ( "<STR_LIT>" , self . riot_api_key ) <EOL> self . need_arg_message = kwargs . get ( "<STR_LIT>" , self . need_arg_message ) <EOL> self . not_admin_message = kwargs . get ( "<STR_LIT>" , self . not_admin_message ) <EOL> self . room_invite_message = kwargs . get ( "<STR_LIT>" , self . room_invite_message ) <EOL> self . someone_added_message = kwargs . get ( "<STR_LIT>" , self . someone_added_message ) <EOL> self . someone_online_message = kwargs . get ( "<STR_LIT>" , self . someone_online_message ) <EOL> self . invalid_command_message = kwargs . get ( "<STR_LIT>" , self . invalid_command_message ) <EOL> if isinstance ( admins , list ) : <EOL> for zadmin in admins : <EOL> if zadmin not in self . admins : <EOL> self . add_admin ( zadmin ) <EOL> if admin and admin not in self . admins : <EOL> self . add_admin ( admin ) <EOL> if not self . help_command and "<STR_LIT>" in self . commands : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . commands . pop ( "<STR_LIT>" , None ) <EOL> if newprefix : <EOL> self . logger . debug ( "<STR_LIT>" + newprefix ) <EOL> if self . command_prefix : <EOL> tmp = { } <EOL> for name , value in self . commands . items ( ) : <EOL> tmp [ name [ len ( self . command_prefix ) : ] ] = value <EOL> self . commands = tmp <EOL> self . command_prefix = newprefix <EOL> tmp = { } <EOL> for name , value in self . commands . items ( ) : <EOL> tmp [ self . command_prefix + name ] = value <EOL> self . commands = tmp <EOL> def connect ( self ) : <EOL> """<STR_LIT>""" <EOL> serverIp = dns . resolver . query ( self . server . replace ( "<STR_LIT>" , self . regions [ self . region . upper ( ) ] ) ) <EOL> if serverIp : <EOL> if self . xmpp . connect ( ( str ( serverIp [ <NUM_LIT:0> ] ) , self . port ) , use_ssl = True ) : <EOL> self . xmpp . process ( block = False ) <EOL> self . xmpp . register_plugin ( "<STR_LIT>" ) <EOL> self . xmpp . register_plugin ( "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> return True <EOL> else : <EOL> self . logger . critical ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> self . logger . critical ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> def message ( self , to , message , newline = True ) : <EOL> """<STR_LIT>""" <EOL> if newline : <EOL> message = "<STR_LIT>" + message <EOL> mtype = "<STR_LIT>" <EOL> if str ( to ) [ <NUM_LIT:2> : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> mtype = "<STR_LIT>" <EOL> to = to [ <NUM_LIT:0> : to . find ( "<STR_LIT:/>" ) ] <EOL> self . xmpp . send_message ( mto = str ( to ) , mbody = str ( message ) , mtype = mtype ) <EOL> def message_all ( self , message , newline = True ) : <EOL> """<STR_LIT>""" <EOL> if newline : <EOL> message = "<STR_LIT>" + message <EOL> for person in self . friends_online : <EOL> self . xmpp . send_message ( mto = str ( person ) , mbody = str ( message ) , mtype = "<STR_LIT>" ) <EOL> def add_event_handler ( self , event_type , function ) : <EOL> """<STR_LIT>""" <EOL> if callable ( function ) : <EOL> setattr ( self , "<STR_LIT>" + event_type , function ) <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" + event_type ) <EOL> def fire_event ( self , event_type , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if callable ( getattr ( self , "<STR_LIT>" + event_type , None ) ) : <EOL> if kwargs . items ( ) : <EOL> getattr ( self , "<STR_LIT>" + event_type ) ( kwargs ) <EOL> else : <EOL> getattr ( self , "<STR_LIT>" + event_type ) ( ) <EOL> def set_status ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" , <NUM_LIT:30> ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . status [ "<STR_LIT>" ] = kwargs . get ( "<STR_LIT>" , self . status . get ( "<STR_LIT>" ) ) <EOL> self . xmpp . send_presence ( ptype = "<STR_LIT>" , pstatus = self . get_status ( ) ) <EOL> def get_status ( self ) : <EOL> """<STR_LIT>""" <EOL> status = "<STR_LIT>" <EOL> for name , value in self . status . items ( ) : <EOL> if value != None : <EOL> status += "<STR_LIT:<>" + str ( name ) + "<STR_LIT:>>" + str ( value ) + "<STR_LIT>" + str ( name ) + "<STR_LIT:>>" <EOL> if status . find ( "<STR_LIT>" ) == - <NUM_LIT:1> : <EOL> status += "<STR_LIT>" <EOL> return "<STR_LIT>" + status + "<STR_LIT>" <EOL> def summoner_id_to_name ( self , summoner_id ) : <EOL> """<STR_LIT>""" <EOL> if self . riot_api_key : <EOL> try : <EOL> source = urllib . request . urlopen ( "<STR_LIT>" + urllib . parse . quote ( self . region . lower ( ) ) + <EOL> "<STR_LIT>" + <EOL> urllib . parse . quote ( self . region . lower ( ) ) + <EOL> "<STR_LIT>" + <EOL> urllib . parse . quote ( str ( summoner_id ) ) <EOL> + "<STR_LIT>" + urllib . parse . quote ( self . riot_api_key ) ) <EOL> except urllib . error . HTTPError as err : <EOL> if err . code == <NUM_LIT> : <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . riot_api_key = None <EOL> elif err . code == <NUM_LIT> : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> return None <EOL> else : <EOL> source = source . read ( ) . decode ( ) <EOL> data = json . loads ( source ) <EOL> return data . get ( summoner_id ) <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> def summoner_name_to_id ( self , summoner_name ) : <EOL> """<STR_LIT>""" <EOL> if self . riot_api_key : <EOL> try : <EOL> source = urllib . request . urlopen ( "<STR_LIT>" + urllib . parse . quote ( self . region . lower ( ) ) + <EOL> "<STR_LIT>" + <EOL> urllib . parse . quote ( self . region . lower ( ) ) + <EOL> "<STR_LIT>" + <EOL> urllib . parse . quote ( summoner_name ) + <EOL> "<STR_LIT>" + urllib . parse . quote ( self . riot_api_key ) ) . read ( ) . decode ( ) <EOL> except urllib . error . HTTPError as err : <EOL> if err . code == <NUM_LIT> : <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . riot_api_key = None <EOL> elif err . code == <NUM_LIT> : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> return None <EOL> else : <EOL> data = json . loads ( source ) <EOL> if summoner_name . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) . lower ( ) in data : <EOL> return str ( data [ summoner_name . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) . lower ( ) ] [ "<STR_LIT:id>" ] ) <EOL> else : <EOL> return None <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> def has_riot_api_key ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . riot_api_key <EOL> def jid_to_summoner_id ( self , jid ) : <EOL> """<STR_LIT>""" <EOL> jid = str ( jid ) <EOL> if jid [ <NUM_LIT:0> : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> return str ( jid [ <NUM_LIT:3> : jid . find ( "<STR_LIT:@>" ) ] ) <EOL> else : <EOL> return None <EOL> def get_friends_online ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . friends_online <EOL> def get_friends ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . friends <EOL> def get_admins ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . admins <EOL> def is_admin ( self , jid ) : <EOL> """<STR_LIT>""" <EOL> return self . jid_to_summoner_id ( jid ) in self . admins <EOL> def add_admin ( self , admin ) : <EOL> """<STR_LIT>""" <EOL> admin = str ( admin ) <EOL> error = False <EOL> if admin not in self . admins : <EOL> if admin . isdigit ( ) : <EOL> self . admins . append ( admin ) <EOL> elif self . riot_api_key : <EOL> summoner_id = self . summoner_name_to_id ( admin ) <EOL> if summoner_id : <EOL> self . admins . append ( summoner_id ) <EOL> admin += "<STR_LIT>" + str ( summoner_id ) + "<STR_LIT:)>" <EOL> else : <EOL> error = True <EOL> self . logger . debug ( admin + "<STR_LIT>" ) <EOL> else : <EOL> error = True <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> else : <EOL> error = True <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> if not error : <EOL> self . logger . debug ( admin + "<STR_LIT>" ) <EOL> def remove_admin ( self , admin ) : <EOL> """<STR_LIT>""" <EOL> admin = str ( admin ) <EOL> if admin in self . admins : <EOL> self . admins . remove ( admin ) <EOL> self . logger . debug ( admin + "<STR_LIT>" ) <EOL> else : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> def unregister_command ( self , command_name ) : <EOL> """<STR_LIT>""" <EOL> if command_name in self . commands : <EOL> self . commands . pop ( command_name , None ) <EOL> self . logger . debug ( "<STR_LIT>" + command_name ) <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" + command_name + "<STR_LIT>" ) <EOL> def join_muc_room ( self , room_name , room_type = "<STR_LIT>" , room_domain = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if str ( room_name ) [ <NUM_LIT:2> : <NUM_LIT:3> ] != "<STR_LIT>" : <EOL> room = room_type + "<STR_LIT>" + hashlib . sha1 ( room_name . encode ( ) ) . hexdigest ( ) + "<STR_LIT:@>" + room_domain + "<STR_LIT:/>" + self . username <EOL> else : <EOL> room = room_name + "<STR_LIT:/>" + self . username <EOL> self . xmpp . send_presence ( pto = room , pstatus = self . get_status ( ) , pshow = "<STR_LIT>" ) <EOL> return room <EOL> def leave_muc_room ( self , room_name , room_type = "<STR_LIT>" , room_domain = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if str ( room_name ) [ <NUM_LIT:2> : <NUM_LIT:3> ] != "<STR_LIT>" : <EOL> room = room_type + "<STR_LIT>" + hashlib . sha1 ( room_name . encode ( ) ) . hexdigest ( ) + "<STR_LIT:@>" + room_domain + "<STR_LIT:/>" + self . username <EOL> else : <EOL> room = room_name + "<STR_LIT:/>" + self . username <EOL> self . xmpp . send_presence ( pto = room , pstatus = self . get_status ( ) , pshow = "<STR_LIT>" ) <EOL> def message_muc_room ( self , room_name , message , room_type = "<STR_LIT>" , room_domain = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if str ( room_name ) [ <NUM_LIT:2> : <NUM_LIT:3> ] != "<STR_LIT>" : <EOL> room = room_type + "<STR_LIT>" + hashlib . sha1 ( room_name . encode ( ) ) . hexdigest ( ) + "<STR_LIT:@>" + room_domain + "<STR_LIT:/>" + self . username <EOL> else : <EOL> room = room_name + "<STR_LIT:/>" + self . username <EOL> self . message ( room , message ) <EOL> def add_friend_by_id ( self , summoner_id ) : <EOL> """<STR_LIT>""" <EOL> self . xmpp . send_presence ( pto = "<STR_LIT>" + summoner_id + "<STR_LIT>" , ptype = "<STR_LIT>" ) <EOL> def add_friend_by_name ( self , summoner_name ) : <EOL> """<STR_LIT>""" <EOL> if self . riot_api_key : <EOL> self . xmpp . send_presence ( pto = "<STR_LIT>" + self . summoner_name_to_id ( summoner_name ) + "<STR_LIT>" , ptype = "<STR_LIT>" ) <EOL> def remove_friend_by_id ( self , summoner_id ) : <EOL> """<STR_LIT>""" <EOL> self . xmpp . send_presence ( pto = "<STR_LIT>" + summoner_id + "<STR_LIT>" , ptype = "<STR_LIT>" ) <EOL> def remove_friend_by_name ( self , summoner_name ) : <EOL> """<STR_LIT>""" <EOL> if self . riot_api_key : <EOL> self . xmpp . send_presence ( pto = "<STR_LIT>" + self . summoner_name_to_id ( summoner_name ) + "<STR_LIT>" , ptype = "<STR_LIT>" ) <EOL> @ botcommand <EOL> def help ( self , sender , arg ) : <EOL> """<STR_LIT>""" <EOL> is_admin = self . is_admin ( sender ) <EOL> reply = "<STR_LIT>" <EOL> if arg : <EOL> if arg [ <NUM_LIT:0> ] in self . commands : <EOL> hiddenCommand = getattr ( self . commands [ arg [ <NUM_LIT:0> ] ] , "<STR_LIT>" , False ) <EOL> adminCommand = getattr ( self . commands [ arg [ <NUM_LIT:0> ] ] , "<STR_LIT>" , False ) <EOL> if ( adminCommand and is_admin ) or ( not hiddenCommand and not adminCommand ) or ( hiddenCommand and is_admin ) : <EOL> doc = self . commands [ arg [ <NUM_LIT:0> ] ] . __doc__ or "<STR_LIT>" <EOL> reply = "<STR_LIT>" + arg [ <NUM_LIT:0> ] + "<STR_LIT>" + doc . replace ( "<STR_LIT:\t>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) <EOL> else : <EOL> reply += "<STR_LIT>" <EOL> for command in sorted ( self . commands ) : <EOL> hiddenCommand = getattr ( self . commands [ command ] , "<STR_LIT>" , False ) <EOL> adminCommand = getattr ( self . commands [ command ] , "<STR_LIT>" , False ) <EOL> if ( adminCommand and is_admin ) or ( not hiddenCommand and not adminCommand ) or ( hiddenCommand and is_admin ) : <EOL> doc = self . commands [ command ] . __doc__ or "<STR_LIT>" <EOL> if doc != "<STR_LIT>" : <EOL> doc = doc . split ( "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] <EOL> reply += command + "<STR_LIT>" + doc + "<STR_LIT>" <EOL> if reply : <EOL> self . message ( sender , reply ) <EOL> else : <EOL> self . message ( sender , "<STR_LIT>" + arg [ <NUM_LIT:0> ] ) </s>
