def ignore(inp, notice=None, bot=None, chan=None, db=None): """ignore [channel] <nick|host> -- Makes the bot ignore <nick|host>.""" ignorelist = database.get(db, 'channels', 'ignored', 'chan', chan) targets = inp.split() for target in targets: target = user.get_hostmask(target, db) if (user.is_admin(target, chan, db, bot)): notice( u"[{}]: {} is an admin and cannot be ignored.".format( chan, inp)) else: if ignorelist and target in ignorelist: notice(u"[{}]: {} is already ignored.".format(chan, target)) else: ignorelist = '{} {}'.format(target, ignorelist) database.set( db, 'channels', 'ignored', ignorelist, 'chan', chan) notice(u"[{}]: {} has been ignored.".format(chan, target)) return
def onmode(paraml, input=None, conn=None, raw=None, chan=None, db=None, bot=None): if '#defect' in chan.lower(): if not user.is_admin(input.mask,chan,db,bot): fixed_modes = [] params = [] param_num = 2 accepted_modes = 'vhoaql' doesnt_require_param = 'cntspmiBCMNRSzO' requires_param = 'klvhoaqbeI' modes = list(str(paraml[1])) for mode in modes: if mode is '+': fixed_modes.append(mode.replace('+','-')) elif mode is '-': fixed_modes.append(mode.replace('-','+')) else: if mode not in accepted_modes: if mode in doesnt_require_param: fixed_modes.append(mode) elif mode in requires_param: fixed_modes.append(mode) if mode not in 'kl': params.append(paraml[param_num]) param_num+=1 else: if mode in requires_param: param_num+=1 if len(fixed_modes) > 1: conn.send('MODE {} {} {}'.format(chan, ''.join(fixed_modes), ' '.join(params)))
def ignoresieve(bot, input, func, type, args): """ blocks input from ignored channels/nicks/hosts """ globalignorelist = bot.config["ignored"] db = bot.get_db_connection(input.conn) mask = input.mask.lower() chan = input.chan.lower() ignorelist = database.get(db,'channels','ignored','chan',chan) # don't block input to event hooks # if type == "event": return input if user.is_admin(mask,chan,db,bot): return input if ignorelist and user.format_hostmask(mask) in ignorelist: return None if globalignorelist and user.format_hostmask(mask) in globalignorelist: return None #print "[{}]: {} is ignored.".format(input.chan,mask) # if input.chan.lower() in ignorelist \ # or input.nick.lower().replace('~','') in ignorelist \ # or input.mask.lower().replace('~','').lower() in ignorelist: # if input.command == "PRIVMSG" and input.lastparam[1:] == "unignore": # return input # else: # return None return input
def onmode(paraml, input=None, conn=None, raw=None, chan=None, db=None, bot=None): if '#defect' in chan.lower(): if not user.is_admin(input.mask, chan, db, bot): fixed_modes = [] params = [] param_num = 2 accepted_modes = 'vhoaql' doesnt_require_param = 'cntspmiBCMNRSzO' requires_param = 'klvhoaqbeI' modes = list(str(paraml[1])) for mode in modes: if mode is '+': fixed_modes.append(mode.replace('+', '-')) elif mode is '-': fixed_modes.append(mode.replace('-', '+')) else: if mode not in accepted_modes: if mode in doesnt_require_param: fixed_modes.append(mode) elif mode in requires_param: fixed_modes.append(mode) if mode not in 'kl': params.append(paraml[param_num]) param_num += 1 else: if mode in requires_param: param_num += 1 if len(fixed_modes) > 1: conn.send(u'MODE {} {} {}'.format(chan, ''.join(fixed_modes), ' '.join(params)))
def commands(inp, say=None, notice=None, input=None, conn=None, bot=None, db=None): "commands -- Gives a list of commands/help for a command." funcs = {} disabled = bot.config.get('disabled_plugins', []) disabled_comm = bot.config.get('disabled_commands', []) for command, (func, args) in bot.commands.iteritems(): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1).lower() not in disabled and command not in disabled_comm: # Ignores disabled plugins and commands if args.get('channeladminonly', False) and not user.is_admin(input.mask, input.chan, db, bot): continue if args.get('adminonly', False) and not user.is_globaladmin(input.mask, input.chan, bot): continue if func.__doc__ is not None: if func in funcs: if len(funcs[func]) < len(command): funcs[func] = command else: funcs[func] = command commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: output = [] well = [] line = [] help = "For detailed help, do '{}help <example>' where <example> "\ "is the name of the command you want help for.".format(conn.conf["command_prefix"]) for command in commands: well.append(command) well.sort() for command in well: if output == [] and line == []: line.append("Commands you have access to ({}): {}".format(len(well), str(command))) else: line.append(str(command)) if len(", ".join(line)) > 405: output.append(", ".join(line)) line = [] if len(line) > 0: output.append(", ".join(line)) if len(output) == 1: output.append(help) for line in output: notice(line) else: output = ", ".join(output) # print(output) print bot.config.get('api_keys', {}).get('pastebin') pastebin_vars = {'api_dev_key': bot.config.get('api_keys', {}).get('pastebin'), 'api_option': 'paste', 'api_paste_code': output} response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars)) url = response.read() #haste = web.haste("{}\n\n{}".format(output, help)) notice("Commands you have access to ({}): {}".format(len(well), url)) elif inp in commands: notice("{}{}".format(conn.conf["command_prefix"], commands[inp].__doc__)) return
def is_authenticated(): try: token = decode_token(request.cookies.get('access_token_cookie'), request.cookies.get('csrf_access_token')) current_user = token.get("identity") IS_ADMIN = is_admin(current_user) except Exception as e: IS_ADMIN = False return jsonify({"admin": IS_ADMIN}), 200
def wrapper(*args, **kwds): try: token = decode_token(request.cookies.get('access_token_cookie'), request.cookies.get('csrf_access_token'), allow_expired=True) current_user = token.get("identity") if is_admin(current_user): return route(*args, **kwds) else: return redirect("/unauthorized"), 302 except Exception as e: print(str(e)) return redirect("/unauthorized"), 302
def ignore(inp, notice=None, bot=None, chan=None, db=None): """ignore [channel] <nick|host> -- Makes the bot ignore <nick|host>.""" ignorelist = database.get(db,'channels','ignored','chan',chan) targets = inp.split() for target in targets: target = user.get_hostmask(target,db) if (user.is_admin(target,chan,db,bot)): notice(u"[{}]: {} is an admin and cannot be ignored.".format(chan,inp)) else: if ignorelist and target in ignorelist: notice(u"[{}]: {} is already ignored.".format(chan, target)) else: ignorelist = '{} {}'.format(target,ignorelist) database.set(db,'channels','ignored',ignorelist,'chan',chan) notice(u"[{}]: {} has been ignored.".format(chan,target)) return
def commands(inp, say=None, notice=None, input=None, conn=None, bot=None, db=None): "commands -- Gives a list of commands/help for a command." funcs = {} disabled = bot.config.get('disabled_plugins', []) disabled_comm = bot.config.get('disabled_commands', []) for command, (func, args) in bot.commands.iteritems(): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1).lower( ) not in disabled and command not in disabled_comm: # Ignores disabled plugins and commands if args.get('channeladminonly', False) and not user.is_admin( input.mask, input.chan, db, bot): continue if args.get('adminonly', False) and not user.is_globaladmin( input.mask, input.chan, bot): continue if func.__doc__ is not None: if func in funcs: if len(funcs[func]) < len(command): funcs[func] = command else: funcs[func] = command commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: output = [] well = [] line = [] help = "For detailed help, do '{}help <example>' where <example> "\ "is the name of the command you want help for.".format(conn.conf["command_prefix"]) for command in commands: well.append(command) well.sort() for command in well: if output == [] and line == []: line.append("Commands you have access to ({}): {}".format( len(well), str(command))) else: line.append(str(command)) if len(", ".join(line)) > 405: output.append(", ".join(line)) line = [] if len(line) > 0: output.append(", ".join(line)) if len(output) == 1: output.append(help) for line in output: notice(line) else: output = ", ".join(output) # print(output) print bot.config.get('api_keys', {}).get('pastebin') pastebin_vars = { 'api_dev_key': bot.config.get('api_keys', {}).get('pastebin'), 'api_option': 'paste', 'api_paste_code': output.encode('utf-8') } response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars)) url = response.read() #haste = web.haste("{}\n\n{}".format(output, help)) notice("Commands you have access to ({}): {}".format( len(well), url)) elif inp in commands: notice("{}{}".format(conn.conf["command_prefix"], commands[inp].__doc__)) return