""" automode.py - Provide simple channel ACL management by giving prefix modes to users matching hostmasks or exttargets. """ import collections from pylinkirc import utils, conf, world, structures from pylinkirc.log import log from pylinkirc.coremods import permissions mydesc = ( "The \x02Automode\x02 plugin provides simple channel ACL management by giving prefix modes " "to users matching hostmasks or exttargets.") # Register ourselves as a service. modebot = utils.registerService("automode", desc=mydesc) reply = modebot.reply error = modebot.error # Databasing variables. dbname = utils.getDatabaseName('automode') datastore = structures.JSONDataStore('automode', dbname, default_db=collections.defaultdict(dict)) db = datastore.store # The default set of Automode permissions. default_permissions = { "$ircop": [ 'automode.manage.relay_owned', 'automode.sync.relay_owned',
# cs.py: some chanserv based things from pylinkirc import utils, world from pylinkirc.log import log desc = "Welcome bot. Messages newly registered channels with helpful info." welcome = utils.registerService("welcome", nick="Welcome", ident="Welcome", desc=desc) def hook_privmsg(irc, source, command, args): weuid = irc.nickToUid('Welcome') channel = args['target'] text = args['text'] # irc.pseudoclient stores the IrcUser object of the main PyLink client. # (i.e. the user defined in the bot: section of the config) if 'used REGISTER on' in text and channel == '#debug': nick = text.split() nick = nick[1] nick = nick.split('!') nick = nick[0] regchannel = text.split() regchannel = regchannel[6] irc.proto.join(weuid, regchannel) irc.proto.message(weuid, regchannel, 'Welcome to ElectroCode, %s' % nick)
utils.add_hook(handle_kick, 'KICK') def handle_commands(irc, source, command, args): """Handle commands sent to the PyLink service bots (PRIVMSG).""" target = args['target'] text = args['text'] sbot = irc.isServiceBot(target) if sbot: sbot.call_cmd(irc, source, text) utils.add_hook(handle_commands, 'PRIVMSG') # Register the main PyLink service. All command definitions MUST go after this! mynick = conf.conf['bot'].get("nick", "PyLink") myident = conf.conf['bot'].get("ident", "pylink") # TODO: be more specific, and possibly allow plugins to modify this to mention # their features? mydesc = "\x02%s\x02 provides extended network services for IRC." % mynick utils.registerService('pylink', nick=mynick, ident=myident, desc=mydesc, manipulatable=True)
log.debug('(%s) services_support: respawning service %s after KILL.', irc.name, servicename) spawn_service(irc, source, command, {'name': servicename}) utils.add_hook(handle_kill, 'KILL') def handle_kick(irc, source, command, args): """Handle KICKs to the PyLink service bots, rejoining channels as needed.""" kicked = args['target'] channel = args['channel'] sbot = irc.getServiceBot(kicked) if sbot: sbot.join(irc, channel) utils.add_hook(handle_kick, 'KICK') def handle_commands(irc, source, command, args): """Handle commands sent to the PyLink service bots (PRIVMSG).""" target = args['target'] text = args['text'] sbot = irc.getServiceBot(target) if sbot: sbot.call_cmd(irc, source, text) utils.add_hook(handle_commands, 'PRIVMSG') # Register the main PyLink service. All command definitions MUST go after this! # TODO: be more specific, and possibly allow plugins to modify this to mention # their features? mydesc = "\x02PyLink\x02 provides extended network services for IRC." utils.registerService('pylink', desc=mydesc, manipulatable=True)
# - ident=None: The fallback ident that the service bot should use if nothing is specified # in the config (i.e. both serverdata:SERVICENAME_ident and # conf:SERVICE:ident are missing). If left empty, the fallback ident will # just be the service name. # # - manipulatable=False: Determines whether the service bot should be manipulable by things like # the 'join' command in the 'bots' plugin. Depending on the nature of your # plugin, it's really up to you whether you want to enable this. # # - desc=None: An optional service description that's shown (if present) when the 'help' # command is called without an argument. mydesc = "Example service plugin." # Note: the service name is case-insensitive and always lowercase. servicebot = utils.registerService("exampleserv", manipulatable=True, desc=mydesc, nick='ExampleServ') # These convenience assignments allow calling reply() and error() more quickly, but you can remove # them and call the functions directly if you don't want them. reply = servicebot.reply error = servicebot.error # Command functions for service bots are mostly the same as commands for the main PyLink client, # with a couple of key differences: def greet(irc, source, args): """takes no arguments. Greets the caller. """
""" games.py: Create a bot that provides game functionality (dice, 8ball, etc). """ import random import urllib.request import urllib.error from xml.etree import ElementTree from pylinkirc import utils from pylinkirc.log import log mydesc = "The \x02Games\x02 plugin provides simple games for IRC." gameclient = utils.registerService("Games", manipulatable=True, desc=mydesc) reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply() # commands def dice(irc, source, args): """<num>d<sides> Rolls a die with <sides> sides <num> times. """ if not args: reply(irc, "No string given.") return try: # Split num and sides and convert them to int. num, sides = map(int, args[0].split('d', 1)) except ValueError: # Invalid syntax. Show the command help.
# Config # ## use_mode = conf.conf.get("quote", {}).get("mode", "testing") config_url = conf.conf.get("quote", {}).get("db", "") engine = create_engine(config_url) meta = MetaData() meta.reflect(bind=engine) dbc = Table("channels", meta, autoload=True, autoload_with=engine) dbq = Table("quote", meta, autoload=True, autoload_with=engine) dbcd = Table("channel_data", meta, autoload=True, autoload_with=engine) desc = "Quote bot, stores channel quotes." quote = utils.registerService("quote", nick="Quote", ident="quote", desc=desc) reply = quote.reply error = quote.error default_permissions = {"$ircop": ['quotes.admin']} ## # # End Config # #### # # Helper Functions # ## def format(info, chan=None):
# connversion.py: version users on connect from pylinkirc import utils, world, conf from pylinkirc.log import log import time desc = "CTCP bot, versions connecting users." ctcp = utils.registerService("ctcp", nick="Aurora", ident="ctcp", desc=desc) reply = ctcp.reply error = ctcp.error def hook_connversion(irc, source, command, args): oursids = irc.serverdata.get('sids', []) nickuid = source nicksid = irc.getServer(nickuid) nickts = int(irc.users[nickuid].ts) nowts = int(time.time()) result = args['text'] result = result.split() result = result[1:] result = (" ").join(result) result = result.strip('\x01') if nowts <= nickts + 15: if nicksid in oursids: myuid = ctcp.uids.get(irc.name) if args['text'].startswith('\x01') and args['text'].endswith( '\x01'): irc.proto.message(