def start_list(db, twitter, name, list_id, *args, **kwargs): num = 0 if db.settings.has_key(name): try: if db.settings[name][0]["id"] > db.settings[name][-1]["id"]: last_id = db.settings[name][0]["id"] else: last_id = db.settings[name][-1]["id"] except IndexError: pass tl = twitter.twitter.get_list_statuses(list_id=list_id, *args, **kwargs) else: tl = twitter.twitter.get_list_statuses(list_id=list_id, *args, **kwargs) tl.reverse() db.settings[name] = [] last_id = 0 if len(db.settings[name]) > 0: for i in tl: if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 db.settings.update() return num
def search(db, twitter, name, *args, **kwargs): num = 0 if db.settings.has_key(name) == False: db.settings[name] = [] tl = twitter.twitter.search(*args, **kwargs) tl["statuses"].reverse() if len(db.settings[name]) > 0: for i in tl["statuses"]: if utils.find_item( i["id"], db.settings[name]) == None and utils.is_allowed(i): if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 elif len(db.settings[name]) == 0: for i in tl["statuses"]: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 return num
def start_stream(db, twitter, name, function, param=None): num = 0 if db.settings.has_key(name): try: if db.settings[name][0]["id"] > db.settings[name][-1]["id"]: last_id = db.settings[name][0]["id"] else: last_id = db.settings[name][-1]["id"] except IndexError: pass if param != None: tl = call_paged(function, twitter, sinze_id=last_id, screen_name=param, count=config.main["general"]["max_tweets_per_call"]) else: tl = call_paged(function, twitter, sinze_id=last_id, count=config.main["general"]["max_tweets_per_call"]) else: if param != None: tl = call_paged(function, twitter, screen_name=param, count=config.main["general"]["max_tweets_per_call"]) else: tl = call_paged(function, twitter, count=config.main["general"]["max_tweets_per_call"]) db.settings[name] = [] last_id = 0 if len(db.settings[name]) > 0: for i in tl: if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 # db.settings.update() return num
def get_favourites_timeline(db, twitter, name, param, *args, **kwargs): num = 0 if db.settings.has_key(name) == False: db.settings[name] = [] tl = twitter.twitter.get_favorites(screen_name=param, *args, **kwargs) tl.reverse() if len(db.settings[name]) > 0: for i in tl: if utils.find_item( i["id"], db.settings[name]) == None and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 return num
def start_stream(db, twitter, name, function, param=None): num = 0 if db.settings.has_key(name): try: if db.settings[name][0]["id"] > db.settings[name][-1]["id"]: last_id = db.settings[name][0]["id"] else: last_id = db.settings[name][-1]["id"] except IndexError: pass if param != None: tl = call_paged( function, twitter, sinze_id=last_id, screen_name=param, count=config.main["general"]["max_tweets_per_call"]) else: tl = call_paged( function, twitter, sinze_id=last_id, count=config.main["general"]["max_tweets_per_call"]) else: if param != None: tl = call_paged( function, twitter, screen_name=param, count=config.main["general"]["max_tweets_per_call"]) else: tl = call_paged( function, twitter, count=config.main["general"]["max_tweets_per_call"]) db.settings[name] = [] last_id = 0 if len(db.settings[name]) > 0: for i in tl: if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 # db.settings.update() return num
async def on_message(message): if message.author.id == client.user.id: return if isinstance( message.author, discord.Member ) and message.channel.category.id in LAUGHS_CATEGORIES and BOUFFON_ROLES_ID in [ r.id for r in message.author.roles ]: if message.content.startswith('-'): return log_info("Send laugh") await message.channel.send(random.choice(LAUGH_LIST)) if not utils.is_allowed(message.channel): return if bank is None: return if message.content.startswith("."): log_info("{} ({}): {}".format(message.author.name, message.author.id, message.content)) # await message.channel.send("```{}```".format(message.content)) await client.process_commands(message)
def mode(irc, event, args): """[<channel>] <modes> Sets <modes> in <channel>. <channel> is only necessary if the command isn't sent in the channel itself. """ try: if utils.is_private(event) or irc.is_channel(args[0]): if args[0] in irc.state["channels"]: channel = args[0] setmodes = utils.split_modes(args[1:]) elif not utils.is_private(event): channel = event.target setmodes = utils.split_modes(args) else: irc.reply(event, utils.gethelp("mode")) return else: channel = event.target setmodes = utils.split_modes(args) except IndexError: irc.reply(event, utils.gethelp("mode")) else: if utils.is_allowed(irc, event.source, channel): already_op = irc.is_opped(irc.get_nick(), channel) if not already_op: setmodes.append("-o {}".format(irc.get_nick())) gotop = utils.getop(irc, channel) if gotop: for modes in utils.unsplit_modes(setmodes): irc.mode(channel, modes)
def squiet(irc, event, args): """[<channel>] <nick|hostmask> [<nick|hostmask>...] Quiets <nick> in <channel> using services. <channel> is only necessary if the command isn't sent in the channel itself. """ try: if utils.is_private(event): channel = args[0] nicks = args[1:] else: if irc.is_channel(args[0]): channel = args[0] nicks = args[1:] else: channel = event.target nicks = args except IndexError: irc.reply(event, utils.gethelp("squiet")) else: if utils.is_allowed(irc, event.source, channel): try: if irc.channels[channel].get("chanserv", irc.chanserv): irc.privmsg("ChanServ", "QUIET {} {}".format(channel, " ".join(nicks))) except KeyError: pass
def launch(symbol): try: precision = get_precision(symbol) pip = get_pip(symbol) price_precision = len( '{0:.10f}'.format(pip).split('.')[1].split('1')[0]) + 1 to_general_log(symbol, 'Start monitoring') while is_allowed(symbol): ma8 = get_ma_value(symbol, '5M', 8) ma21 = get_ma_value(symbol, '5M', 21) current_candle_open = float(get_current_candle(symbol, '5M')[1]) current_candle_close = float(get_current_candle(symbol, '5M')[4]) # looking for BUY signal if ma21 < ma8 < min(current_candle_open, current_candle_close) and check_anchor_chart( symbol, 'buy'): # waiting trigger bar for BUY while True: current_candle = get_current_candle(symbol, '5M') current_candle_close = float(current_candle[4]) ma8 = get_ma_value(symbol, '5M', 8) if current_candle_close < ma8: entrance_point = round( last_bars_extremum(symbol, 5, 'buy') + (30 * pip), price_precision) place_pending_order(symbol, 'buy', entrance_point, precision, price_precision) break # looking for SELL signal if ma21 > ma8 > max(current_candle_open, current_candle_close) and check_anchor_chart( symbol, 'sell'): # waiting trigger bar for SELL while True: current_candle = get_current_candle(symbol, '5M') current_candle_open = float(current_candle[1]) ma8 = get_ma_value(symbol, '5M', 8) if current_candle_open > ma8: entrance_point = round( last_bars_extremum(symbol, 5, 'sell') - (30 * pip), price_precision) place_pending_order(symbol, 'sell', entrance_point, precision, price_precision) break time.sleep(1) except: to_err_log(symbol, traceback.format_exc())
def search(db, twitter, name, *args, **kwargs): num = 0 if db.settings.has_key(name) == False: db.settings[name] = [] tl = twitter.twitter.search(*args, **kwargs) tl["statuses"].reverse() if len(db.settings[name]) > 0: for i in tl["statuses"]: if utils.find_item(i["id"], db.settings[name]) == None and utils.is_allowed(i): if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 elif len(db.settings[name]) == 0: for i in tl["statuses"]: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 return num
def get_favourites_timeline(db, twitter, name, param, *args, **kwargs): num = 0 if db.settings.has_key(name) == False: db.settings[name] = [] tl = twitter.twitter.get_favorites(screen_name=param, *args, **kwargs) tl.reverse() if len(db.settings[name]) > 0: for i in tl: if utils.find_item(i["id"], db.settings[name]) == None and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num+1 return num
def unquiet(irc, event, args): """[<channel>] [<nick|hostmask>...] Unquiets <nick> (or yourself if no <nick> is specified) in <channel>. <channel> is only necessary if the command isn't sent in the channel itself. """ setmodes = [] try: if utils.is_private(event): channel = args[0] if len(args) > 1: nicks = args[1:] else: nicks = [event.source.nick] else: if len(args) > 0: if irc.is_channel(args[0]): channel = args[0] if len(args) > 1: nicks = args[1:] else: nicks = [event.source.nick] else: channel = event.target nicks = args else: channel = event.target nicks = [event.source.nick] except IndexError: irc.reply(event, utils.gethelp("unquiet")) else: if utils.is_allowed(irc, event.source, channel): for nick in nicks: if utils.is_hostmask(nick): hmask = nick else: hmask = utils.gethm(irc, nick) if hmask and channel in irc.state["channels"]: for bmask in irc.state["channels"][channel]["quiets"]: if fnmatch(utils.irclower(hmask), utils.irclower(bmask)): setmodes.append("-q {}".format(bmask)) else: return if len(setmodes) == 0: return already_op = irc.is_opped(irc.get_nick(), channel) if not already_op: setmodes.append("-o {}".format(irc.get_nick())) gotop = utils.getop(irc, channel) if gotop: for mode in utils.unsplit_modes(setmodes): irc.mode(channel, mode)
def update_stream(config, twitter, name, function, param=None, sndFile=""): num = 0 sounded = False tl = function(sinze_id=config.settings[name][-1]["id"], screen_name=param, count=config.main["general"]["max_tweets_per_call"]) tl.reverse() for i in tl: if i["id"] > config.settings[name][-1]["id"] and utils.is_allowed(i) == True: config.settings[name].append(i) sounded = True num = num+1 if sounded == True: sound.play(sndFile) return num
def start_list(db, twitter, name, list_id, *args, **kwargs): num = 0 if db.settings.has_key(name): try: if db.settings[name][0]["id"] > db.settings[name][-1]["id"]: last_id = db.settings[name][0]["id"] else: last_id = db.settings[name][-1]["id"] except IndexError: pass tl = twitter.twitter.get_list_statuses(list_id=list_id, *args, **kwargs) else: tl = twitter.twitter.get_list_statuses(list_id=list_id, *args, **kwargs) tl.reverse() db.settings[name] = [] last_id = 0 if len(db.settings[name]) > 0: for i in tl: if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 elif len(db.settings[name]) == 0: for i in tl: if utils.is_allowed(i) == True: if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i) else: db.settings[name].insert(0, i) num = num + 1 db.settings.update() return num
def quiet(irc, event, args): """[<channel>] <nick|hostmask> [<nick|hostmask>...] Quiets <nick> in <channel>. <channel> is only necessary if the command isn't sent in the channel itself. """ setmodes = [] affected = [] try: if utils.is_private(event): channel = args[0] nicks = args[1:] else: if irc.is_channel(args[0]): channel = args[0] nicks = args[1:] else: channel = event.target nicks = args except IndexError: irc.reply(event, utils.gethelp("quiet")) else: if utils.is_allowed(irc, event.source, channel): for nick in nicks: if utils.is_hostmask(nick): bmask = nick else: bmask = utils.banmask(irc, nick) setmodes.append("+q {}".format(bmask)) for affect in utils.ban_affects(irc, channel, bmask): if affect not in affected and affect != irc.get_nick(): affected.append(affect) for nick in affected: if irc.is_opped(nick, channel): setmodes.append("-o {}".format(nick)) if irc.is_voiced(nick, channel): setmodes.append("-v {}".format(nick)) if len(setmodes) == 0: return already_op = irc.is_opped(irc.get_nick(), channel) if not already_op: setmodes.append("-o {}".format(irc.get_nick())) gotop = utils.getop(irc, channel) if gotop: for mode in utils.unsplit_modes(setmodes): irc.mode(channel, mode)
def update_stream(config, twitter, name, function, param=None, sndFile=""): num = 0 sounded = False tl = function(sinze_id=config.settings[name][-1]["id"], screen_name=param, count=config.main["general"]["max_tweets_per_call"]) tl.reverse() for i in tl: if i["id"] > config.settings[name][-1]["id"] and utils.is_allowed( i) == True: config.settings[name].append(i) sounded = True num = num + 1 if sounded == True: sound.play(sndFile) return num
def kick(irc, event, args): """[<channel>] <nick> [<nick>...] [:][<reason>] Kicks <nick> in <channel>. <channel> is only necessary if the command isn't sent in the channel itself. It is recommended to use ':' as a seperator between <nick> and <reason>, otherwise, if there's a nick in the channel matching the first word in reason it will be kicked. """ prepare_nicks = [] reason = None try: if utils.is_private(event): channel = args[0] nicks = args[1:] else: if irc.is_channel(args[0]): channel = args[0] nicks = args[1:] else: channel = event.target nicks = args except IndexError: irc.reply(event, utils.gethelp("kick")) else: if utils.is_allowed(irc, event.source, channel): for nick in nicks: if nick in irc.state["channels"][channel]["names"] and nick not in prepare_nicks and not nick.startswith(":"): prepare_nicks.append(nick) else: reason = " ".join(nicks[len(prepare_nicks):]).lstrip(": ") break nicks = prepare_nicks already_op = irc.is_opped(irc.get_nick(), channel) gotop = utils.getop(irc, channel) if gotop: for nick in nicks: if reason: irc.kick(channel, nick, reason) else: irc.kick(channel, nick) if not already_op: irc.mode(channel, "-o {}".format(irc.get_nick()))
def deop(irc, event, args): """[<channel>] [<nick>...] Deops <nick> (or yourself if no <nick> is specified) in <channel>. <channel> is only necessary if the command isn't set in the channel itself. """ setmodes = [] try: if len(args) == 0: nicks = [event.source.nick] channel = event.target elif irc.is_channel(args[0]): channel = args[0] if len(args) > 1: nicks = args[1:] else: nicks = [event.source.nick] else: nicks = args channel = event.target except IndexError: irc.reply(event, utils.gethelp("deop")) else: if utils.is_allowed(irc, event.source, channel): already_op = irc.is_opped(irc.get_nick(), channel) if "*" in nicks: nicks = irc.state["channels"][channel]["names"] if irc.get_nick() in nicks: nicks.remove(irc.get_nick()) if irc.channels[channel].get("chanserv", irc.chanserv) and "ChanServ" in nicks: nicks.remove("ChanServ") for nick in nicks: if irc.is_opped(nick, channel): setmodes.append("-o {}".format(nick)) if len(setmodes) == 0: return if not already_op: setmodes.append("-o {}".format(irc.get_nick())) gotop = utils.getop(irc, channel) if gotop: for mode in utils.unsplit_modes(setmodes): irc.mode(channel, mode)
def sdevoice(irc, event, args): """[<channel>] [<nick>...] Devoices <nick> (or the bot if no <nick> is given) in <channel> using services. <channel> is only necessary if the command isn't sent in the channel itself. """ try: if utils.is_private(event): channel = args[0] if len(args) > 1: nicks = args[1:] else: nicks = [irc.get_nick()] else: if len(args) > 0: if irc.is_channel(args[0]): channel = args[0] if len(args) > 1: nicks = args[1:] else: nicks = [irc.get_nick()] else: channel = event.target nicks = args else: channel = event.target nicks = [irc.get_nick()] except IndexError: irc.reply(event, utils.gethelp("sdevoice")) else: if utils.is_allowed(irc, event.source, channel): try: if irc.channels[channel].get("chanserv", irc.chanserv): for nick in nicks: if not irc.is_voiced(nick, channel): nicks.remove(nick) if len(nicks) > 0: irc.privmsg("ChanServ", "DEVOICE {} {}".format(channel, " ".join(nicks))) except KeyError: pass
def uninstall(irc, event, args, utils = utils): plugin_sources = check(irc) if utils.is_owner(irc, event.source): try: if utils.is_allowed(irc, event.source, event.target): for plugin_source_url in irc.plugins[name]["urls"]: for plugin in irc.plugins[name]["urls"][plugin_source_url]: if plugin in os.listdir("plugins") and args[0] == plugin.replace(".py", ""): try: irc.reply(event, "Uninstalling plugin") os.remove("plugins/" + plugin) irc.reply(event, "Plugin successfully uninstalled") except: irc.reply(event, "That plugin cannot be uninstalled") elif plugin not in os.listdir("plugins") and args[0] == plugin.replace(".py", ""): irc.reply(event, "That plugin isn't installed") else: pass except KeyError: pass
def launch(symbol): try: precision = get_precision(symbol) pip = get_pip(symbol) price_precision = len( '{0:.10f}'.format(pip).split('.')[1].split('1')[0]) + 1 to_general_log(symbol, 'Start monitoring') while is_allowed(symbol): # looking for BUY signal if get_price_change_percent_difference(symbol) > 2: place_pending_order(symbol, 'buy', precision, price_precision) break # looking for SELL signal if get_price_change_percent_difference(symbol) > 2: place_pending_order(symbol, 'sell', precision, price_precision) break time.sleep(1) except: to_err_log(symbol, traceback.format_exc())
def factoid(irc, event, args): """<add|remove|list> [<channel>] <factoid> [<text>] Adds or removes a factoid for <channel> or globally. <channel> is only necessary if the command isn't sent in the channel itself, <text> is only necessary if adding a factoid. Global factoids are modified by sending the command in private with no <channel> specified. """ try: if args[0] == "add": if irc.is_channel(args[1]): channel = args[1] factoid = args[2] text = " ".join(args[3:]) elif irc.is_channel(event.target): channel = event.target factoid = args[1] text = " ".join(args[2:]) else: channel = None factoid = args[1] text = " ".join(args[2:]) if channel: if utils.is_allowed(irc, event.source, channel): if "factoids" not in irc.channels[channel]: irc.channels[channel]["factoids"] = {} irc.channels[channel]["factoids"][factoid] = text irc.reply(event, "Factoid {} added for '{}' in {}".format(factoid, text, channel)) else: if utils.is_allowed(irc, event.source): irc.factoids[factoid] = text irc.reply(event, "Global factoid {} added for '{}'".format(factoid, text)) elif args[0] == "remove": if irc.is_channel(args[1]): channel = args[1] factoid = args[2] elif irc.is_channel(event.target): channel = event.target factoid = args[1] else: channel = None factoid = args[1] if channel: if utils.is_allowed(irc, event.source, channel): if "factoids" not in irc.channels[channel]: irc.reply(event, "ERROR: No factoids exist for {}".format(channel)) elif factoid in irc.channels[channel]["factoids"]: del (irc.channels[channel]["factoids"][factoid]) irc.reply(event, "Factoid {} deleted in {}".format(factoid, channel)) else: if utils.is_allowed(irc, event.source): if factoid in irc.factoids: del (irc.factoids[factoid]) irc.reply(event, "Global factoid {} deleted".format(factoid)) else: irc.reply(event, "ERROR: No global factoids named {} were found".format(factoid)) elif args[0] == "list": if len(args) > 1: if irc.is_channel(args[1]): channel = args[1] elif irc.is_channel(event.target): channel = event.target elif irc.is_channel(event.target): channel = event.target else: channel = None if channel: if "factoids" in irc.channels[channel]: irc.reply( event, "Factoids for {} are: {}".format( channel, ", ".join(['"{}"'.format(x) for x in irc.channels[channel]["factoids"]]) ), ) else: irc.reply(event, "No factoids were found for {}".format(channel)) else: irc.reply(event, "Global factoids are: {}".format(", ".join(['"{}"'.format(x) for x in irc.factoids]))) except (KeyError, IndexError): irc.reply(event, utils.gethelp("factoid"))
def kban(irc, event, args): """[<channel>] <nick|hostmask> [<nick|hostmask>...] [:][<reason>] Bans <nick> in <channel> and kicks anyone affected using <reason> as the kick message if specified. <channel> is only necessary if the command isn't sent in the channel itself. It is recommended to use ':' as a seperator between <nick> and <reason>, otherwise, if there's a nick in the channel matching the first word in reason it will be kicked. """ prepare_nicks = [] setmodes = [] affected = [] reason = None try: if utils.is_private(event): channel = args[0] nicks = args[1:] else: if irc.is_channel(args[0]): channel = args[0] nicks = args[1:] else: channel = event.target nicks = args except IndexError: irc.reply(event, utils.gethelp("kban")) else: if utils.is_allowed(irc, event.source, channel): for nick in nicks: if nick in irc.state["channels"][channel]["names"] and nick not in prepare_nicks and not nick.startswith(":"): prepare_nicks.append(nick) elif utils.is_hostmask(nick): prepare_nicks.append(nick) else: reason = " ".join(nicks[len(prepare_nicks):]).lstrip(": ") break nicks = prepare_nicks for nick in nicks: if utils.is_hostmask(nick): bmask = nick else: bmask = utils.banmask(irc, nick) setmodes.append("+b {}".format(bmask)) for affect in utils.ban_affects(irc, channel, bmask): if affect not in affected and affect != irc.get_nick(): if irc.is_opped(affect, channel): setmodes.append("-o {}".format(affect)) if irc.is_voiced(affect, channel): setmodes.append("-v {}".format(affect)) affected.append(affect) if len(setmodes) == 0: return already_op = irc.is_opped(irc.get_nick(), channel) gotop = utils.getop(irc, channel) if gotop: for mode in utils.unsplit_modes(setmodes): irc.mode(channel, mode) for nick in affected: if reason: irc.kick(channel, nick, reason) else: irc.kick(channel, nick) if not already_op: irc.mode(channel, "-o {}".format(irc.get_nick()))
def alias(irc, event, args): """<add|remove|list> [<channel>] <alias> [<command>] Adds or removes an alias for <channel> or globally. <channel> is only necessary if the command isn't sent in the channel itself, <command> is only necessary if adding an alias. Global aliases are modified by sending the command in private with no <channel> specified. """ try: if args[0] == "add": if irc.is_channel(args[1]): channel = args[1] alias = args[2] command = " ".join(args[3:]) elif irc.is_channel(event.target): channel = event.target alias = args[1] command = " ".join(args[2:]) else: channel = None alias = args[1] command = " ".join(args[2:]) if channel: if utils.is_allowed(irc, event.source, channel): if len(command) >= 2 and command.split()[0] in utils.commands: #and alias.lower() not in utils.commands: if "aliases" not in irc.channels[channel]: irc.channels[channel]["aliases"] = {} if alias != alias.lower(): irc.reply(event, "The alias name has to be lowercase. Changing alias name...") alias = alias.lower() if alias in utils.commands: irc.reply(event, "Alias \"{}\" is a command and cannot be overwritten".format(alias)) else: irc.channels[channel]["aliases"][alias] = command irc.reply(event, "Alias \"{}\" with arguments \"{}\" added for command \"{}\" in \"{}\"".format(alias, " ".join(command.split()[1:]), command.split()[0], channel)) elif command.split()[0] in utils.commands and alias not in utils.commands: if "aliases" not in irc.channels[channel]: irc.channels[channel]["aliases"] = {} if alias != alias.lower(): irc.reply(event, "The alias name has to be lowercase. Changing alias name...") alias = alias.lower() irc.reply(event, "testing") irc.channels[channel]["aliases"][alias] = command irc.reply(event, "Alias \"{}\" added for command \"{}\" in \"{}\"".format(alias, command, channel)) elif alias in utils.commands: irc.reply(event, "A command with the name \"{}\" already exists".format(alias)) elif not command.split()[0] in utils.commands: irc.reply(event, "No command called \"{}\" exists".format(command.split()[0])) else: if utils.is_allowed(irc, event.source) and command in utils.commands and alias not in utils.commands: irc.aliases[alias] = command irc.reply(event, "Global alias \"{}\" added for command \"{}/\"".format(alias, command)) elif alias in utils.commands: irc.reply(event, "A command with the name \"{}\" already exists".format(command)) elif not command in utils.commands: irc.reply(event, "No command called \"{}\" exists".format(command)) elif args[0] == "remove": if irc.is_channel(args[1]): channel = args[1] alias = args[2] elif irc.is_channel(event.target): channel = event.target alias = args[1] else: channel = None alias = args[1] if channel: if utils.is_allowed(irc, event.source, channel): if "aliases" not in irc.channels[channel]: irc.reply(event, "ERROR: No aliases exist for \"{}\"".format(channel)) elif alias not in irc.channels[channel]["aliases"]: irc.reply(event, "Alias \"{}\" does not exist in \"{}\"".format(alias, channel)) elif alias in irc.channels[channel]["aliases"]: del(irc.channels[channel]["aliases"][alias]) irc.reply(event, "Alias \"{}\" deleted in \"{}\"".format(alias, channel)) else: if utils.is_allowed(irc, event.source): if alias in irc.aliases: del(irc.aliases[alias]) irc.reply(event, "Global alias {} deleted".format(alias)) else: irc.reply(event, "ERROR: No global aliases named {} were found".format(alias)) elif args[0] == "list": if len(args) > 1: if irc.is_channel(args[1]): channel = args[1] elif irc.is_channel(event.target): channel = event.target elif irc.is_channel(event.target): channel = event.target else: channel = None if channel: if "aliases" in irc.channels[channel]: irc.reply(event, "Aliases for {} are: {}".format(channel, ", ".join(["\"{}\"".format(x) for x in irc.channels[channel]["aliases"]]))) else: irc.reply(event, "No aliases were found for {}".format(channel)) else: irc.reply(event, "Global aliases are: {}".format(", ".join(["\"{}\"".format(x) for x in irc.aliases]))) except (KeyError, IndexError): irc.reply(event, utils.gethelp("alias"))