Exemple #1
0
def load_plugin(name: str, package: str = "plugins"):
    """ Load a plugin with the name name. If package isn't specified, this
    looks for plugin with specified name in /plugins/

    Any loaded plugin is imported and stored in the self.plugins dictionary.
    """
    if not name.startswith("__") or not name.endswith("__"):
        try:
            plugin = importlib.import_module("{package}.{plugin}".format(
                plugin=name, package=package))
        except ImportError as e:
            logging.error(
                "An error occurred when loading plugin {}:\n{}".format(
                    name, format_exception(e)))
            return False
        except:
            logging.error(
                "An error occurred when loading plugin {}:\n{}".format(
                    name, format_exc()))
            return False

        plugins[name] = plugin
        logging.debug("LOADED PLUGIN " + name)
        return True

    return False
Exemple #2
0
def cmd_eval(client: discord.Client, message: discord.Message,
             code: Annotate.Content):
    """ Evaluate an expression. """
    script = get_formatted_code(code)

    try:
        result = eval(script, globals(), locals())
    except Exception as e:
        result = format_exception(e)

    yield from client.send_message(message.channel, "**Result:** \n```{}\n```".format(result))
Exemple #3
0
def cmd_do(client: discord.Client, message: discord.Message,
           code: Annotate.Content):
    """  """
    def say(msg, c=message.channel):
        asyncio.async(client.send_message(c, msg))

    script = get_formatted_code(code)

    try:
        exec(script, locals(), globals())
    except Exception as e:
        say("```" + format_exception(e) + "```")
Exemple #4
0
def on_message(client: discord.Client, message: discord.Message, args: list):
    if args[0] in lambdas.data and args[0] not in lambda_blacklist:
        def say(msg, c=message.channel):
            asyncio.async(client.send_message(c, msg))

        def arg(i, default=0):
            if len(args) > i:
                return args[i]
            else:
                return default

        try:
            exec(lambdas.data[args[0]], locals(), globals())
        except Exception as e:
            if client.is_owner(message.author):
                say("```" + format_exception(e) + "```")

        logging.info("@{0.author} -> {0.content}".format(message))