from pylinkirc.log import log # Having a hard limit here is sensible because otherwise it can flood the client or server off. CHECKBAN_MAX_RESULTS = 200 def _checkban_positiveint(value): value = int(value) if value <= 0 or value > CHECKBAN_MAX_RESULTS: raise argparse.ArgumentTypeError( "%s is not a positive integer between 1 and %s." % (value, CHECKBAN_MAX_RESULTS)) return value checkban_parser = utils.IRCParser() checkban_parser.add_argument('banmask') checkban_parser.add_argument('target', nargs='?', default='') checkban_parser.add_argument('--channel', default='') checkban_parser.add_argument('--maxresults', type=_checkban_positiveint, default=50) def checkban(irc, source, args, use_regex=False): """<banmask> [<target nick or hostmask>] [--channel #channel] [--maxresults <num>] CHECKBAN provides a ban checker command based on nick!user@host masks, user@host masks, and PyLink extended targets. If a target nick or hostmask is given, this command returns whether the given banmask will match it.
except IndexError: # Arguments not given. irc.error( 'Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).' ) return except KeyError: # Unknown network. irc.error('No such network "%s" (case sensitive).' % netname) return except ValueError: irc.error('Invalid argument "%s" for <seconds>.' % seconds) return network.serverdata['autoconnect'] = seconds irc.reply("Done.") remote_parser = utils.IRCParser() remote_parser.add_argument('network') remote_parser.add_argument('--service', type=str, default='pylink') remote_parser.add_argument('command', nargs=utils.IRCParser.REMAINDER) @utils.add_cmd def remote(irc, source, args): """<network> [--service <service name>] <command> Runs <command> on the remote network <network>. Plugin responses sent using irc.reply() are supported and returned here, but others are dropped due to protocol limitations.""" permissions.checkPermissions(irc, source, ['networks.remote']) args = remote_parser.parse_args(args) netname = args.network
return cf.zones.dns_records.get(options.zone, params=body) def cf_rem(options): cf = get_cf() return cf.zones.dns_records.delete(options.zone, options.id) ## # # Arg Parsing # ## parser = utils.IRCParser() parser.set_defaults(zone=cf_conf.get("cf-zone", "")) subparsers = parser.add_subparsers() rr_add = subparsers.add_parser("add") rr_add.set_defaults(command="cf_add") rr_show = subparsers.add_parser("show") rr_show.set_defaults(command="cf_show") rr_rem = subparsers.add_parser("rem") rr_rem.set_defaults(command="cf_rem") ## # # Commands # ##
class DNSBLError(Exception): pass class Blacklists: def __init__(self): self.path = conf.conf.get('dnsbl', {}).get('path', 'blacklists.yml') def path(self): return self.path def _dict(self): return yaml.load(open(self.path, 'r'), Loader=yamlordereddictloader.Loader) def dump(self, updated_dict): yaml.dump(updated_dict, open(self.path, 'w'), default_flow_style=False) dnsbl_addrec = utils.IRCParser() dnsbl_addrec.add_argument('blacklist') dnsbl_addrec.add_argument('record', type=int) dnsbl_addrec.add_argument('reply', nargs=utils.IRCParser.REMAINDER) def addrec(irc, source, args): """<blacklist> <record> <reply...> Adds a record reply for the given blacklist. """ permissions.checkPermissions(irc, source, ["dnsbl.radd"]) args = dnsbl_addrec.parse_args(args) bls = Blacklists() config = bls._dict() if config.get("blacklists", {}): blacklist = args.blacklist if config.get('blacklists').get(blacklist, {}): record = args.record
if ids == []: error(irc, "No quotes exist for this channel") else: id_list = [x[0] for x in ids] random_id = random.choice(id_list) result = engine.execute( select([dbq]).where( and_(dbq.c.id == "%s" % random_id, dbq.c.channel == channel))).fetchone() row_dict = dict(result.items()) reply(irc, format(row_dict, chan=False)) quote.add_cmd(rquote, "quote") q_parser = utils.IRCParser() q_parser.add_argument("-i", "--id", action="store_true", default=True) q_parser.add_argument("-w", "--wildcard", action="store_true") q_parser.add_argument("-b", "--by", action="store_true") q_parser.add_argument("query") def q(irc, source, args): """<[options]> <query> Looks up a quote in the database for the current channel. In addition to just running the command with a quote ID, you are able to use the following switch arguments. -i/--id: Look up a quote by quote ID. (default)