diff options
author | 2020-08-27 20:49:29 +0100 | |
---|---|---|
committer | 2020-08-27 20:49:29 +0100 | |
commit | e05884b8753a2da1d7d3a34a34dd9654babb6d38 (patch) | |
tree | 5f71de1ab688af9a2161b282181fcd0988b648e4 | |
parent | Remove opt_out from upsert (diff) |
Wait for DB before performing any operations
-rw-r--r-- | core.py | 53 | ||||
-rw-r--r-- | metricity/bot.py | 13 |
2 files changed, 65 insertions, 1 deletions
@@ -0,0 +1,53 @@ +ClippySettings = None +Forbidden = None + +async def cmd_usage(client, message, cmds): + try: + if message.content.lower().startswith(ClippySettings.commandprefix + 'usage help'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "help`:\nDescription: Shows the help menu.\nUsage: `" + ClippySettings.commandprefix + "help`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage info'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "info`:\nDescription: Shows details about the bot.\nUsage: `" + ClippySettings.commandprefix + "info`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage calc'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "calc`:\nDescription: Solves basic math equations.\nUsage: `" + ClippySettings.commandprefix + "calc <equation>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage afk'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "afk`:\nDescription: Tells the channel that you are now afk.\nUsage: `" + ClippySettings.commandprefix + "afk`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage unafk'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "unafk`:\nDescription: Tells the channel that you are no longer afk.\nUsage: `" + ClippySettings.commandprefix + "unafk`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage ping'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "ping`:\nDescription: Tests to see if the bot is still alive.\nUsage: `" + ClippySettings.commandprefix + "ping`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage date'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "date`:\nDescription: **Will** show your current time/date. Currently it only shows the bots.\nUsage: `" + ClippySettings.commandprefix + "date <timezone>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage shoot'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "shoot`:\nDescription: Shoots a person.\nUsage: `" + ClippySettings.commandprefix + "shoot <@User>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage 8ball'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "8ball`:\nDescription: Tells your fortune.\nUsage: `" + ClippySettings.commandprefix + "8ball <message>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage rr'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "rr`:\nDescription: Simulates a game of Russian Roulette.\nUsage: `" + ClippySettings.commandprefix + "rr`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage say'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "say`:\nDescription: Makes the bot say a message.\nUsage: `" + ClippySettings.commandprefix + "say <message>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage avatar'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "avatar`:\nDescription: Gives the avatar of the mentioned user.\nUsage: `" + ClippySettings.commandprefix + "avatar <@User>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage timer'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "timer`:\nDescription: **Will** set a timer to remind you of something.\nUsage: `" + ClippySettings.commandprefix + "timer <seconds> <message>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage weather'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "weather`:\nDescription: **Will** show your current weather.\nUsage: `" + ClippySettings.commandprefix + "weather <location>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage join'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "join`:\nDescription: Makes the bot join the desired Discord link.\nUsage: `" + ClippySettings.commandprefix + "join <link>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage awwshit'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "awwshit`:\nDescription: Gives you a handy dandy meme.\nUsage: `" + ClippySettings.commandprefix + "awwshit`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage translate'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "translate`:\nDescription: **Will** translate a phrase.\nUsage: `" + ClippySettings.commandprefix + "translate '<message>' '<to-language>'`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage speak'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "speak`:\nDescription: Makes the bot say a text-to-speech message.\nUsage: `" + ClippySettings.commandprefix + "speak <message>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage roti'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "roti`:\nDescription: Gives you one of the 102 rules of the internet.\nUsage: `" + ClippySettings.commandprefix + "roti <1-102>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage usage'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "usage`:\nDescription: Gives a description of a command and how to use it.\nUsage: `" + ClippySettings.commandprefix + "usage <command>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage wiki'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "wiki`:\nDescription: Gives you info on the specified topic as well as a link for more info.\nUsage: `" + ClippySettings.commandprefix + "wiki <topic>`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage quote'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "quote`:\nDescription: A randomized quote to spruce up your day.\nUsage: `" + ClippySettings.commandprefix + "quote`.") + elif message.content.lower().startswith(ClippySettings.commandprefix + 'usage emojis'): + await client.send_message(message.channel, "Info for the command `" + ClippySettings.commandprefix + "emojis`:\nDescription: Type `" + ClippySettings.commandprefix + "emojis` for 4 helpful emojis, and `" + ClippySettings.commandprefix + "emojis long` for the link to the whole list.\nUsage: `" + ClippySettings.commandprefix + "emojis/emojis long`.") + except Forbidden: + pass diff --git a/metricity/bot.py b/metricity/bot.py index 5176e81..fb40c97 100644 --- a/metricity/bot.py +++ b/metricity/bot.py @@ -24,7 +24,7 @@ bot = Bot( sync_process_complete = asyncio.Event() channel_sync_in_progress = asyncio.Event() - +db_ready = asyncio.Event() async def sync_channels(guild: Guild) -> None: """Sync channels and categories with the database.""" @@ -89,11 +89,14 @@ async def on_ready() -> None: """Initiate tasks when the bot comes online.""" log.info(f"Metricity is online, logged in as {bot.user}") await connect() + db_ready.set() @bot.event async def on_guild_channel_create(channel: Messageable) -> None: """Sync the channels when one is created.""" + await db_ready.wait() + if channel.guild.id != BotConfig.guild_id: return @@ -103,6 +106,8 @@ async def on_guild_channel_create(channel: Messageable) -> None: @bot.event async def on_guild_channel_update(_before: Messageable, channel: Messageable) -> None: """Sync the channels when one is updated.""" + await db_ready.wait() + if channel.guild.id != BotConfig.guild_id: return @@ -112,6 +117,8 @@ async def on_guild_channel_update(_before: Messageable, channel: Messageable) -> @bot.event async def on_guild_available(guild: Guild) -> None: """Synchronize the user table with the Discord users.""" + await db_ready.wait() + log.info(f"Received guild available for {guild.id}") if guild.id != BotConfig.guild_id: @@ -153,6 +160,7 @@ async def on_guild_available(guild: Guild) -> None: @bot.event async def on_member_join(member: Member) -> None: """On a user joining the server add them to the database.""" + await db_ready.wait() await sync_process_complete.wait() if member.guild.id != BotConfig.guild_id: @@ -184,6 +192,7 @@ async def on_member_join(member: Member) -> None: @bot.event async def on_member_remove(member: Member) -> None: """On a user leaving the server mark in_guild as False.""" + await db_ready.wait() await sync_process_complete.wait() if member.guild.id != BotConfig.guild_id: @@ -239,6 +248,8 @@ async def on_member_update(_before: Member, member: Member) -> None: @bot.event async def on_message(message: DiscordMessage) -> None: """Add a message to the table when one is sent providing the author has accepted.""" + await db_ready.wait() + if message.channel.id == BotConfig.bot_commands_channel: await bot.process_commands(message) |