def __init__(self, config_file): self.read_config(config_file) self.dbc = Database(self.config) self.players = self.dbc.get_players() self.profiles = self.dbc.get_profiles() self.arsenals = self.dbc.get_arsenals() CustomSingleServerIRCBot.__init__( self, [(self.config['server'], self.config['port'])], self.config['nick'], self.config['realname']) self.sched = schedule.Schedule(self.connection, self.dbc, self.config['channel'], self.players, self.profiles, self.arsenals) self.uc = user_command.UserCommand(self.connection, self.dbc, self.config['channel'], self.config['channel_accesstype'], self.profiles, self.arsenals) self.ac = admin_command.AdminCommand(self.connection, self.dbc, self.config['channel'], str(self.config['admin_passwd']), self.config['channel_accesstype'], self.sched, self.profiles, self.arsenals) Utils.bosses = Utils.create_bosses() Utils.b_created = True
def __init__(self, config_file): self.read_config(config_file) self.dbc = Database(self.config) self.players = self.dbc.get_players() self.profiles = self.dbc.get_profiles() self.arsenals = self.dbc.get_arsenals() CustomSingleServerIRCBot.__init__(self, [(self.config['server'], self.config['port'])], self.config['nick'], self.config['realname']) self.sched = schedule.Schedule(self.connection, self.dbc, self.config['channel'], self.players, self.profiles, self.arsenals) self.uc = user_command.UserCommand(self.connection, self.dbc, self.config['channel'], self.config['channel_accesstype'], self.profiles, self.arsenals) self.ac = admin_command.AdminCommand(self.connection, self.dbc, self.config['channel'], str(self.config['admin_passwd']), self.config['channel_accesstype'], self.sched, self.profiles, self.arsenals) Utils.bosses = Utils.create_bosses() Utils.b_created = True
class Zombire(CustomSingleServerIRCBot): def __init__(self, config_file): self.read_config(config_file) self.dbc = Database(self.config) self.players = self.dbc.get_players() self.profiles = self.dbc.get_profiles() self.arsenals = self.dbc.get_arsenals() CustomSingleServerIRCBot.__init__( self, [(self.config['server'], self.config['port'])], self.config['nick'], self.config['realname']) self.sched = schedule.Schedule(self.connection, self.dbc, self.config['channel'], self.players, self.profiles, self.arsenals) self.uc = user_command.UserCommand(self.connection, self.dbc, self.config['channel'], self.config['channel_accesstype'], self.profiles, self.arsenals) self.ac = admin_command.AdminCommand(self.connection, self.dbc, self.config['channel'], str(self.config['admin_passwd']), self.config['channel_accesstype'], self.sched, self.profiles, self.arsenals) Utils.bosses = Utils.create_bosses() Utils.b_created = True def read_config(self, filename): if not os.path.exists(filename): print('Error: config.yml could not be found.') sys.exit(1) with open(filename, 'r') as config_fd: self.config = yaml.load(config_fd) def on_welcome(self, c, e): if self.config['nspass']: self.connection.privmsg( "nickserv", "identify {}".format(self.config['nspass'])) c.join(self.config['channel']) def on_privnotice(self, c, e): # checking for nickserv replies if e.source.nick.lower() == "nickserv" and e.arguments[0].lower( ).startswith("status "): largs = e.arguments[0].split(" ") if largs[2] == "3": # if user is identified to nickserv self.uc.register2( largs[1].lower(), self.channels, self.players) # proceed with the registration else: self.connection.privmsg(self.config['channel'], ( "\x02{}:\x02 You must register your nick first " + "through NickServ, or identify if you have already registered it." ).format(largs[1])) return # retrieving chanserv access list for channel elif e.source.nick.lower() == "chanserv": if Utils.registering_nick: args = e.arguments[0] detected = re.match(r"all user modes on", args, re.IGNORECASE) if detected: self.uc.register3(Utils.registering_nick, self.channels, self.players) return # if Utils.cs_list == 2: # detected = re.match(r"channel access list", args, re.IGNORECASE) # if detected: # Utils.reg_list2 = [] # return # detected = re.match(r"\d+\.\s+(\w+)\s+", args, re.IGNORECASE) # if detected: # Utils.reg_list2.append(detected.group(1).strip().lower()) # return # detected = re.match(r"end of access list", args, re.IGNORECASE) # if detected: # Utils.cs_list = 0 # return # elif Utils.cs_list == 1: # detected = re.match(r"channel access list", args, re.IGNORECASE) # if detected: # Utils.reg_list1 = [] # return # detected = re.match(r"\d+\.\s+(\w+)\s+", args, re.IGNORECASE) # if detected: # Utils.reg_list1.append(detected.group(1).strip().lower()) # return # detected = re.match(r"end of access list", args, re.IGNORECASE) # if detected: # Utils.cs_list = 2 # self.uc.register3(Utils.registering_nick, self.channels, self.players) # return def on_privmsg(self, c, e): re_exprs = (r"admin\s+(.+)", ) for expr in re_exprs: try: detected = re.match(expr, e.arguments[0], re.IGNORECASE) raise DetectedCommand except DetectedCommand: if detected: self.ac.execute(e, detected.group(1).strip(), self.players) return def on_pubmsg(self, c, e): re_exprs = (r"\!(register)", r"\!(unregister)", r"\!(status(\s+.+)?)", r"\!(attack\s+.+)", r"\!(heal\s+.+)", r"\!(vampires|zombies)", r"\!(version)", r"\!(topscores)", r"\!(highscores)", r"\!(howtoplay)", r"\!(ambush\s+.+)", r"\!(auto\s+(attack|heal|register|search|chest)(\s+.+)?)", r"\!(challenge)", r"\!(search|inventory)", r"\!((use|drop)\s+.+)", r"\!(chest\s+.+)", r"\!(forge(\s.+)?)", r"\!(upgrade\s+.+)") for expr in re_exprs: try: detected = re.match(expr, e.arguments[0], re.IGNORECASE) raise DetectedCommand except DetectedCommand: if detected: detected_command = detected.group(1).strip() if detected_command.lower().startswith( ("unregister", "attack", "heal", "ambush", "challenge", "auto", "search", "inventory", "use", "drop", "chest", "forge", "upgrade")): # user needs to be registered to use those commands for chname, chobj in self.channels.items(): voiced_users = list(chobj.voiced()) + list( chobj.opers()) + list(chobj.halfops()) nick = e.source.nick nick2 = nick.replace("[", "..").replace("]", ",,") voiced_users = map( lambda x: x.replace("[", "..").replace("]", ",,"). lower(), voiced_users) if nick2.lower() in voiced_users and nick2.lower( ) in list(self.players): self.uc.execute(e, detected_command, self.players) elif nick in voiced_users: self.connection.notice( nick, "Error: Please change your nick " + "to the one you have registered in the game with." ) else: self.connection.notice( nick, "Error: You are not registered, " + "or you did not identify to your nick.") else: self.uc.execute(e, detected_command, self.players) return
class Zombire(CustomSingleServerIRCBot): def __init__(self, config_file): self.read_config(config_file) self.dbc = Database(self.config) self.players = self.dbc.get_players() self.profiles = self.dbc.get_profiles() self.arsenals = self.dbc.get_arsenals() CustomSingleServerIRCBot.__init__(self, [(self.config['server'], self.config['port'])], self.config['nick'], self.config['realname']) self.sched = schedule.Schedule(self.connection, self.dbc, self.config['channel'], self.players, self.profiles, self.arsenals) self.uc = user_command.UserCommand(self.connection, self.dbc, self.config['channel'], self.config['channel_accesstype'], self.profiles, self.arsenals) self.ac = admin_command.AdminCommand(self.connection, self.dbc, self.config['channel'], str(self.config['admin_passwd']), self.config['channel_accesstype'], self.sched, self.profiles, self.arsenals) Utils.bosses = Utils.create_bosses() Utils.b_created = True def read_config(self, filename): if not os.path.exists(filename): print('Error: config.yml could not be found.') sys.exit(1) with open(filename, 'r') as config_fd: self.config = yaml.load(config_fd) def on_welcome(self, c, e): if self.config['nspass']: self.connection.privmsg("nickserv", "identify {}".format(self.config['nspass'])) c.join(self.config['channel']) def on_privnotice(self, c, e): # checking for nickserv replies if e.source.nick.lower() == "nickserv" and e.arguments[0].lower().startswith("status "): largs = e.arguments[0].split(" ") if largs[2] == "3": # if user is identified to nickserv self.uc.register2(largs[1].lower(), self.channels, self.players) # proceed with the registration else: self.connection.privmsg(self.config['channel'], ("\x02{}:\x02 You must register your nick first " + "through NickServ, or identify if you have already registered it.").format(largs[1])) return # retrieving chanserv access list for channel elif e.source.nick.lower() == "chanserv": if Utils.registering_nick: args = e.arguments[0] detected = re.match(r"all user modes on", args, re.IGNORECASE) if detected: self.uc.register3(Utils.registering_nick, self.channels, self.players) return # if Utils.cs_list == 2: # detected = re.match(r"channel access list", args, re.IGNORECASE) # if detected: # Utils.reg_list2 = [] # return # detected = re.match(r"\d+\.\s+(\w+)\s+", args, re.IGNORECASE) # if detected: # Utils.reg_list2.append(detected.group(1).strip().lower()) # return # detected = re.match(r"end of access list", args, re.IGNORECASE) # if detected: # Utils.cs_list = 0 # return # elif Utils.cs_list == 1: # detected = re.match(r"channel access list", args, re.IGNORECASE) # if detected: # Utils.reg_list1 = [] # return # detected = re.match(r"\d+\.\s+(\w+)\s+", args, re.IGNORECASE) # if detected: # Utils.reg_list1.append(detected.group(1).strip().lower()) # return # detected = re.match(r"end of access list", args, re.IGNORECASE) # if detected: # Utils.cs_list = 2 # self.uc.register3(Utils.registering_nick, self.channels, self.players) # return def on_privmsg(self, c, e): re_exprs = (r"admin\s+(.+)",) for expr in re_exprs: try: detected = re.match(expr, e.arguments[0], re.IGNORECASE) raise DetectedCommand except DetectedCommand: if detected: self.ac.execute(e, detected.group(1).strip(), self.players) return def on_pubmsg(self, c, e): re_exprs = (r"\!(register)", r"\!(unregister)", r"\!(status(\s+.+)?)", r"\!(attack\s+.+)", r"\!(heal\s+.+)", r"\!(vampires|zombies)", r"\!(version)", r"\!(topscores)", r"\!(highscores)", r"\!(howtoplay)", r"\!(ambush\s+.+)", r"\!(auto\s+(attack|heal|register|search|chest)(\s+.+)?)", r"\!(challenge)", r"\!(search|inventory)", r"\!((use|drop)\s+.+)", r"\!(chest\s+.+)", r"\!(forge(\s.+)?)", r"\!(upgrade\s+.+)") for expr in re_exprs: try: detected = re.match(expr, e.arguments[0], re.IGNORECASE) raise DetectedCommand except DetectedCommand: if detected: detected_command = detected.group(1).strip() if detected_command.lower().startswith(("unregister", "attack", "heal", "ambush", "challenge", "auto", "search", "inventory", "use", "drop", "chest", "forge", "upgrade")): # user needs to be registered to use those commands for chname, chobj in self.channels.items(): voiced_users = list(chobj.voiced()) + list(chobj.opers()) + list(chobj.halfops()) nick = e.source.nick nick2 = nick.replace("[", "..").replace("]", ",,") voiced_users = map(lambda x: x.replace("[", "..").replace("]", ",,").lower(), voiced_users) if nick2.lower() in voiced_users and nick2.lower() in list(self.players): self.uc.execute(e, detected_command, self.players) elif nick in voiced_users: self.connection.notice(nick, "Error: Please change your nick " + "to the one you have registered in the game with.") else: self.connection.notice(nick, "Error: You are not registered, " + "or you did not identify to your nick.") else: self.uc.execute(e, detected_command, self.players) return