import random bold = "\x02" italic = "\x1D" underline = "\x1F" reverse = "\x16" # swap background and foreground colors ("reverse video") reset = "\x0F" blue = "\x0302" green = "\x0303" red = "\x0304" grey = "\x0314" class CommandHelpers(): def disect_command(self, event): trigger = event.arguments[0] command = trigger[1:] #Command without prefix. # Determine command type. if trigger.startswith(self.cmdchar): cmdtype = "cmd" elif trigger.startswith(self.helpchar): cmdtype = "help" else: cmdtype = False # Determine where to reply to. if event.type == "pubmsg": replyto = event.target elif event.type == "privmsg": replyto = event.source.nick else: replyto = False return(cmdtype, trigger, command, replyto) def ccc(self, command, rights=False, event=False): # Commandlist colour coding and channel rights filter. if rights: show = False if rights["homechan"] == "owner": if self.channels[self.homechannel].is_owner(event.source.nick): show = True if rights["homechan"] == "admin": if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick): show = True if rights["homechan"] == "oper": if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick): show = True if rights["chan"] == "owner": if self.channels[event.target].is_owner(event.source.nick): show = True if rights["chan"] == "admin": if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick): show = True if rights["chan"] == "oper": if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick) or self.channels[event.target].is_oper(event.source.nick): show = True if show: return blue + self.cmdchar + command + reset + ", " else: return blue + self.cmdchar + command + reset + ", " class AdminHelpers(): def get_channelfunctions(self, channel): channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games, chat FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'") if channelfunctions[0]: autojoin = "on" else: autojoin = "off" if channelfunctions[2]: joingreet = "on" else: joingreet = "off" if channelfunctions[3]: statscmds = "on" else: statscmds = "off" if channelfunctions[4]: games = "on" else: games = "off""" if channelfunctions[5]: chat = "on" else: chat = "off""" return ("autojoin " + green + autojoin + reset + ", aggressiveness " + green + channelfunctions[1] + reset + ", join_greeting " + green + joingreet + reset + ", statistics_commands " + green + statscmds + reset + ", games " + green + games + reset + ", chat " + green + chat + reset + ".") def is_channelfunction(value): if value.lower() in ["autojoin", "aggressiveness", "join_greeting", "statistics_commands", "games", "chat"]: return True else: return False def describe_channelfunction(function): if function == "autojoin": message = "Join the channel automaticly after connecting." elif function == "aggressiveness": message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + ", " + blue + "equal_retalliation" + reset + ", " + blue + "battlebot" + reset + "." elif function == "join_greeting": message = "Greet users joining the channel on the first few joins, and later on large amounts." elif function == "statistics_commands": message = "Enable use of statistics commands." elif function == "games": message = "Enable use of game commands." elif function == "chat": message = "Respond to and initiate chat." else: message = "Sorry, this function has no description yet." return message def is_aggressiveness(value): if value.lower() in ["passive", "defense_only", "equal_retalliation", "battlebot"]: return True else: return False class GameHelpers(): def roll_dice(amount, type): rolls = [] for iterations in range(amount): rolls.append(random.randint(1, type)) return rolls