async def launch(self): print(f"[Cluster Manager] Starting a total of {config.BOT_CLUSTERS} clusters.") self.bot = ModMail(cluster_id=0, cluster_count=int(config.BOT_CLUSTERS)) await self.bot.start(worker=False) self.bot.id = (await self.bot.real_user()).id self.bot.state.id = self.bot.id async with self.bot.pool.acquire() as conn: exists = await conn.fetchrow( "SELECT EXISTS (SELECT relname FROM pg_class WHERE relname = 'data')" ) if exists[0] is False: with open("schema.sql", "r") as file: await conn.execute(file.read()) for i in range(int(config.BOT_CLUSTERS)): self.instances.append(Instance(i + 1, loop=self.loop, main=self)) self.write_targets() scheduler = Scheduler(loop=self.loop, bot=self.bot) loop.create_task(scheduler.launch()) server = web.Server(self.handler) runner = web.ServerRunner(server) await runner.setup() site = web.TCPSite(runner, config.BOT_API_HOST, int(config.BOT_API_PORT)) await site.start()
logger = logging.getLogger() logger.setLevel(logging.INFO) handler = logging.FileHandler(filename=f"logs/cluster-{cluster_id}.log", encoding="utf-8", mode="w") handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) log = logging.getLogger(__name__) async def command_prefix(bot2, message): prefix = await tools.get_guild_prefix(bot2, message.guild) return [f"<@{bot.id}> ", f"<@!{bot.id}> ", prefix] bot = ModMail( command_prefix=?, bot_id=825273370953515018, cluster_id=cluster_id, cluster_count=cluster_count, version="3.0.0", ) @bot.event async def on_message(_): pass loop = asyncio.get_event_loop() loop.run_until_complete(bot.start())
mode="w") handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) def _get_guild_prefix(bot2, message): prefix = get_guild_prefix(bot2, message) return commands.when_mentioned_or(prefix)(bot2, message) bot = ModMail( fetch_offline_members=True, command_prefix=_get_guild_prefix, case_insensitive=True, description="The one and only public ModMail Discord bot.", help_command=None, owner_id=config.owner, heartbeat_timeout=300, ) c = bot.conn.cursor() c.execute( "CREATE TABLE IF NOT EXISTS data " "(guild bigint NOT NULL PRIMARY KEY, prefix text, category bigint, accessrole text, " "logging bigint, welcome text, goodbye text, loggingplus integer, pingrole text, blacklist text, anon integer)" ) c.execute( "CREATE TABLE IF NOT EXISTS premium (user bigint NOT NULL PRIMARY KEY, server text)" ) c.execute(
def _get_guild_prefix(bot2, message): prefix = get_guild_prefix(bot2, message.guild) return commands.when_mentioned_or(prefix)(bot2, message) bot = ModMail( intents=discord.Intents(guilds=True, members=True, presences=True, messages=True, reactions=True), member_cache_flags=None, chunk_guilds_at_startup=config.fetch_all_members, command_prefix=_get_guild_prefix, case_insensitive=True, help_command=None, owner_id=config.owner, heartbeat_timeout=300, shard_ids=shard_ids, shard_count=shard_count, cluster_id=cluster_id, cluster_count=cluster_count, version="2.1.1", ) @bot.event async def on_message(_): pass
encoding="utf-8", mode="w") handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) log = logging.getLogger(__name__) async def command_prefix(bot2, message): prefix = await tools.get_guild_prefix(bot2, message.guild) return [f"<@{bot.id}> ", f"<@!{bot.id}> ", prefix] bot = ModMail( command_prefix=command_prefix, bot_id=bot_id, cluster_id=cluster_id, cluster_count=cluster_count, version="3.0.0", ) @bot.event async def on_message(_): pass loop = asyncio.get_event_loop() loop.run_until_complete(bot.start())
log = logging.getLogger(__name__) def _get_guild_prefix(bot2, message): prefix = get_guild_prefix(bot2, message.guild) return commands.when_mentioned_or(prefix)(bot2, message) bot = ModMail( fetch_offline_members=config.fetch_all_members, command_prefix=_get_guild_prefix, case_insensitive=True, help_command=None, owner_id=config.owner, heartbeat_timeout=300, shard_ids=shard_ids, shard_count=shard_count, cluster_id=cluster_id, cluster_count=cluster_count, version="2.0.1", ) @bot.event async def on_message(_): pass loop = asyncio.get_event_loop() loop.run_until_complete(bot.start_bot())