Пример #1
0
    def __init__(self):
        super().__init__(command_prefix=get_prefix, reconnect=True, case_insensitive=True)

        # Bot vars
        self.embed_color = 0xFE8000
        self.loop = asyncio.get_event_loop()
        self.andesite = andesite.Client(self)
        self.session = aiohttp.ClientSession(loop=self.loop)

        # Loading the extensions
        for extension in BOT_EXTENSIONS:
            try:
                self.load_extension(extension)
            except Exception as e:
                print(f'[WARNING] Could not load extension {extension}: {e}')
Пример #2
0
def create_pool(http_nodes: Iterable[NodeDetails],
                web_socket_nodes: Iterable[NodeDetails], *,
                user_id: int,
                state: andesite.StateArgumentType = None,
                http_pool_kwargs: Mapping[str, Any] = None,
                web_socket_pool_kwargs: Mapping[str, Any] = None) -> andesite.Client:
    """Create an `Client` with client pools.

    Uses `HTTPBase` and `WebSocketBase` which are contained in
    `HTTPPoolBase` and `WebSocketPoolBase` pools respectively.

    Args:
        http_nodes: Tuples of [uri, password] for each REST node to connect to.
        web_socket_nodes: Tuples of [uri, password] for each WebSocket node to
            connect to.
        user_id: Bot's user id.
        state: State handler to use for the pools. Defaults to `State`,
            because a state handler is required for node migration to work. You
            can pass `False` to disable state handling though.
        http_pool_kwargs: Additional keyword arguments to pass to the http pool
            constructor.
        web_socket_pool_kwargs: Additional keyword arguments to pass to the web
            socket pool constructor.

    Returns:
        A combined Andesite client operation on an http pool and a web socket
        pool.
    """
    http_clients = []
    for uri, password in http_nodes:
        http_clients.append(andesite.HTTPBase(uri, password))

    web_socket_clients = []
    for uri, password in web_socket_nodes:
        ws = andesite.WebSocketBase(uri, user_id, password, state=False)
        web_socket_clients.append(ws)

    http_pool_kwargs = http_pool_kwargs or {}
    http_pool = HTTPPoolBase(http_clients, **http_pool_kwargs)

    web_socket_pool_kwargs = web_socket_pool_kwargs or {}
    web_socket_pool = WebSocketPoolBase(web_socket_clients, **web_socket_pool_kwargs)

    inst = andesite.Client(http_pool, web_socket_pool)

    # the setter will make sure the state is proper
    inst.state = state
    return inst
Пример #3
0
    async def on_ready(self):

        print(f"\n[BOT] Logged in as {self.bot.user} - {self.bot.user.id}")

        # If we are connected to the database.
        if self.bot.db_ready is True:

            # Create config for bots guilds.
            print("\n[DB] Adding guilds.")

            # Loop through all the bots guilds.
            for guild in self.bot.guilds:

                # If the guild already has a config, skip it.
                if await self.bot.db.fetchrow(
                        "SELECT * FROM guild_config WHERE key = $1", guild.id):
                    continue

                # Else create a config for the guild.
                await self.bot.db.execute(
                    "INSERT INTO guild_config VALUES ($1)", guild.id)
                print(f"\n[DB] Created config for guild - {guild.name}.")

            print("[DB] Done adding guilds.")

        # Initialise andesite nodes.
        self.bot.andesite = andesite.Client(self.bot)
        await self.initiate_nodes()

        # Set our user/guild blacklists.
        blacklisted_users = await self.bot.db.fetch(
            "SELECT * FROM user_blacklist")
        blacklisted_guilds = await self.bot.db.fetch(
            "SELECT * FROM guild_blacklist")

        for i in range(len(blacklisted_users)):
            self.bot.user_blacklist.append(int(blacklisted_users[i]["id"]))
        for i in range(len(blacklisted_guilds)):
            self.bot.guild_blacklist.append(int(blacklisted_guilds[i]["id"]))

        # Leave any guilds that are blacklisted.
        for guild in self.bot.guilds:
            if guild.id in self.bot.guild_blacklist:
                await guild.leave()
                print(f"[BOT] Left blacklisted guild - {guild.id}")
Пример #4
0

async def unload_prefixes():
    await bot.db.execute("DELETE FROM prefixes;")
    await bot.db.executemany(
        "INSERT INTO prefixes(guild_id, prefixes) VALUES ($1, $2)",
        bot.prefixes.items())
    logger.info("Unloaded prefixes")


async def connect_node():
    await bot.andesite.start_node("127.0.0.1",
                                  5000,
                                  rest_uri="http://127.0.0.1:5000/",
                                  password=None,
                                  identifier="Main")


bot.andesite = andesite.Client(bot)

bot.add_ready_func(connect_db)
bot.add_ready_func(load_prefixes)

bot.add_ready_func(connect_node)
bot.add_ready_func(bot.load_extension, "extras.logger")

bot.add_logout_func(unload_prefixes)
bot.add_logout_func(disconnect_db)

bot.run(config.token)