def handle_aliasget(bot, ievent): """ not arguments - show aliases. (per user) """ aliases = ievent.chan.data.aliases if aliases: ievent.reply("channel aliases: %s" % str(aliases)) from tl.lib.aliases import getaliases aliases = getaliases() if aliases: ievent.reply("global aliases: %s" % aliases.tojson())
def handle_aliasmakeglobal(bot, ievent): """ no arguments - make channel aliases global. """ aliases = ievent.chan.data.aliases if not aliases: ievent.chan.data.aliases = aliases = {} from tl.lib.aliases import getaliases, savealiases galiases = getaliases() galiases.update(ievent.chan.data.aliases) savealiases() ievent.reply('global aliases updated')
def reloadcheck(self, bot, event, target=None): """ check if event requires a plugin to be reloaded. if so reload the plugin. """ from .boot import getcmndtable from .boot import plugins plugloaded = None plugin = None try: if not target: target = event.iscmnd().split()[0] if not target: target = event.txt.split()[0] except Exception as ex: target = None if not target: logging.debug("can't find target in %s" % event.txt) ; return from tl.lib.aliases import getaliases aliases = getaliases() try: target = aliases[target] except KeyError: try: target = event.chan.data.aliases[target] except (AttributeError, KeyError, TypeError): pass cmndtable = getcmndtable() if not target in cmndtable: try: short = getshorttable() if target in short: cmndlist = short[target] if len(cmndlist) == 1: target = cmndlist[0] except Exception as ex: handle_exception() if target: target = target.split()[0] logging.info("checking for reload of %s" % target) try: plugin = cmndtable[target] except KeyError: logging.warn("no cmnd for %s .. trying REGEX" % target) try: retable = getretable() for regex, mod in retable.items(): if re.search(regex, event.stripcc() or event.txt): plugin = mod ; break except Exception as ex: handle_exception() logging.info("plugin is %s" % plugin) if not plugin: logging.debug("can't find plugin to reload for %s" % target) ; return if plugin in bot.plugs: logging.info("%s already loaded" % plugin) ; return plugloaded elif plugin in plugins.data.refused: logging.warn("%s is refused" % plugin) ; return plugloaded elif bot.cfg.loadlist and plugin not in bot.cfg.loadlist: logging.warn("plugin %s is blacklisted" % plugin) ; return plugloaded logging.info("loaded %s on demand" % plugin) plugloaded = bot.plugs.reload(plugin) return plugloaded
def resolvealias(self, cmnd, event=None): alias = None if event: try: alias = event.chan.data.aliases[cmnd] except (KeyError, TypeError): pass if not alias: try: alias = getaliases()[cmnd] except (KeyError, TypeError): pass if not alias: if not cmnd in self: try: short = getshorttable() if cmnd in short: cmndlist = short[cmnd] if len(cmndlist) == 1: alias = cmndlist[0] else: event and event.reply("choose one of: ", cmndlist) ; return except Exception as ex: handle_exception() return alias