From 7ea4a6c20b5a6225549deeebb142b63f21dcb980 Mon Sep 17 00:00:00 2001 From: AEnterprise Date: Wed, 5 Oct 2022 21:43:20 +0200 Subject: [PATCH] updates from the last few months - move to database for configs - don't try to update messages in the database that are older then the max storage duration - bunch of general bugfixes --- GearBot/Bot/GearBot.py | 3 + GearBot/Bot/TheRealGearBot.py | 14 +- GearBot/Cogs/Admin.py | 2 +- GearBot/Cogs/AntiRaid.py | 12 +- GearBot/Cogs/AntiSpam.py | 50 +++--- GearBot/Cogs/Basic.py | 10 +- GearBot/Cogs/Censor.py | 24 +-- GearBot/Cogs/CustCommands.py | 12 +- GearBot/Cogs/DashLink.py | 8 +- GearBot/Cogs/Infractions.py | 2 +- GearBot/Cogs/Interactions.py | 12 +- GearBot/Cogs/ModLog.py | 24 +-- GearBot/Cogs/Moderation.py | 58 +++---- GearBot/Cogs/ServerAdmin.py | 194 +++++++++++------------ GearBot/Util/Archive.py | 4 +- GearBot/Util/Configuration.py | 89 +++++++---- GearBot/Util/Converters.py | 2 +- GearBot/Util/DashConfig.py | 6 +- GearBot/Util/DashUtils.py | 6 +- GearBot/Util/Features.py | 4 +- GearBot/Util/GearbotLogging.py | 8 +- GearBot/Util/HelpGenerator.py | 4 +- GearBot/Util/MessageUtils.py | 3 +- GearBot/Util/Permissioncheckers.py | 12 +- GearBot/Util/RaidHandling/RaidActions.py | 2 +- GearBot/Util/Selfroles.py | 8 +- GearBot/Util/Translator.py | 4 +- GearBot/Util/Utils.py | 4 +- GearBot/Util/server_info.py | 4 +- GearBot/database/DBUtils.py | 4 +- GearBot/database/DatabaseConnector.py | 8 +- GearBot/views/SelfRole.py | 2 +- migration/add_config_table.sql | 6 + 33 files changed, 325 insertions(+), 280 deletions(-) create mode 100644 migration/add_config_table.sql diff --git a/GearBot/Bot/GearBot.py b/GearBot/Bot/GearBot.py index b6eb9ded..0d56c340 100644 --- a/GearBot/Bot/GearBot.py +++ b/GearBot/Bot/GearBot.py @@ -52,6 +52,9 @@ def dispatch(self, event_name, *args, **kwargs): #### event handlers, basically bouncing everything to TheRealGearBot file so we can hotreload our listeners + async def on_connect(self): + await TheRealGearBot.on_connect(self) + async def on_ready(self): await TheRealGearBot.on_ready(self) diff --git a/GearBot/Bot/TheRealGearBot.py b/GearBot/Bot/TheRealGearBot.py index 8169f693..2a8e540b 100644 --- a/GearBot/Bot/TheRealGearBot.py +++ b/GearBot/Bot/TheRealGearBot.py @@ -22,6 +22,7 @@ from Util import Configuration, GearbotLogging, Emoji, Pages, Utils, Translator, InfractionUtils, MessageUtils, \ server_info, DashConfig +from Util.Configuration import ConfigNotLoaded from Util.Permissioncheckers import NotCachedException from Util.Utils import to_pretty_time from database import DatabaseConnector, DBUtils @@ -34,7 +35,7 @@ def prefix_callable(bot, message): if message.guild is None: prefixes.append('!') #use default ! prefix in DMs elif bot.STARTUP_COMPLETE: - prefixes.append(Configuration.get_var(message.guild.id, "GENERAL", "PREFIX")) + prefixes.append(Configuration.legacy_get_var(message.guild.id, "GENERAL", "PREFIX")) return prefixes @@ -126,6 +127,9 @@ async def on_message(bot, message:Message): else: await bot.invoke(ctx) +async def on_connect(bot): + await Configuration.load_bulk([guild.id for guild in bot.guilds]) + async def on_guild_join(bot, guild: Guild): blocked = Configuration.get_persistent_var("server_blocklist", []) @@ -145,7 +149,7 @@ async def on_guild_join(bot, guild: Guild): await guild.leave() else: GearbotLogging.info(f"A new guild came up: {guild.name} ({guild.id}).") - Configuration.load_config(guild.id) + await Configuration.load_config(guild.id) name = await Utils.clean(guild.name) await guild.chunk(cache=True) await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('JOIN')} A new guild came up: {name} ({guild.id}).", embed=server_info.server_info_embed(guild)) @@ -178,6 +182,8 @@ def __init__(self, type, error): async def on_command_error(bot, ctx: commands.Context, error): + if isinstance(error, ConfigNotLoaded): + return if isinstance(error, NotCachedException): if bot.loading_task is not None: if bot.initial_fill_complete: @@ -190,7 +196,7 @@ async def on_command_error(bot, ctx: commands.Context, error): GearbotLogging.error(f"Encountered a permission error while executing {ctx.command}: {error}") await send(ctx, error) elif isinstance(error, commands.CheckFailure): - if ctx.command.qualified_name != "latest" and ctx.guild is not None and Configuration.get_var(ctx.guild.id, "GENERAL", "PERM_DENIED_MESSAGE"): + if ctx.command.qualified_name != "latest" and ctx.guild is not None and await Configuration.get_var(ctx.guild.id, "GENERAL", "PERM_DENIED_MESSAGE"): await MessageUtils.send_to(ctx, 'LOCK', 'permission_denied') elif isinstance(error, commands.CommandOnCooldown): await send(ctx, error) @@ -393,7 +399,7 @@ async def handle_exception(exception_type, bot, exception, event=None, message=N - for t in [ConnectionClosed, ClientOSError, ServerDisconnectedError]: + for t in [ConnectionClosed, ClientOSError, ServerDisconnectedError, ConfigNotLoaded]: if isinstance(exception, t): return #nice embed for info on discord diff --git a/GearBot/Cogs/Admin.py b/GearBot/Cogs/Admin.py index 7ff28f8e..8dd7cc95 100644 --- a/GearBot/Cogs/Admin.py +++ b/GearBot/Cogs/Admin.py @@ -185,7 +185,7 @@ async def reset_cache(self, ctx): async def thread_migration(self, ctx): await MessageUtils.send_to(ctx, "LOADING", "Thread migration initiated", translate=False) for guild in self.bot.guilds: - role_id = Configuration.get_var(guild.id, 'ROLES', 'MUTE_ROLE') + role_id = await Configuration.get_var(guild.id, 'ROLES', 'MUTE_ROLE') if role_id != 0: role = guild.get_role(role_id) if role is not None: diff --git a/GearBot/Cogs/AntiRaid.py b/GearBot/Cogs/AntiRaid.py index e354cf0b..6da3e387 100644 --- a/GearBot/Cogs/AntiRaid.py +++ b/GearBot/Cogs/AntiRaid.py @@ -24,7 +24,7 @@ def __init__(self, bot): @commands.Cog.listener() async def on_member_join(self, member: disnake.Member): - raid_settings = Configuration.get_var(member.guild.id, "RAID_HANDLING") + raid_settings = await Configuration.get_var(member.guild.id, "RAID_HANDLING") if not raid_settings["ENABLED"]: return @@ -175,7 +175,7 @@ async def raid_end(self, ctx): await MessageUtils.send_to(ctx, 'YES', 'raid_terminated') async def terminate_raid(self, guild): - raid_settings = Configuration.get_var(guild, "RAID_HANDLING") + raid_settings = await Configuration.get_var(guild, "RAID_HANDLING") for shield in raid_settings["SHIELDS"]: if guild in self.raid_trackers and shield["id"] in self.raid_trackers[guild]["SHIELDS"]: h = self.raid_trackers[guild]["SHIELDS"][shield["id"]] @@ -183,7 +183,7 @@ async def terminate_raid(self, guild): @raid.command('status') async def raid_status(self, ctx): - raid_settings = Configuration.get_var(ctx.guild.id, "RAID_HANDLING") + raid_settings = await Configuration.get_var(ctx.guild.id, "RAID_HANDLING") if len(raid_settings.get('SHIELDS', [])) == 0: await MessageUtils.send_to(ctx, 'WRENCH', 'raid_shields_not_configured') elif raid_settings['ENABLED']: @@ -193,7 +193,7 @@ async def raid_status(self, ctx): @raid.command('enable') async def raid_enable(self, ctx): - raid_settings = Configuration.get_var(ctx.guild.id, "RAID_HANDLING") + raid_settings = await Configuration.get_var(ctx.guild.id, "RAID_HANDLING") if len(raid_settings.get('SHIELDS', [])) == 0: await MessageUtils.send_to(ctx, 'NO', 'raid_shields_not_configured') else: @@ -202,11 +202,11 @@ async def raid_enable(self, ctx): @raid.command('disable') async def raid_disable(self, ctx): - raid_settings = Configuration.get_var(ctx.guild.id, "RAID_HANDLING") + raid_settings = await Configuration.get_var(ctx.guild.id, "RAID_HANDLING") if len(raid_settings.get('SHIELDS', [])) == 0: await MessageUtils.send_to(ctx, 'NO', 'raid_shields_not_configured') else: - Configuration.set_var(ctx.guild.id, 'RAID_HANDLING', 'ENABLED', False) + await Configuration.set_var(ctx.guild.id, 'RAID_HANDLING', 'ENABLED', False) await MessageUtils.send_to(ctx, 'YES', 'raid_shields_disabled') diff --git a/GearBot/Cogs/AntiSpam.py b/GearBot/Cogs/AntiSpam.py index c26c8ba4..578ed2b6 100644 --- a/GearBot/Cogs/AntiSpam.py +++ b/GearBot/Cogs/AntiSpam.py @@ -100,7 +100,7 @@ def get_bucket(self, guild_id, rule_name, bucket_info): async def on_message(self, message: Message): if message.author.id == self.bot.user.id or message.guild is None: return # Don't track anti-spam for ourselves or DMs - cfg = Configuration.get_var(message.guild.id, "ANTI_SPAM") + cfg = await Configuration.get_var(message.guild.id, "ANTI_SPAM") if not cfg.get("ENABLED", False) or message.id in self.processed: return self.processed.append(message.id) @@ -108,7 +108,7 @@ async def on_message(self, message: Message): async def process_message(self, message: Message): # print(f'{datetime.datetime.now().isoformat()} - Processing message') - if message.webhook_id is not None or self.is_exempt(message.guild.id, message.author): + if message.webhook_id is not None or await self.is_exempt(message.guild.id, message.author): return # Use the discord's message timestamp to hopefully not trigger false positives @@ -131,7 +131,7 @@ async def check_bucket(check, friendly_text, amount, b): b, count))) counters = dict() - buckets = Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) + buckets = await Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) # so if someone does 20 levels of too many mentions for some stupid reason we don't end up running the same regex 20 times for nothing cache = dict() @@ -235,7 +235,9 @@ async def mute_punishment(self, v: Violation, member): duration = v.bucket["PUNISHMENT"]["DURATION"] until = time.time() + duration reason = self.assemble_reason(v) - role = AntiSpam._get_mute_role(v.guild) + role = await AntiSpam._get_mute_role(v.guild) + if role is None: + return i = await Infraction.get_or_none(user_id = member.id, type = "Mute", guild_id = member.guild.id, active=True) if i is None: i = await InfractionUtils.add_infraction(v.guild.id, member.id, self.bot.user.id, 'Mute', reason, @@ -256,7 +258,7 @@ async def mute_punishment(self, v: Violation, member): moderator_id=v.guild.me.id, duration=Utils.to_pretty_time(duration, v.guild.id), reason=reason, inf=i.id) - if Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_MUTE"): + if await Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_MUTE"): await Utils.send_infraction(self.bot, member, v.guild, 'MUTE', 'mute', reason, duration=Utils.to_pretty_time(duration, v.guild.id)) else: i.end += duration @@ -282,7 +284,7 @@ async def kick_punishment(self, v: Violation, member): active=False) await self.bot.redis_pool.psetex(f"forced_exits:{v.guild.id}-{member.id}", 8000, "1") try: - if Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_KICK"): + if await Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_KICK"): asyncio.create_task(Utils.send_infraction(self.bot, member, v.guild, 'BOOT', 'kick', "Spam")) await v.guild.kick(member, reason=reason) except Forbidden: @@ -302,7 +304,7 @@ async def temp_ban_punishment(self, v: Violation, member): await v.guild.ban(member, reason=reason, delete_message_days=0) i = await InfractionUtils.add_infraction(v.guild.id, member.id, self.bot.user.id, 'Tempban', reason, end=until) - if Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_TEMPBAN"): + if await Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_TEMPBAN"): dur = Utils.to_pretty_time(duration, None) asyncio.create_task(Utils.send_infraction(self.bot, member, v.guild, 'BAN', 'tempban', "Spam", duration=dur)) GearbotLogging.log_key(v.guild.id, 'tempban_log', user=Utils.clean_user(member), @@ -319,7 +321,7 @@ async def ban_punishment(self, v: Violation, member): GearbotLogging.log_key(v.guild.id, 'ban_log', user=Utils.clean_user(member), user_id=member.id, moderator=Utils.clean_user(v.guild.me), moderator_id=v.guild.me.id, reason=reason, inf=i.id) - if Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_BAN"): + if await Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_BAN"): asyncio.create_task(Utils.send_infraction(self.bot, member, v.guild, 'BAN', 'ban', "Spam")) @@ -335,10 +337,10 @@ async def censor_detector(self): return # make sure anti-spam is enabled - cfg = Configuration.get_var(message.guild.id, "ANTI_SPAM") + cfg = await Configuration.get_var(message.guild.id, "ANTI_SPAM") if not cfg.get("ENABLED", False) or message.id in self.censor_processed: continue - buckets = Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) + buckets = await Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) count = 0 for b in buckets: t = b["TYPE"] @@ -372,10 +374,10 @@ async def voice_spam_detector(self): return # make sure anti-spam is enabled - cfg = Configuration.get_var(member.guild.id, "ANTI_SPAM") - if after.channel is None or before.channel == after.channel or member is None or not cfg.get("ENABLED", False) or self.is_exempt(member.guild.id, member): + cfg = await Configuration.get_var(member.guild.id, "ANTI_SPAM") + if after.channel is None or before.channel == after.channel or member is None or not cfg.get("ENABLED", False) or await self.is_exempt(member.guild.id, member): continue - buckets = Configuration.get_var(member.guild.id, "ANTI_SPAM", "BUCKETS", []) + buckets = await Configuration.get_var(member.guild.id, "ANTI_SPAM", "BUCKETS", []) count = 0 for b in buckets: t = b["TYPE"] @@ -405,15 +407,15 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent): member = await Utils.get_member(self.bot, self.bot.get_guild(data.guild_id), message.author) if member is None: return # user no longer present, probably already actioned - if self.is_exempt(data.guild_id, member): + if await self.is_exempt(data.guild_id, member): return # don't action except users - if data.message_id in self.bot.deleted_messages and not Configuration.get_var("GENERAL", "BOT_DELETED_STILL_GHOSTS"): + if data.message_id in self.bot.deleted_messages and not await Configuration.get_var(data.guild_id, "GENERAL", "BOT_DELETED_STILL_GHOSTS"): return - ghost_message_threshold = Configuration.get_var(data.guild_id, "GENERAL", "GHOST_MESSAGE_THRESHOLD") - ghost_ping_threshold = Configuration.get_var(data.guild_id, "GENERAL", "GHOST_PING_THRESHOLD") - buckets = Configuration.get_var(data.guild_id, "ANTI_SPAM", "BUCKETS", []) + ghost_message_threshold = await Configuration.get_var(data.guild_id, "GENERAL", "GHOST_MESSAGE_THRESHOLD") + ghost_ping_threshold = await Configuration.get_var(data.guild_id, "GENERAL", "GHOST_PING_THRESHOLD") + buckets = await Configuration.get_var(data.guild_id, "ANTI_SPAM", "BUCKETS", []) mentions = len(MENTION_MATCHER.findall(message.content)) msg_time = int(snowflake_time(message.messageid).timestamp()) @@ -456,9 +458,9 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent): async def handle_failed_ping(self, message: disnake.Message, amount): - if self.is_exempt(message.guild.id, message.author) or message.author.bot or message.webhook_id is not None: + if await self.is_exempt(message.guild.id, message.author) or message.author.bot or message.webhook_id is not None: return # don't action except users - buckets = Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) + buckets = await Configuration.get_var(message.guild.id, "ANTI_SPAM", "BUCKETS", []) msg_time = int(snowflake_time(message.id).timestamp()) for b in buckets: t = b["TYPE"] @@ -485,18 +487,18 @@ def assemble_reason(v): friendly=v.friendly) @staticmethod - def is_exempt(guild_id, member: Member): + async def is_exempt(guild_id, member: Member): if not hasattr(member, "roles"): return False - config = Configuration.get_var(guild_id, "ANTI_SPAM") + config = await Configuration.get_var(guild_id, "ANTI_SPAM") for role in member.roles: if role.id in config["EXEMPT_ROLES"]: return True return member.id in config["EXEMPT_USERS"] or Permissioncheckers.is_mod(member) @staticmethod - def _get_mute_role(guild): - role_id = Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") + async def _get_mute_role(guild): + role_id = await Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") if role_id == 0: return None role = guild.get_role(role_id) diff --git a/GearBot/Cogs/Basic.py b/GearBot/Cogs/Basic.py index 3a058c00..cd9bc34c 100644 --- a/GearBot/Cogs/Basic.py +++ b/GearBot/Cogs/Basic.py @@ -74,7 +74,7 @@ async def about(self, ctx): click_here = Translator.translate('click_here', ctx) embed.add_field(name=Translator.translate('support_server', ctx), - value=f"[{click_here}](https://disnake.gg/vddW3D9)") + value=f"[{click_here}](https://discord.gg/vddW3D9)") embed.add_field(name=Translator.translate('website', ctx), value=f"[{click_here}](https://gearbot.rocks)") embed.add_field(name=f"Github", value=f"[{click_here}](https://github.com/gearbot/GearBot)") embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.display_avatar.url) @@ -115,7 +115,7 @@ async def quote(self, ctx: commands.Context, *, message: Message): if message.content is None or message.content == "": if attachment is not None: url = Utils.assemble_attachment(message.channel.id, attachment.id, attachment.name) - if attachment.isImage: + if attachment.isimage: embed.set_image(url=url) else: embed.add_field(name=Translator.translate("attachment_link", ctx), @@ -128,7 +128,7 @@ async def quote(self, ctx: commands.Context, *, message: Message): value=f"[Jump to message]({message.jump_url})") if attachment is not None: url = Utils.assemble_attachment(message.channel.id, attachment.id, attachment.name) - if attachment.isImage: + if attachment.isimage: embed.set_image(url=url) else: embed.add_field(name=Translator.translate("attachment_link", ctx), @@ -175,7 +175,7 @@ async def self_role(self, ctx: commands.Context, *, role: str = None): except BadArgument as ex: await ctx.send(Translator.translate("role_not_found", ctx)) else: - roles = Configuration.get_var(ctx.guild.id, "ROLES", "SELF_ROLES") + roles = await Configuration.get_var(ctx.guild.id, "ROLES", "SELF_ROLES") if role.id in roles: try: if role in ctx.author.roles: @@ -214,7 +214,7 @@ async def uid(self, ctx, *, text: str): @commands.Cog.listener() async def on_guild_role_delete(self, role: disnake.Role): - roles = Configuration.get_var(role.guild.id, "ROLES", "SELF_ROLES") + roles = await Configuration.get_var(role.guild.id, "ROLES", "SELF_ROLES") if role.id in roles: roles.remove(role.id) Configuration.save(role.guild.id) diff --git a/GearBot/Cogs/Censor.py b/GearBot/Cogs/Censor.py index 58b5f0de..4d2d3073 100644 --- a/GearBot/Cogs/Censor.py +++ b/GearBot/Cogs/Censor.py @@ -24,7 +24,7 @@ def __init__(self, bot): @commands.Cog.listener() async def on_message(self, message: disnake.Message): - if message.guild is None or message.webhook_id is not None or message.channel is None or isinstance(message.channel, DMChannel) or not Configuration.get_var(message.channel.guild.id, "CENSORING", "ENABLED") or self.bot.user.id == message.author.id: + if message.guild is None or message.webhook_id is not None or message.channel is None or isinstance(message.channel, DMChannel) or not await Configuration.get_var(message.channel.guild.id, "CENSORING", "ENABLED") or self.bot.user.id == message.author.id: return member = await Utils.get_member(self.bot, message.guild, message.author.id, fetch_if_missing=True) if member is None: @@ -40,7 +40,7 @@ async def on_raw_message_edit(self, event: disnake.RawMessageUpdateEvent): channel = self.bot.get_channel(int(event.data["channel_id"])) m = await MessageUtils.get_message_data(self.bot, event.message_id) reply = None - if channel is None or isinstance(channel, DMChannel) or not Configuration.get_var(channel.guild.id, "CENSORING", "ENABLED") or "content" not in event.data: + if channel is None or isinstance(channel, DMChannel) or not await Configuration.get_var(channel.guild.id, "CENSORING", "ENABLED") or "content" not in event.data: return author_id=None if m is not None: @@ -63,15 +63,15 @@ async def on_raw_message_edit(self, event: disnake.RawMessageUpdateEvent): await self.check_message(member, event.data["content"], channel, event.message_id, True, reply, None) async def check_message(self, member, content, channel, message_id, edit, reply, attachments): - if Permissioncheckers.get_user_lvl(member.guild, member) >= 2: + if await Permissioncheckers.get_user_lvl(member.guild, member) >= 2: return - censorlist = Configuration.get_var(member.guild.id, "CENSORING", "TOKEN_CENSORLIST") - word_censorlist = Configuration.get_var(member.guild.id, "CENSORING", "WORD_CENSORLIST") - guilds = Configuration.get_var(member.guild.id, "CENSORING", "ALLOWED_INVITE_LIST") - domain_list = Configuration.get_var(member.guild.id, "CENSORING", "DOMAIN_LIST") - domains_allowed = Configuration.get_var(member.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") - full_message_list = Configuration.get_var(member.guild.id, "CENSORING", "FULL_MESSAGE_LIST") - censor_emoji_message = Configuration.get_var(member.guild.id, "CENSORING", "CENSOR_EMOJI_ONLY_MESSAGES") + censorlist = await Configuration.get_var(member.guild.id, "CENSORING", "TOKEN_CENSORLIST") + word_censorlist = await Configuration.get_var(member.guild.id, "CENSORING", "WORD_CENSORLIST") + guilds = await Configuration.get_var(member.guild.id, "CENSORING", "ALLOWED_INVITE_LIST") + domain_list = await Configuration.get_var(member.guild.id, "CENSORING", "DOMAIN_LIST") + domains_allowed = await Configuration.get_var(member.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") + full_message_list = await Configuration.get_var(member.guild.id, "CENSORING", "FULL_MESSAGE_LIST") + censor_emoji_message = await Configuration.get_var(member.guild.id, "CENSORING", "CENSOR_EMOJI_ONLY_MESSAGES") content = content.replace('\\', '') if Configuration.get_var(member.guild.id, "CENSORING", "IGNORE_IDS"): @@ -142,7 +142,7 @@ async def check_message(self, member, content, channel, message_id, edit, reply, async def censor_message(self, message_id, content, channel, member, bad, key="", edit=False, reply="", attachments=""): - if Configuration.get_var(member.guild.id, "CENSORING", "ALLOW_TRUSTED_CENSOR_BYPASS") and Permissioncheckers.is_trusted(member): + if await Configuration.get_var(member.guild.id, "CENSORING", "ALLOW_TRUSTED_CENSOR_BYPASS") and Permissioncheckers.is_trusted(member): return e = '_edit' if edit else '' clean_message = await Utils.clean(content, channel.guild, markdown=False) @@ -179,7 +179,7 @@ async def censor_message(self, message_id, content, channel, member, bad, key="" async def censor_invite(self, member, message_id, channel, code, server_name, content, edit, reply, attachments): # Allow for users with a trusted role, or trusted users, to post invite links - if Configuration.get_var(member.guild.id, "CENSORING", "ALLOW_TRUSTED_BYPASS") and Permissioncheckers.is_trusted(member): + if await Configuration.get_var(member.guild.id, "CENSORING", "ALLOW_TRUSTED_BYPASS") and Permissioncheckers.is_trusted(member): return e = '_edit' if edit else '' diff --git a/GearBot/Cogs/CustCommands.py b/GearBot/Cogs/CustCommands.py index 751141d3..70d07595 100644 --- a/GearBot/Cogs/CustCommands.py +++ b/GearBot/Cogs/CustCommands.py @@ -174,11 +174,11 @@ async def on_message(self, message: disnake.Message): if not (permissions.read_messages and permissions.send_messages and permissions.embed_links): return - role_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLES") - role_required = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") - channel_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS") - channels_ignored = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") - mod_bypass = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "MOD_BYPASS") + role_list = await Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLES") + role_required = await Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") + channel_list = await Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS") + channels_ignored = await Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") + mod_bypass = await Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "MOD_BYPASS") is_mod = message.author is not None and Permissioncheckers.is_mod(message.author) @@ -195,7 +195,7 @@ async def on_message(self, message: disnake.Message): if has_role is not role_required and not (is_mod and mod_bypass): return - prefix = Configuration.get_var(message.guild.id, "GENERAL", "PREFIX") + prefix = await Configuration.get_var(message.guild.id, "GENERAL", "PREFIX") if message.content.startswith(prefix, 0) and message.guild.id in self.commands: for trigger in self.commands[message.guild.id]: if message.content.lower() == prefix + trigger or ( diff --git a/GearBot/Cogs/DashLink.py b/GearBot/Cogs/DashLink.py index 201ec022..221b91a6 100644 --- a/GearBot/Cogs/DashLink.py +++ b/GearBot/Cogs/DashLink.py @@ -248,11 +248,11 @@ async def send_guild_info_update_to_all(self, guild): async def send_guild_info(self, member): await self.send_to_dash("guild_update", user_id=member.id, guild_id=member.guild.id, - info=DashUtils.assemble_guild_info(self.bot, member)) + info=await DashUtils.assemble_guild_info(self.bot, member)) @needs_perm(DASH_PERMS.VIEW_CONFIG) async def get_guild_settings(self, message): - section = Configuration.get_var(int(message["guild_id"]), message["section"]) + section = await Configuration.get_var(int(message["guild_id"]), message["section"]) section = {k: [str(rid) if isinstance(rid, int) else rid for rid in v] if isinstance(v, list) else str( v) if isinstance(v, int) and not isinstance(v, bool) else v for k, v in section.items()} return section @@ -261,7 +261,7 @@ async def get_guild_settings(self, message): async def save_guild_settings(self, message): guild_id, user_id = get_info(message) guild = self.bot.get_guild(guild_id) - return DashConfig.update_config_section( + return await DashConfig.update_config_section( guild, message["section"], message["modified_values"], @@ -272,7 +272,7 @@ async def save_guild_settings(self, message): async def replace_guild_settings(self, message): guild_id, user_id = get_info(message) guild = self.bot.get_guild(guild_id) - return DashConfig.update_config_section( + return await DashConfig.update_config_section( guild, message["section"], message["modified_values"], diff --git a/GearBot/Cogs/Infractions.py b/GearBot/Cogs/Infractions.py index 81f60b2e..cda65cb5 100644 --- a/GearBot/Cogs/Infractions.py +++ b/GearBot/Cogs/Infractions.py @@ -29,7 +29,7 @@ async def _warn(self, ctx, target, *, reason, message=True, dm_action=True): aname = Utils.clean_user(ctx.author) GearbotLogging.log_key(ctx.guild.id, 'warning_added_modlog', user=name, moderator=aname, reason=reason, user_id=target.id, moderator_id=ctx.author.id, inf=i.id) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_WARN") and dm_action: + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_WARN") and dm_action: await Utils.send_infraction(self.bot, target, ctx.guild, 'WARNING', 'warn', reason) @commands.guild_only() diff --git a/GearBot/Cogs/Interactions.py b/GearBot/Cogs/Interactions.py index e596eeed..3f287bd2 100644 --- a/GearBot/Cogs/Interactions.py +++ b/GearBot/Cogs/Interactions.py @@ -24,7 +24,7 @@ async def on_interaction(self, interaction): rid = parts[2] if rid.isnumeric(): rid = int(rid) - roles = Configuration.get_var(interaction.guild_id, "ROLES", "SELF_ROLES") + roles = await Configuration.get_var(interaction.guild_id, "ROLES", "SELF_ROLES") if rid in roles: role = guild.get_role(rid) if role is None: @@ -116,7 +116,7 @@ async def on_interaction(self, interaction): elif t == 'censor_list': cog = self.bot.get_cog('Moderation') if cog is not None: - censor_list = Configuration.get_var(interaction.guild.id, "CENSORING", "TOKEN_CENSORLIST") + censor_list = await Configuration.get_var(interaction.guild.id, "CENSORING", "TOKEN_CENSORLIST") pages = Pages.paginate("\n".join(censor_list)) page, view, page_num = SimplePager.get_parts(pages, int(parts[1]), interaction.guild.id, 'censor_list') @@ -126,7 +126,7 @@ async def on_interaction(self, interaction): elif t == 'word_censor_list': cog = self.bot.get_cog('Moderation') if cog is not None: - censor_list = Configuration.get_var(guild.id, "CENSORING", "WORD_CENSORLIST") + censor_list = await Configuration.get_var(guild.id, "CENSORING", "WORD_CENSORLIST") pages = Pages.paginate("\n".join(censor_list)) page, view, page_num = SimplePager.get_parts(pages, int(parts[1]), guild.id, 'word_censor_list') @@ -136,7 +136,7 @@ async def on_interaction(self, interaction): elif t == 'full_censor_list': cog = self.bot.get_cog('Moderation') if cog is not None: - censor_list = Configuration.get_var(guild.id, "CENSORING", "FULL_MESSAGE_LIST") + censor_list = await Configuration.get_var(guild.id, "CENSORING", "FULL_MESSAGE_LIST") pages = Pages.paginate("\n".join(censor_list)) page, view, page_num = SimplePager.get_parts(pages, int(parts[1]), guild.id, 'full_censor_list') @@ -146,7 +146,7 @@ async def on_interaction(self, interaction): elif t == 'flag_list': cog = self.bot.get_cog('Moderation') if cog is not None: - censor_list = Configuration.get_var(guild.id, "FLAGGING", "TOKEN_LIST") + censor_list = await Configuration.get_var(guild.id, "FLAGGING", "TOKEN_LIST") pages = Pages.paginate("\n".join(censor_list)) page, view, page_num = SimplePager.get_parts(pages, int(parts[1]), guild.id, 'flag_list') await interaction.response.edit_message( @@ -155,7 +155,7 @@ async def on_interaction(self, interaction): elif t == 'word_flag_list': cog = self.bot.get_cog('Moderation') if cog is not None: - censor_list = Configuration.get_var(guild.id, "FLAGGING", "WORD_LIST") + censor_list = await Configuration.get_var(guild.id, "FLAGGING", "WORD_LIST") pages = Pages.paginate("\n".join(censor_list)) page, view, page_num = SimplePager.get_parts(pages, int(parts[1]), guild.id, 'word_flag_list') await interaction.response.edit_message( diff --git a/GearBot/Cogs/ModLog.py b/GearBot/Cogs/ModLog.py index c0ddf5da..88b9907f 100644 --- a/GearBot/Cogs/ModLog.py +++ b/GearBot/Cogs/ModLog.py @@ -68,7 +68,7 @@ async def buildCache(self, guild: disnake.Guild, limit=None, startup=False): async def on_message(self, message: disnake.Message): if not hasattr(message.channel, "guild") or message.channel.guild is None: return - if Configuration.get_var(message.guild.id, "MESSAGE_LOGS", "ENABLED") and ( + if await Configuration.get_var(message.guild.id, "MESSAGE_LOGS", "ENABLED") and ( message.content != "" or len(message.attachments) > 0) and message.author.id != self.bot.user.id: await MessageUtils.insert_message(self.bot, message) else: @@ -98,7 +98,7 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent): return c = self.bot.get_channel(data.channel_id) if c is None or isinstance(c, DMChannel) or c.guild is None or ( - not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or data.channel_id in Configuration.get_var( + not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or data.channel_id in await Configuration.get_var( c.guild.id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"): @@ -111,14 +111,14 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent): guild = self.bot.get_guild(message.server) user: disnake.User = await Utils.get_user(message.author) hasUser = user is not None - if not hasUser or user.id in Configuration.get_var(guild.id, "MESSAGE_LOGS", + if not hasUser or user.id in await Configuration.get_var(guild.id, "MESSAGE_LOGS", "IGNORED_USERS") or user.id == guild.me.id: return channel = self.bot.get_channel(message.channel) name = Utils.clean_user(user) if hasUser else str(message.author) _time = Utils.to_pretty_time((datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc) - snowflake_time(data.message_id)).total_seconds(), guild.id) - with_id = Configuration.get_var(guild.id, "MESSAGE_LOGS", "MESSAGE_ID") + with_id = await Configuration.get_var(guild.id, "MESSAGE_LOGS", "MESSAGE_ID") reply_str = "" if message.reply_to is not None: reply_str = f"\n**{Translator.translate('in_reply_to', guild.id)}: **<{assemble_jumplink(guild.id, channel.id, message.reply_to)}>" @@ -137,7 +137,7 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent): type_string = Translator.translate('system_message_unknown', guild) type_string = Translator.translate('system_message', guild, type=type_string) - if Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"): + if await Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"): embed_content = type_string or message.content if len(embed_content) == 0: @@ -185,7 +185,7 @@ async def on_raw_message_edit(self, event: RawMessageUpdateEvent): return c = self.bot.get_channel(cid) if c is None or isinstance(c, DMChannel) or c.guild is None or ( - not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or cid in Configuration.get_var(c.guild.id, + not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or cid in await Configuration.get_var(c.guild.id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"): return @@ -228,19 +228,19 @@ async def on_raw_message_edit(self, event: RawMessageUpdateEvent): after = event.data["content"] if after is None or after == "": after = f"<{Translator.translate('no_content', channel.guild.id)}>" - if hasUser and user.id not in Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", + if hasUser and user.id not in await Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "IGNORED_USERS") and user.id != channel.guild.me.id: _time = Utils.to_pretty_time((datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc) - snowflake_time(message.messageid)).total_seconds(), channel.guild.id) - with_id = Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "MESSAGE_ID") + with_id = await Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "MESSAGE_ID") reply_str = "" if message.reply_to is not None: reply_str = f"\n**{Translator.translate('in_reply_to', c.guild.id)}: **<{assemble_jumplink(c.guild.id, channel.id, message.reply_to)}>" GearbotLogging.log_key(channel.guild.id, 'edit_logging_with_id' if with_id else 'edit_logging', user=Utils.clean_user(user), user_id=user.id, channel=channel.mention, message_id=message.messageid, time=_time.strip(), reply=reply_str) - if Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"): + if await Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"): embed = disnake.Embed() embed.set_author(name=user if hasUser else message.author, icon_url=user.display_avatar.url if hasUser else EmptyEmbed) @@ -263,7 +263,7 @@ async def on_member_join(self, member: disnake.Member): if Features.is_logged(member.guild.id, "TRAVEL_LOGS"): dif = (datetime.datetime.utcfromtimestamp(time.time()).replace( tzinfo=datetime.timezone.utc) - member.created_at) - new_user_threshold = Configuration.get_var(member.guild.id, "GENERAL", "NEW_USER_THRESHOLD") + new_user_threshold = await Configuration.get_var(member.guild.id, "GENERAL", "NEW_USER_THRESHOLD") minutes, seconds = divmod(dif.days * 86400 + dif.seconds, 60) hours, minutes = divmod(minutes, 60) age = (Translator.translate('days', member.guild.id, @@ -482,7 +482,7 @@ async def on_voice_state_update(self, member, before, after): @commands.Cog.listener() async def on_raw_bulk_message_delete(self, event: disnake.RawBulkMessageDeleteEvent): if Features.is_logged(event.guild_id, "MESSAGE_LOGS"): - if event.channel_id in Configuration.get_var(event.guild_id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"): + if event.channel_id in await Configuration.get_var(event.guild_id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"): return if event.channel_id in self.bot.being_cleaned: for mid in event.message_ids: @@ -531,7 +531,7 @@ async def on_guild_channel_delete(self, channel): @commands.Cog.listener() async def on_guild_channel_update(self, before, after): - if not Features.is_logged(before.guild.id, "CHANNEL_CHANGES") or before.id in Configuration.get_var( + if not Features.is_logged(before.guild.id, "CHANNEL_CHANGES") or before.id in await Configuration.get_var( before.guild.id, "MESSAGE_LOGS", "IGNORED_CHANNELS_CHANGES"): return timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) await self.handle_simple_changes(before, after, "channel_update_simple", diff --git a/GearBot/Cogs/Moderation.py b/GearBot/Cogs/Moderation.py index 51ecce7b..cd3336ed 100644 --- a/GearBot/Cogs/Moderation.py +++ b/GearBot/Cogs/Moderation.py @@ -171,8 +171,8 @@ async def role_handler(self, ctx, user, role, action): return if Actions.can_act(f"role_{action}", ctx, user): - role_list = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") - mode = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") + role_list = await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") + mode = await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") mode_name = "allow" if mode else "block" if (drole.id in role_list) is mode: if drole < ctx.me.top_role: @@ -215,7 +215,7 @@ async def kick(self, ctx, user: ServerMember, *, reason: Reason = ""): async def _kick(self, ctx, user, reason, message, dm_action=True): await self.bot.redis_pool.psetex(f"forced_exits:{ctx.guild.id}-{user.id}", 8000, "1") - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_KICK") and dm_action: + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_KICK") and dm_action: await Utils.send_infraction(self.bot, user, ctx.guild, 'BOOT', 'kick', reason) await ctx.guild.kick(user, @@ -242,7 +242,7 @@ async def yes(interaction: disnake.Interaction): await interaction.response.edit_message(content=MessageUtils.assemble(ctx, "REFRESH", "processing"), view=None) failures = await Actions.mass_action(ctx, "kick", targets, self._kick, reason=reason, message=False, - dm_action=Configuration.get_var(ctx.guild.id, "INFRACTIONS", + dm_action=Configuration.legacy_get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_KICK")) await interaction.edit_original_message( content=MessageUtils.assemble(ctx, "YES", "mkick_confirmation", count=len(targets) - len(failures))) @@ -402,7 +402,7 @@ async def tempban(self, ctx: commands.Context, user: DiscordUser, duration: Dura if allowed: duration_seconds = duration.to_seconds(ctx) if duration_seconds > 0: - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_TEMPBAN"): + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_TEMPBAN"): dur = f'{duration.length}{duration.unit}' await Utils.send_infraction(self.bot, user, ctx.guild, 'BAN', 'tempban', reason, duration=dur) await self.bot.redis_pool.psetex(f"forced_exits:{ctx.guild.id}-{user.id}", 8000, "1") @@ -428,7 +428,7 @@ async def tempban(self, ctx: commands.Context, user: DiscordUser, duration: Dura async def _ban(self, ctx, user, reason, confirm, days=0, dm_action=True): await self.bot.redis_pool.psetex(f"forced_exits:{ctx.guild.id}-{user.id}", 8000, "1") - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_BAN") and dm_action: + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_BAN") and dm_action: await Utils.send_infraction(self.bot, user, ctx.guild, 'BAN', 'ban', reason) await ctx.guild.ban(user, reason=Utils.trim_message( @@ -479,7 +479,7 @@ async def yes(interaction: disnake.Interaction): view=None) failures = await Actions.mass_action(ctx, "ban", targets, self._ban, reason=reason, confirm=False, require_on_server=False, - dm_action=Configuration.get_var(ctx.guild.id, "INFRACTIONS", + dm_action=Configuration.legacy_get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_BAN")) await interaction.edit_original_message( content=MessageUtils.assemble(ctx, "YES", "mban_confirmation", count=len(targets) - len(failures))) @@ -576,7 +576,7 @@ async def yes(interaction: disnake.Interaction): view=None) failures = await Actions.mass_action(ctx, "ban", targets, self._ban, reason=reason, confirm=False, require_on_server=False, - dm_action=Configuration.get_var(ctx.guild.id, "INFRACTIONS", + dm_action=Configuration.legacy_get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_BAN")) await interaction.edit_original_message( content=MessageUtils.assemble(ctx, "YES", "mban_confirmation", count=len(targets) - len(failures))) @@ -823,7 +823,7 @@ async def mmute(self, ctx, targets: Greedy[PotentialID], duration: Duration, *, duration.unit = parts[0] reason = " ".join(parts[1:]) reason = Utils.enrich_reason(ctx, reason) - roleid = Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") + roleid = await Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") if roleid == 0: await ctx.send( f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mmute_not_configured', ctx.guild.id)}") @@ -839,7 +839,7 @@ async def yes(interaction: disnake.Interaction): await interaction.response.edit_message(content=MessageUtils.assemble(ctx, "REFRESH", "processing"), view=None) failures = await Actions.mass_action(ctx, "mute", targets, self._mmute, reason=reason, - dm_action=len(targets) < 6 and Configuration.get_var( + dm_action=len(targets) < 6 and Configuration.legacy_get_var( ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"), role=role, duration=duration) @@ -923,7 +923,7 @@ async def mute(self, ctx: commands.Context, target: ServerMember, duration: Dura duration.unit = parts[0] reason = " ".join(parts[1:]) reason = Utils.enrich_reason(ctx, reason) - roleid = Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") + roleid = await Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") if roleid == 0: await ctx.send( f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_not_configured', ctx.guild.id, user=target.mention)}") @@ -974,7 +974,7 @@ async def mute(self, ctx: commands.Context, target: ServerMember, duration: Dura moderator_id=ctx.author.id, duration=f'{duration.length} {duration.unit}', reason=reason, inf=i.id) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): dur = f'{duration.length}{duration.unit}' await Utils.send_infraction(self.bot, target, ctx.guild, 'MUTE', 'mute', reason, duration=dur) @@ -995,7 +995,7 @@ async def extend(interaction: Interaction): end=datetime.datetime.utcfromtimestamp( infraction.end).strftime('%Y-%m-%d %H:%M:%S')) name = Utils.clean_user(target) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): try: dur = f'{duration.length}{duration.unit}' await target.send( @@ -1018,7 +1018,7 @@ async def until(interaction: Interaction): end=datetime.datetime.utcfromtimestamp( infraction.end).strftime('%Y-%m-%d %H:%M:%S')) name = Utils.clean_user(target) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): try: dur = f'{duration.length}{duration.unit}' await target.send( @@ -1039,7 +1039,7 @@ async def overwrite(interaction: Interaction): duration=f'{duration.length} {duration.unit}', reason=reason, inf_id=infraction.id, end=infraction.end) name = Utils.clean_user(target) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_MUTE"): try: dur = f'{duration.length}{duration.unit}' await target.send( @@ -1075,7 +1075,7 @@ async def yes(interaction: disnake.Interaction): view=None) failures = await Actions.mass_action(ctx, "unmute", targets, self._unmute, reason=reason, require_on_server=True, - dm_action=Configuration.get_var(ctx.guild.id, "INFRACTIONS", + dm_action=Configuration.legacy_get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_UNMUTE")) await interaction.edit_original_message( content=MessageUtils.assemble(ctx, "YES", "munmute_confirmation", count=len(targets) - len(failures))) @@ -1118,9 +1118,9 @@ async def unmute(self, ctx: commands.Context, target: ServerMember, *, reason: R async def _unmute(self, ctx, target, *, reason, confirm=False, dm_action=None): if dm_action is None: - dm_action = Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_UNMUTE") + dm_action = await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_UNMUTE") reason = Utils.enrich_reason(ctx, reason) - roleid = Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") + roleid = await Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE") if roleid == 0: if confirm: await MessageUtils.send_to(ctx, 'NO', 'unmute_fail_disabled') @@ -1161,7 +1161,7 @@ async def _unmute(self, ctx, target, *, reason, confirm=False, dm_action=None): raise ActionFailed(Translator.translate("unmute_higher_role", ctx)) i = await InfractionUtils.add_infraction(ctx.guild.id, target.id, ctx.author.id, "Unmute", reason) name = Utils.clean_user(target) - if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_UNMUTE") and dm_action: + if await Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_UNMUTE") and dm_action: await Utils.send_infraction(self.bot, target, ctx.guild, 'INNOCENT', 'unmute', reason) await Infraction.filter(user_id=target.id, type="Mute", guild_id=ctx.guild.id).update(active=False) await target.remove_roles(role, reason=f"Unmuted by {ctx.author.name}, {reason}") @@ -1215,7 +1215,7 @@ async def channel(self, ctx, channel: disnake.TextChannel = None, amount=100): if not permissions.read_messages: await MessageUtils.send_to(ctx, 'NO', 'archive_leak_denied') return - if Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", "ENABLED"): + if await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", "ENABLED"): await MessageUtils.send_to(ctx, 'SEARCH', 'searching_archives') messages = await LoggedMessage.filter(server=ctx.guild.id, channel=channel.id).order_by("-messageid").limit( amount).prefetch_related("attachments") @@ -1230,7 +1230,7 @@ async def user(self, ctx, user: DiscordUser, amount=100): if amount > 5000: await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('archive_too_much', ctx)}") return - if Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", "ENABLED"): + if await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", "ENABLED"): await MessageUtils.send_to(ctx, 'SEARCH', 'searching_archives') messages = await LoggedMessage.filter(server=ctx.guild.id, author=user).order_by("-messageid").limit( amount).prefetch_related("attachments") @@ -1418,7 +1418,7 @@ async def on_guild_channel_create(self, channel: disnake.abc.GuildChannel): # sleep a little, sometimes discord sends the event too soon await asyncio.sleep(5) guild: disnake.Guild = channel.guild - roleid = Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") + roleid = await Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") if roleid != 0: role = guild.get_role(roleid) if role is not None and channel.permissions_for(guild.me).manage_channels: @@ -1443,7 +1443,7 @@ async def on_member_join(self, member: disnake.Member): i = await Infraction.get_or_none(type="Mute", active=True, end__gt=now, guild_id=member.guild.id, user_id=member.id) if i is not None: - roleid = Configuration.get_var(member.guild.id, "ROLES", "MUTE_ROLE") + roleid = await Configuration.get_var(member.guild.id, "ROLES", "MUTE_ROLE") if roleid != 0: role = member.guild.get_role(roleid) if role is not None: @@ -1499,7 +1499,7 @@ async def _lift_mute(self, infraction: Infraction): f"Got an expired mute for {infraction.guild_id} but i'm no longer in that server, marking mute as ended") return await self.end_infraction(infraction) - role = Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") + role = await Configuration.get_var(guild.id, "ROLES", "MUTE_ROLE") member = await Utils.get_member(self.bot, guild, infraction.user_id, fetch_if_missing=True) role = guild.get_role(role) if role is None or member is None: @@ -1611,10 +1611,10 @@ async def check_for_flagged_words(self, content, guild_id, channel_id, message_i if content is None: return content = content.lower() - token_list = Configuration.get_var(guild_id, "FLAGGING", "TOKEN_LIST") - word_list = Configuration.get_var(guild_id, "FLAGGING", "WORD_LIST") + token_list = await Configuration.get_var(guild_id, "FLAGGING", "TOKEN_LIST") + word_list = await Configuration.get_var(guild_id, "FLAGGING", "WORD_LIST") - if Configuration.get_var(guild_id, "FLAGGING", "IGNORE_IDS"): + if await Configuration.get_var(guild_id, "FLAGGING", "IGNORE_IDS"): content = re.sub(r'(<(?:@|#|@&|@!)[0-9]{15,20}>)', '', content) content = re.sub(r'', '', content) content = re.sub(r"(https://(?:canary|ptb)?\.?discord(?:app)?.com/channels/\d{15,20}/\d{15,20}/\d{15,20})", @@ -1641,7 +1641,7 @@ async def check_for_flagged_words(self, content, guild_id, channel_id, message_i return async def flag_message(self, content, flagged, guild_id, channel_id, message_id, author=None, type=""): - if Configuration.get_var(guild_id, "FLAGGING", "TRUSTED_BYPASS") and Permissioncheckers.is_trusted(author): + if await Configuration.get_var(guild_id, "FLAGGING", "TRUSTED_BYPASS") and Permissioncheckers.is_trusted(author): return if author is None: message = await MessageUtils.get_message_data(self.bot, message_id) @@ -1653,7 +1653,7 @@ async def flag_message(self, content, flagged, guild_id, channel_id, message_id, pass if message is not None: author = await Utils.get_member(self.bot, self.bot.get_guild(guild_id), message.author) - if author is None or author.id == self.bot.user.id or Permissioncheckers.get_user_lvl(author.guild, + if author is None or author.id == self.bot.user.id or await Permissioncheckers.get_user_lvl(author.guild, author) >= 2: return diff --git a/GearBot/Cogs/ServerAdmin.py b/GearBot/Cogs/ServerAdmin.py index a400b208..537eb68a 100644 --- a/GearBot/Cogs/ServerAdmin.py +++ b/GearBot/Cogs/ServerAdmin.py @@ -29,7 +29,7 @@ def __init__(self, sid): async def add_item(ctx, item, item_type, list_name="roles", config_section="PERMISSIONS"): target = f"{item_type}_{list_name}".upper() - roles = Configuration.get_var(ctx.guild.id, config_section, target) + roles = await Configuration.get_var(ctx.guild.id, config_section, target) sname = list_name[:-1] if list_name[-1:] == "s" else list_name if item == ctx.guild.default_role: return await ctx.send( @@ -46,7 +46,7 @@ async def add_item(ctx, item, item_type, list_name="roles", config_section="PERM async def remove_item(ctx, item, item_type, list_name="roles", config_section="PERMISSIONS"): target = f"{item_type}_{list_name}".upper() - roles = Configuration.get_var(ctx.guild.id, config_section, target) + roles = await Configuration.get_var(ctx.guild.id, config_section, target) sname = list_name[:-1] if list_name[-1:] == "s" else list_name if item.id not in roles: await ctx.send( @@ -60,7 +60,7 @@ async def remove_item(ctx, item, item_type, list_name="roles", config_section="P async def list_list(ctx, item_type, list_name="roles", wrapper="<@&{item}>", config_section="PERMISSIONS"): target = f"{item_type}_{list_name}".upper() - items = Configuration.get_var(ctx.guild.id, config_section, target) + items = await Configuration.get_var(ctx.guild.id, config_section, target) if len(items) == 0: desc = Translator.translate(f"no_{item_type}_{list_name}", ctx) else: @@ -119,7 +119,7 @@ async def prefix(self, ctx: commands.Context, *, new_prefix: str = None): """configure_prefix_help""" if new_prefix is None: await ctx.send( - f"{Translator.translate('current_server_prefix', ctx, prefix=Configuration.get_var(ctx.guild.id, 'GENERAL', 'PREFIX'))}") + f"{Translator.translate('current_server_prefix', ctx, prefix=await Configuration.get_var(ctx.guild.id, 'GENERAL', 'PREFIX'))}") elif len(new_prefix) > 25: await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('prefix_too_long', ctx)}") else: @@ -272,7 +272,7 @@ async def remove_from_allowed_list(self, ctx: commands.Context, server: int): @configure.command(aliases=["trustedinvitebypass"]) async def trusted_invite_bypass(self, ctx: commands.Context, enabled_status: bool): """censortrustedbypass_help""" - config_status = Configuration.get_var(ctx.guild.id, "CENSORING", "ALLOW_TRUSTED_BYPASS") + config_status = await Configuration.get_var(ctx.guild.id, "CENSORING", "ALLOW_TRUSTED_BYPASS") enabled_string = "enabled" if enabled_status else "disabled" enabled_string = Translator.translate(enabled_string, ctx.guild.id) @@ -304,7 +304,7 @@ async def removeIgnoredUser(self, ctx: commands.Context, user: disnake.User): async def configure_cog_overrides(self, ctx): """cog_overrides_help""" if ctx.invoked_subcommand is None: - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") desc = "" for k, v in overrides.items(): lvl = v["required"] @@ -333,7 +333,7 @@ async def add_cog_override(self, ctx, cog: str, perm_lvl: int): await ctx.send( f"{Emoji.get_chat_emoji('NO')} {Translator.translate('cog_max_perm_violation', ctx, cog=cog, max_lvl=max_lvl, max_lvl_name=Translator.translate(f'perm_lvl_{max_lvl}', ctx))}") else: - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") if cog not in overrides: overrides[cog] = { "required": perm_lvl, @@ -352,7 +352,7 @@ async def add_cog_override(self, ctx, cog: str, perm_lvl: int): @configure_cog_overrides.command(name="remove") async def remove_cog_override(self, ctx, cog: str): - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") if cog in overrides: overrides[cog]["required"] = -1 Configuration.save(ctx.guild.id) @@ -366,7 +366,7 @@ async def remove_cog_override(self, ctx, cog: str): async def command_overrides(self, ctx): """command_overrides_help""" if ctx.invoked_subcommand is None: - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") embed = disnake.Embed(color=6008770, title=Translator.translate('command_overrides', ctx)) has_overrides = False for cog in self.bot.cogs: @@ -400,7 +400,7 @@ async def add_command_override(self, ctx, command: str, perm_lvl: int): await ctx.send( f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_max_perm_violation', ctx, command=command, max_lvl=lvl, max_lvl_name=Translator.translate(f'perm_lvl_{lvl}', ctx))}") else: - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") if cog_name not in overrides: overrides[cog_name] = { "required": -1, @@ -434,7 +434,7 @@ async def remove_command_override(self, ctx, command: str): command_object = self.bot.get_command(command) if command_object is not None: cog_name = command_object.cog_name - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") found = False if cog_name in overrides: override = Permissioncheckers.get_perm_dict(command_object.qualified_name.split(" "), @@ -491,7 +491,7 @@ async def add_lvl4(self, ctx, command: str, person: disnake.Member): command_object = self.bot.get_command(command) if command_object is not None: cog_name = command_object.cog_name - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") if cog_name not in overrides: overrides[cog_name] = { "required": -1, @@ -526,7 +526,7 @@ async def remove_lvl4(self, ctx, command: str, person: disnake.Member): command_object = self.bot.get_command(command) if command_object is not None: cog_name = command_object.cog_name - overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES") found = False if cog_name in overrides: lvl4_list = Permissioncheckers.get_perm_dict(command.split(" "), overrides[cog_name], strict=True) @@ -547,7 +547,7 @@ async def remove_lvl4(self, ctx, command: str, person: disnake.Member): async def logging(self, ctx): if ctx.invoked_subcommand is None: embed = disnake.Embed(color=6008770, title=Translator.translate('log_channels', ctx)) - channels = Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") + channels = await Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") if len(channels) > 0: for cid, info in channels.items(): embed.add_field(name=cid, value=self.get_channel_properties(ctx, cid, info["CATEGORIES"])) @@ -576,7 +576,7 @@ def get_channel_properties(ctx, cid, info): @logging.command(name="add") async def add_logging(self, ctx, channel: disnake.TextChannel, *, types): cid = str(channel.id) - channels = Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") + channels = await Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") if cid not in channels: channels[cid] = { "CATEGORIES": [], @@ -611,7 +611,7 @@ async def add_logging(self, ctx, channel: disnake.TextChannel, *, types): features = [] for a in added: feature = Utils.find_key(Features.requires_logging, a) - if feature is not None and not Configuration.get_var(ctx.guild.id, feature): + if feature is not None and not await Configuration.get_var(ctx.guild.id, feature): features.append(feature) if len(features) > 0: @@ -638,7 +638,7 @@ def check(interaction: Interaction): @logging.command(name="remove") async def remove_logging(self, ctx, cid: LoggingChannel, *, types): channel = self.bot.get_channel(int(cid)) - channels = Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") + channels = await Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") if cid not in channels: await ctx.send( f"{Emoji.get_chat_emoji('NO')} {Translator.translate('no_log_channel', ctx, channel=f'<{cid}>')}") @@ -698,7 +698,7 @@ def get_logging_status(self, ctx): @commands.guild_only() async def features(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send(embed=self.get_features_status(ctx)) + await ctx.send(embed=await self.get_features_status(ctx)) @features.command(name="enable") async def enable_feature(self, ctx, types): @@ -720,7 +720,7 @@ async def _enable_feature(self, ctx, types, interaction): unknown.append(t) message = "" for t in known: - if Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS" if t == "EDIT_LOGS" else "CENSORING", "ENABLED"): + if await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS" if t == "EDIT_LOGS" else "CENSORING", "ENABLED"): ignored.append(t) else: enabled.append(t) @@ -744,30 +744,30 @@ async def _enable_feature(self, ctx, types, interaction): unknown) if interaction is None: - await ctx.send(message, embed=self.get_features_status(ctx)) + await ctx.send(message, embed=await self.get_features_status(ctx)) else: - interaction.response.edit_message(content=message, embed=self.get_features_status(ctx), view=None) + interaction.response.edit_message(content=message, embed=await self.get_features_status(ctx), view=None) @staticmethod - def get_features_status(ctx): + async def get_features_status(ctx): enabled = f"{Emoji.get_chat_emoji('YES')} {Translator.translate('enabled', ctx)}" disabled = f"{Emoji.get_chat_emoji('NO')} {Translator.translate('disabled', ctx)}" embed = disnake.Embed(color=6008770, title=Translator.translate('features', ctx)) for f, t in Features.requires_logging.items(): - e = Configuration.get_var(ctx.guild.id, t, "ENABLED", f) + e = await Configuration.get_var(ctx.guild.id, t, "ENABLED", f) embed.add_field(name=f, value=enabled if e else disabled) return embed def can_remove(self, guild, logging): counts = dict() - for cid, info in Configuration.get_var(guild, "LOG_CHANNELS").items(): + for cid, info in Configuration.legacy_get_var(guild, "LOG_CHANNELS").items(): for i in info: if i not in counts: counts[i] = 1 else: counts[i] += 1 return logging not in Features.requires_logging.values() or ( - logging in counts and counts[logging] > 1) or Configuration.get_var( + logging in counts and counts[logging] > 1) or Configuration.legacy_get_var( "MESSAGE_LOGS" if logging == "EDIT_LOGS" else "CENSORING", "ENABLED", False) @features.command(name="disable") @@ -787,7 +787,7 @@ async def feature_disable(self, ctx, types: str): unknown.append(t) message = "" for t in known: - if not Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS" if t == "EDIT_LOGS" else "CENSORING", "ENABLED"): + if not await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS" if t == "EDIT_LOGS" else "CENSORING", "ENABLED"): ignored.append(t) else: disabled.append(t) @@ -806,7 +806,7 @@ async def feature_disable(self, ctx, types: str): message += MessageUtils.assemble(ctx.guild.id, 'NO', 'features_unknown', count=len(unknown)) + ', '.join( unknown) - await ctx.send(message, embed=self.get_features_status(ctx)) + await ctx.send(message, embed=await self.get_features_status(ctx)) def extract_types(self, raw_types): raw_types = raw_types.upper() @@ -841,7 +841,7 @@ async def ignored_channels_changes(self, ctx): @ignored_channels_changes.command("add") async def ignored_channels_changes_add(self, ctx, channel: typing.Union[disnake.TextChannel, disnake.VoiceChannel]): """ignored_channels_add_help""" - channels = Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_CHANGES') + channels = await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_CHANGES') if channel.id in channels: await MessageUtils.send_to(ctx, 'NO', 'ignored_channels_already_on_list', channel=channel.mention) else: @@ -852,7 +852,7 @@ async def ignored_channels_changes_add(self, ctx, channel: typing.Union[disnake. @ignored_channels_changes.command("remove") async def ignored_channels_changes_remove(self, ctx, channel: typing.Union[disnake.TextChannel, disnake.VoiceChannel]): """ignored_channels_remove_help""" - channels = Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_CHANGES') + channels = await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_CHANGES') if not channel.id in channels: await MessageUtils.send_to(ctx, 'NO', 'ignored_channels_not_on_list', channel=channel.mention) else: @@ -867,7 +867,7 @@ async def ignored_channels_changes_list(self, ctx): @staticmethod async def list_channels(ctx, type): - channel_list = Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", f'IGNORED_CHANNELS_{type.upper()}') + channel_list = await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", f'IGNORED_CHANNELS_{type.upper()}') if len(channel_list) > 0: channels = "\n".join(ctx.guild.get_channel(c).mention for c in channel_list) else: @@ -887,7 +887,7 @@ async def ignored_channels_edits(self, ctx): @ignored_channels_edits.command("add") async def ignored_channels_edits_add(self, ctx, channel: typing.Union[disnake.TextChannel, disnake.VoiceChannel]): """ignored_channels_add_help""" - channels = Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_OTHER') + channels = await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_OTHER') if channel.id in channels: await MessageUtils.send_to(ctx, 'NO', 'ignored_channels_already_on_list', channel=channel.mention) else: @@ -898,7 +898,7 @@ async def ignored_channels_edits_add(self, ctx, channel: typing.Union[disnake.Te @ignored_channels_edits.command("remove") async def ignored_channels_edits_remove(self, ctx, channel: typing.Union[disnake.TextChannel, disnake.VoiceChannel]): """ignored_channels_remove_help""" - channels = Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_OTHER') + channels = await Configuration.get_var(ctx.guild.id, "MESSAGE_LOGS", 'IGNORED_CHANNELS_OTHER') if channel.id not in channels: await MessageUtils.send_to(ctx, 'NO', 'ignored_channels_not_on_list') else: @@ -922,7 +922,7 @@ async def mute(self, ctx: commands.Context): """disable_mute_help""" await Infraction.filter(type="Mute", guild_id=ctx.guild.id, active=True).update(active=False) infractions = await Infraction.filter(type="Mute", guild_id=ctx.guild.id, active=True) - role = ctx.guild.get_role(Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE")) + role = ctx.guild.get_role(await Configuration.get_var(ctx.guild.id, "ROLES", "MUTE_ROLE")) for i in infractions: member = ctx.guild.get_member(i.user_id) if member is not None: @@ -933,7 +933,7 @@ async def mute(self, ctx: commands.Context): async def dm_configure(self, ctx, kind, value): config_key = f"DM_ON_{kind.upper()}" - current = Configuration.get_var(ctx.guild.id, "INFRACTIONS", config_key) + current = await Configuration.get_var(ctx.guild.id, "INFRACTIONS", config_key) if value is None: await MessageUtils.send_to(ctx, 'WRENCH', f'dm_on_{kind}_msg_is_' + ('enabled' if current else 'disabled')) elif current != value: @@ -982,7 +982,7 @@ async def dm_notifications(self, ctx): for x in ["WARN", "UNMUTE", "MUTE", "KICK", "BAN", "TEMPBAN"]: key = f"DM_ON_{x}" - v = Configuration.get_var(ctx.guild.id, "INFRACTIONS", key) + v = await Configuration.get_var(ctx.guild.id, "INFRACTIONS", key) embed.add_field(name=key, value=enabled if v else disabled) await ctx.send(embed=embed) @@ -1003,7 +1003,7 @@ async def log_message_ids(self, ctx, value: bool): async def censor_list(self, ctx): """censor_list_help""" if ctx.invoked_subcommand is None: - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") if len(censor_list) > 0: pages = Pages.paginate("\n".join(censor_list)) else: @@ -1014,7 +1014,7 @@ async def censor_list(self, ctx): @censor_list.command("add") async def censor_list_add(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") if word in censor_list: await MessageUtils.send_to(ctx, "NO", "already_censored", word=word) else: @@ -1025,7 +1025,7 @@ async def censor_list_add(self, ctx, *, word: str): @censor_list.command("remove") async def censor_list_remove(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") if word not in censor_list: await MessageUtils.send_to(ctx, "NO", "not_censored", word=word) else: @@ -1035,7 +1035,7 @@ async def censor_list_remove(self, ctx, *, word: str): @censor_list.command("get") async def censor_list_get(self, ctx): - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "TOKEN_CENSORLIST") if len(censor_list) > 0: out = '\n'.join(censor_list) buffer = io.BytesIO() @@ -1072,7 +1072,7 @@ async def receive_list(self, ctx, target_cat, target_key, prefix): await MessageUtils.send_to(ctx, 'NO', 'list_parsing_failed') return - max_length = Configuration.get_var(ctx.guild.id, target_cat, "MAX_LIST_LENGTH") + max_length = await Configuration.get_var(ctx.guild.id, target_cat, "MAX_LIST_LENGTH") new_list = content.splitlines() if len(new_list) > max_length: @@ -1088,7 +1088,7 @@ async def receive_list(self, ctx, target_cat, target_key, prefix): @configure.group(aliases=["wordcensorlist", "wcl"], invoke_without_command=True) async def word_censor_list(self, ctx): if ctx.invoked_subcommand is None: - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") if len(censor_list) > 0: pages = Pages.paginate("\n".join(censor_list)) else: @@ -1101,7 +1101,7 @@ async def word_censor_list(self, ctx): @word_censor_list.command("add") async def word_censor_list_add(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") if word in censor_list: await MessageUtils.send_to(ctx, "NO", "word_already_censored", word=word) else: @@ -1114,7 +1114,7 @@ async def word_censor_list_add(self, ctx, *, word: str): @word_censor_list.command("remove") async def word_censor_list_remove(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") if word not in censor_list: await MessageUtils.send_to(ctx, "NO", "word_not_censored", word=word) else: @@ -1126,7 +1126,7 @@ async def word_censor_list_remove(self, ctx, *, word: str): @word_censor_list.command("get") async def word_censor_list_get(self, ctx): - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "WORD_CENSORLIST") if len(censor_list) > 0: out = '\n'.join(censor_list) buffer = io.BytesIO() @@ -1146,7 +1146,7 @@ async def word_censor_list_upload(self, ctx): async def flag_list(self, ctx): """flag_list_help""" if ctx.invoked_subcommand is None: - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") if len(censor_list) > 0: pages = Pages.paginate("\n".join(censor_list)) else: @@ -1159,7 +1159,7 @@ async def flag_list(self, ctx): @flag_list.command("add") async def flag_list_add(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") if word in censor_list: await MessageUtils.send_to(ctx, "NO", "already_flagged", word=word) else: @@ -1172,7 +1172,7 @@ async def flag_list_add(self, ctx, *, word: str): @flag_list.command("remove") async def flag_list_remove(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") if word not in censor_list: await MessageUtils.send_to(ctx, "NO", "not_flagged", word=word) else: @@ -1188,7 +1188,7 @@ async def flag_list_upload(self, ctx): @flag_list.command("get") async def flag_list_get(self, ctx): - flag_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") + flag_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "TOKEN_LIST") if len(flag_list) > 0: out = '\n'.join(flag_list) buffer = io.BytesIO() @@ -1204,7 +1204,7 @@ async def flag_list_get(self, ctx): async def word_flag_list(self, ctx): """word_flag_list_help""" if ctx.invoked_subcommand is None: - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") if len(censor_list) > 0: pages = Pages.paginate("\n".join(censor_list)) else: @@ -1217,7 +1217,7 @@ async def word_flag_list(self, ctx): @word_flag_list.command("add") async def word_flag_list_add(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") if word in censor_list: await MessageUtils.send_to(ctx, "NO", "word_already_flagged", word=word) else: @@ -1230,7 +1230,7 @@ async def word_flag_list_add(self, ctx, *, word: str): @word_flag_list.command("remove") async def word_flag_list_remove(self, ctx, *, word: str): word = word.lower() - censor_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") if word not in censor_list: await MessageUtils.send_to(ctx, "NO", "word_not_flagged", word=word) else: @@ -1246,7 +1246,7 @@ async def word_flag_list_upload(self, ctx): @word_flag_list.command("get") async def word_flag_list_get(self, ctx): - flag_list = Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") + flag_list = await Configuration.get_var(ctx.guild.id, "FLAGGING", "WORD_LIST") if len(flag_list) > 0: out = '\n'.join(flag_list) buffer = io.BytesIO() @@ -1264,8 +1264,8 @@ async def word_flag_list_get(self, ctx): async def role_list(self, ctx): """configure_role_list_help""" if ctx.invoked_subcommand is None: - items = Configuration.get_var(ctx.guild.id, "ROLES", f"ROLE_LIST") - mode = "allow" if Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" + items = await Configuration.get_var(ctx.guild.id, "ROLES", f"ROLE_LIST") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" if len(items) == 0: desc = Translator.translate(f"no_role_{mode}", ctx) else: @@ -1276,8 +1276,8 @@ async def role_list(self, ctx): @role_list.command("add") async def role_list_add(self, ctx, *, role: disnake.Role): """configure_role_list_add""" - roles = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") - mode = "allow" if Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" + roles = await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" if role == ctx.guild.default_role: await MessageUtils.send_to(ctx, "NO", "default_role_forbidden") elif role.id in roles: @@ -1291,8 +1291,8 @@ async def role_list_add(self, ctx, *, role: disnake.Role): @role_list.command("remove", aliases=["rmv"]) async def role_list_remove(self, ctx, *, role: disnake.Role): """configure_role_list_remove""" - roles = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") - mode = "allow" if Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" + roles = await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE") else "block" if role.id not in roles: await MessageUtils.send_to(ctx, "NO", f"role_list_rmv_fail_{mode}", role=Utils.escape_markdown(role.name)) else: @@ -1314,8 +1314,8 @@ async def role_list_mode(self, ctx, mode: ListMode): async def domain_list(self, ctx): """configure_domain_list_help""" if ctx.invoked_subcommand is None: - items = Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") - mode = "allowed" if Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "blocked" + items = await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") + mode = "allowed" if await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "blocked" if len(items) == 0: desc = Translator.translate(f"empty_domain_list", ctx) else: @@ -1327,8 +1327,8 @@ async def domain_list(self, ctx): async def domain_list_add(self, ctx, *, domain): """configure_domain_list_add""" domain = domain.lower() - domains = Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") - mode = "allow" if Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "block" + domains = await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "block" if domain in domains: await MessageUtils.send_to(ctx, "NO", f"domain_list_add_fail_{mode}", domain=domain) else: @@ -1339,8 +1339,8 @@ async def domain_list_add(self, ctx, *, domain): @domain_list.command("remove", aliases=["rmv"]) async def domain_list_remove(self, ctx, *, domain): """configure_domain_list_remove""" - domains = Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") - mode = "allow" if Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "block" + domains = await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED") else "block" if domain not in domains: await MessageUtils.send_to(ctx, "NO", f"domain_list_rmv_fail_{mode}", domain=domain) else: @@ -1357,7 +1357,7 @@ async def domain_list_mode(self, ctx, mode: ListMode): @domain_list.command("get") async def domain_list_get(self, ctx): - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "DOMAIN_LIST") if len(censor_list) > 0: out = '\n'.join(censor_list) buffer = io.BytesIO() @@ -1377,7 +1377,7 @@ async def domain_list_upload(self, ctx): @commands.guild_only() async def timezone(self, ctx, new_zone=None): """timezone_help""" - current_zone = Configuration.get_var(ctx.guild.id, "GENERAL", "TIMEZONE") + current_zone = await Configuration.get_var(ctx.guild.id, "GENERAL", "TIMEZONE") if new_zone is None: # no new zone, spit out the current one await MessageUtils.send_to(ctx, "CLOCK", "current_timezone", timezone=current_zone) @@ -1397,7 +1397,7 @@ async def timezone(self, ctx, new_zone=None): async def full_message_censor_list(self, ctx): """full_message_censor_list_help""" if ctx.invoked_subcommand is None: - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") if len(censor_list) > 0: pages = Pages.paginate("\n".join(censor_list)) else: @@ -1409,7 +1409,7 @@ async def full_message_censor_list(self, ctx): @full_message_censor_list.command("add") async def full_message_censor_list_add(self, ctx, *, message: str): - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") if message.lower() in censor_list: await MessageUtils.send_to(ctx, "NO", "already_censored", word=message) else: @@ -1419,7 +1419,7 @@ async def full_message_censor_list_add(self, ctx, *, message: str): @full_message_censor_list.command("remove") async def full_message_censor_list_remove(self, ctx, *, message: str): - censor_list = Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") + censor_list = await Configuration.get_var(ctx.guild.id, "CENSORING", "FULL_MESSAGE_LIST") if message.lower() not in censor_list: await MessageUtils.send_to(ctx, "NO", "not_censored", word=message) else: @@ -1439,8 +1439,8 @@ async def censor_emoji_only_messages(self, ctx, value: bool): @commands.bot_has_permissions(embed_links=True) async def custom_commands_role_list(self, ctx): if ctx.invoked_subcommand is None: - items = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", f"ROLES") - mode = "allow" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" + items = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", f"ROLES") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" if len(items) == 0: desc = Translator.translate(f"custom_commands_role_list_empty_{mode}", ctx) else: @@ -1451,8 +1451,8 @@ async def custom_commands_role_list(self, ctx): @custom_commands_role_list.command("add") async def custom_commands_role_list_add(self, ctx, *, role: disnake.Role): - roles = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLES") - mode = "allow" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" + roles = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLES") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" if role == ctx.guild.default_role: await MessageUtils.send_to(ctx, "NO", "default_role_forbidden") elif role.id in roles: @@ -1466,8 +1466,8 @@ async def custom_commands_role_list_add(self, ctx, *, role: disnake.Role): @custom_commands_role_list.command("remove", aliases=["rmv"]) async def custom_commands_role_list_remove(self, ctx, *, role: disnake.Role): - roles = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLES") - mode = "allow" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" + roles = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLES") + mode = "allow" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") else "block" if role.id not in roles: await MessageUtils.send_to(ctx, "NO", f"custom_commands_role_list_rmv_fail_{mode}", role=Utils.escape_markdown(role.name)) @@ -1482,8 +1482,8 @@ async def custom_commands_role_list_remove(self, ctx, *, role: disnake.Role): @commands.bot_has_permissions(embed_links=True) async def custom_commands_channel_list(self, ctx): if ctx.invoked_subcommand is None: - items = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS") - mode = "use" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" + items = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS") + mode = "use" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" if len(items) == 0: desc = Translator.translate(f"custom_commands_channel_list_empty_{mode}", ctx) else: @@ -1494,8 +1494,8 @@ async def custom_commands_channel_list(self, ctx): @custom_commands_channel_list.command("add") async def custom_commands_ignored_channels_add(self, ctx, channel: TextChannel): - channels = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", 'CHANNELS') - mode = "use" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" + channels = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", 'CHANNELS') + mode = "use" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" if channel.id in channels: await MessageUtils.send_to(ctx, 'NO', f'custom_commands_channel_already_on_{mode}_list', channel=channel.mention) @@ -1506,8 +1506,8 @@ async def custom_commands_ignored_channels_add(self, ctx, channel: TextChannel): @custom_commands_channel_list.command("remove") async def custom_commands_ignored_channels_remove(self, ctx, channel: TextChannel): - channels = Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", 'CHANNELS') - mode = "use" if Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" + channels = await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", 'CHANNELS') + mode = "use" if await Configuration.get_var(ctx.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") else "ignore" if not channel.id in channels: await MessageUtils.send_to(ctx, 'NO', f'custom_commands_channel_not_on_{mode}_list', channel=channel.mention) @@ -1564,7 +1564,7 @@ async def anti_spam(self, ctx): await ctx.send(embed=await self.get_anti_spam_embed(ctx)) async def get_anti_spam_embed(self, ctx): - buckets = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") + buckets = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") embed = disnake.Embed() limit = Translator.translate("limit", ctx) timeframe = Translator.translate("timeframe", ctx) @@ -1581,7 +1581,7 @@ async def get_anti_spam_embed(self, ctx): for other in self.anti_spam_types - seen: embed.add_field(name=other, value=disabled) - users = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") + users = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") desc = None if len(users) == 0: desc = Translator.translate('no_ignored_spammers', ctx) @@ -1590,7 +1590,7 @@ async def get_anti_spam_embed(self, ctx): desc = "\n".join(f"{str(user)} (`{user.id}`)" for user in resolved_users) embed.add_field(name=Translator.translate('ignored_spammers', ctx), value=desc) - roles = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") + roles = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") if len(roles) == 0: desc = Translator.translate('no_ignored_roles', ctx) else: @@ -1614,7 +1614,7 @@ async def set(self, ctx, type: SpamType, amount: RangedInt(2, 150), seconds: Ran Configuration.set_var(ctx.guild.id, "ANTI_SPAM", "ENABLED", True) Configuration.set_var(ctx.guild.id, "ANTI_SPAM", "CLEAN", True) - existing = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") + existing = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") new = { "TYPE": type, @@ -1644,7 +1644,7 @@ async def set(self, ctx, type: SpamType, amount: RangedInt(2, 150), seconds: Ran @anti_spam.command("disable") async def anti_spam_disable(self, ctx, type: SpamType): """anti_spam_disable_help""" - existing = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") + existing = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "BUCKETS") for i in range(0, len(existing)): if existing[i]["TYPE"] == type: del existing[i] @@ -1661,7 +1661,7 @@ async def immune_users(self, ctx): @immune_users.command("add") async def immune_users_add(self, ctx, member: disnake.Member): """anti_spam_immune_users_add_help""" - users = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") + users = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") if member.id in users: await MessageUtils.send_to(ctx, 'NO', 'already_immune', user=Utils.clean_user(member)) else: @@ -1673,7 +1673,7 @@ async def immune_users_add(self, ctx, member: disnake.Member): @immune_users.command("remove") async def immune_users_remove(self, ctx, mid: int): """anti_spam_immune_users_remove_help""" - users = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") + users = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_USERS") user = await Utils.get_user(mid) uname = Utils.clean_user(user) if user is not None else mid if mid not in users: @@ -1692,7 +1692,7 @@ async def immune_roles(self, ctx): @immune_roles.command("add") async def immune_roles_add(self, ctx, role: disnake.Role): """anti_spam_immune_roles_add_help""" - roles = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") + roles = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") if role.id in roles: await MessageUtils.send_to(ctx, 'NO', 'role_already_immune', role=role.name) else: @@ -1704,7 +1704,7 @@ async def immune_roles_add(self, ctx, role: disnake.Role): @immune_roles.command("remove") async def immune_roles_roles(self, ctx, role: int): """anti_spam_immune_roles_remove_help""" - roles = Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") + roles = await Configuration.get_var(ctx.guild.id, "ANTI_SPAM", "EXEMPT_ROLES") r = ctx.guild.get_role(role) if role not in roles: await MessageUtils.send_to(ctx, 'NO', 'role_not_immune', role=r.name if r is not None else role) @@ -1717,7 +1717,7 @@ async def immune_roles_roles(self, ctx, role: int): @configure.command(aliases=["trustedcensorbypass"]) async def trusted_censor_bypass(self, ctx: commands.Context, enabled_status: bool): """trustedcensorbypass_help""" - config_status = Configuration.get_var(ctx.guild.id, "CENSORING", "ALLOW_TRUSTED_CENSOR_BYPASS") + config_status = await Configuration.get_var(ctx.guild.id, "CENSORING", "ALLOW_TRUSTED_CENSOR_BYPASS") enabled_string = "enabled" if enabled_status else "disabled" enabled_string = Translator.translate(enabled_string, ctx.guild.id) @@ -1732,7 +1732,7 @@ async def trusted_censor_bypass(self, ctx: commands.Context, enabled_status: boo @configure.command(aliases=["trustedflagbypass"]) async def trusted_flag_bypass(self, ctx: commands.Context, enabled_status: bool): """trustedflagbypass_help""" - config_status = Configuration.get_var(ctx.guild.id, "FLAGGING", "TRUSTED_BYPASS") + config_status = await Configuration.get_var(ctx.guild.id, "FLAGGING", "TRUSTED_BYPASS") enabled_string = "enabled" if enabled_status else "disabled" enabled_string = Translator.translate(enabled_string, ctx.guild.id) @@ -1747,7 +1747,7 @@ async def trusted_flag_bypass(self, ctx: commands.Context, enabled_status: bool) @configure.command(aliases=["gmt"]) async def ghost_message_threshold(self, ctx, threshold: RangedInt(1, 60) = None): """ghost_message_threshold_help""" - current = Configuration.get_var(ctx.guild.id, "GENERAL", "GHOST_MESSAGE_THRESHOLD") + current = await Configuration.get_var(ctx.guild.id, "GENERAL", "GHOST_MESSAGE_THRESHOLD") if threshold is None: await MessageUtils.send_to(ctx, 'WRENCH', 'ghost_message_threshold_current', threshold=current) elif current != threshold: @@ -1759,7 +1759,7 @@ async def ghost_message_threshold(self, ctx, threshold: RangedInt(1, 60) = None) @configure.command(aliases=["gpt"]) async def ghost_ping_threshold(self, ctx, threshold: RangedInt(1, 60) = None): """ghost_ping_threshold_help""" - current = Configuration.get_var(ctx.guild.id, "GENERAL", "GHOST_PING_THRESHOLD") + current = await Configuration.get_var(ctx.guild.id, "GENERAL", "GHOST_PING_THRESHOLD") if threshold is None: await MessageUtils.send_to(ctx, 'WRENCH', 'ghost_ping_threshold_current', threshold=current) elif current != threshold: @@ -1770,7 +1770,7 @@ async def ghost_ping_threshold(self, ctx, threshold: RangedInt(1, 60) = None): @configure.command() async def ignore_ids_for_censoring(self, ctx, value: bool = None): - current = Configuration.get_var(ctx.guild.id, 'CENSORING', 'IGNORE_IDS') + current = await Configuration.get_var(ctx.guild.id, 'CENSORING', 'IGNORE_IDS') if value is None: await MessageUtils.send_to(ctx, 'WRENCH', f'censoring_ignore_ids_is_' + ('enabled' if current else 'disabled')) @@ -1783,7 +1783,7 @@ async def ignore_ids_for_censoring(self, ctx, value: bool = None): @configure.command() async def ignore_ids_for_flagging(self, ctx, value: bool = None): - current = Configuration.get_var(ctx.guild.id, 'FLAGGING', 'IGNORE_IDS') + current = await Configuration.get_var(ctx.guild.id, 'FLAGGING', 'IGNORE_IDS') if value is None: await MessageUtils.send_to(ctx, 'WRENCH', f'flagging_ignore_ids_is_' + ('enabled' if current else 'disabled')) @@ -1798,7 +1798,7 @@ async def ignore_ids_for_flagging(self, ctx, value: bool = None): async def on_guild_channel_delete(self, channel): changed = False for name in ["IGNORED_CHANNELS_CHANGES", "IGNORED_CHANNELS_OTHER"]: - channels = Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", name) + channels = await Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", name) if channel.id in channels: channels.remove(channel.id) changed = True diff --git a/GearBot/Util/Archive.py b/GearBot/Util/Archive.py index e9fa3e7f..c88902fc 100644 --- a/GearBot/Util/Archive.py +++ b/GearBot/Util/Archive.py @@ -15,7 +15,7 @@ async def archive_purge(bot, guild_id, messages): archive_counter += 1 channel = bot.get_channel(list(messages.values())[0].channel) timestamp = datetime.datetime.strftime(datetime.datetime.now().astimezone( - pytz.timezone(Configuration.get_var(guild_id, 'GENERAL', 'TIMEZONE'))), '%H:%M:%S') + pytz.timezone(await Configuration.get_var(guild_id, 'GENERAL', 'TIMEZONE'))), '%H:%M:%S') out = f"purged at {timestamp} from {channel.name}\n" out += await pack_messages(messages.values(), guild_id) buffer = io.BytesIO() @@ -29,7 +29,7 @@ async def pack_messages(messages, guild_id): reply = "" if message.reply_to is not None: reply = f" | In reply to https://discord.com/channels/{message.server}/{message.channel}/{message.reply_to}" - timestamp = datetime.datetime.strftime(disnake.Object(message.messageid).created_at.astimezone(pytz.timezone(Configuration.get_var(guild_id, 'GENERAL', 'TIMEZONE'))),'%H:%M:%S') + timestamp = datetime.datetime.strftime(disnake.Object(message.messageid).created_at.astimezone(pytz.timezone(await Configuration.get_var(guild_id, 'GENERAL', 'TIMEZONE'))),'%H:%M:%S') out += f"{timestamp} {message.server} - {message.channel} - {message.messageid} | {name} ({message.author}) | {message.content}{reply} | {(', '.join(Utils.assemble_attachment(message.channel, attachment.id, attachment.name) for attachment in message.attachments))}\r\n" return out diff --git a/GearBot/Util/Configuration.py b/GearBot/Util/Configuration.py index 26234322..5d8a72e5 100644 --- a/GearBot/Util/Configuration.py +++ b/GearBot/Util/Configuration.py @@ -1,6 +1,4 @@ import asyncio -from json import JSONDecodeError - MASTER_CONFIG = dict() SERVER_CONFIGS = dict() @@ -10,6 +8,8 @@ PERSISTENT = dict() TEMPLATE = dict() +class ConfigNotLoaded(Exception): + pass def save_master(): global MASTER_CONFIG @@ -47,11 +47,11 @@ def get_master_var(key, default=None): import json -import os from disnake.ext import commands from Util import GearbotLogging, Utils, Features +from database.DatabaseConnector import GuildConfig def initial_migration(config): @@ -440,28 +440,33 @@ async def initialize(bot: commands.Bot): # validate_config(guild.id) -def load_config(guild): - from Bot.TheRealGearBot import handle_exception +async def load_config(guild): global SERVER_CONFIGS - try: - config = Utils.fetch_from_disk(f'config/{guild}') - except JSONDecodeError as e: - GearbotLogging.error(f"Failed to deserialize config! {e}") - asyncio.create_task(handle_exception("loading config", BOT, e)) - config = Utils.fetch_from_disk("template") - if len(config.keys()) != 0 and "VERSION" not in config and len(config) < 15: + config = await GuildConfig.get_or_none(guild_id=guild) + if config is None: + loaded = Utils.fetch_from_disk("template") + else: + loaded = config.guild_config + if len(loaded.keys()) != 0 and "VERSION" not in loaded and len(loaded) < 15: GearbotLogging.info(f"The config for {guild} is to old to migrate, resetting") - config = dict() - elif len(config.keys()) != 0: - if "VERSION" not in config: - config["VERSION"] = 0 - SERVER_CONFIGS[guild] = update_config(guild, config) - if len(config.keys()) == 0: + loaded = dict() + elif len(loaded.keys()) != 0: + if "VERSION" not in loaded: + loaded["VERSION"] = 0 + SERVER_CONFIGS[guild] = update_config(guild, loaded) + if len(loaded.keys()) == 0: GearbotLogging.info(f"No config available for {guild}, creating a blank one.") SERVER_CONFIGS[guild] = Utils.fetch_from_disk("template") save(guild) validate_config(guild) - Features.check_server(guild) + await Features.check_server(guild) + +async def load_bulk(guilds): + global SERVER_CONFIGS + configs = await GuildConfig.filter(guild_id__in=guilds) + for c in configs: + SERVER_CONFIGS[c.guild_id] = c.guild_config + await Features.check_server(c.guild_id) def validate_config(guild_id): @@ -479,7 +484,7 @@ def validate_config(guild_id): def checklist(guid, key, getter): changed = False tr = list() - cl = get_var(guid, "PERMISSIONS", key) + cl = legacy_get_var(guid, "PERMISSIONS", key) for c in cl: if getter(c) is None: tr.append(c) @@ -493,23 +498,33 @@ def update_config(guild, config): while config["VERSION"] < CONFIG_VERSION: v = config["VERSION"] GearbotLogging.info(f"Upgrading config version from version {v} to {v + 1}") - d = f"config/backups/v{v}" - if not os.path.isdir(d): - os.makedirs(d) - Utils.save_to_disk(f"{d}/{guild}", config) + # d = f"config/backups/v{v}" + # if not os.path.isdir(d): + # os.makedirs(d) + # Utils.save_to_disk(f"{d}/{guild}", config) MIGRATORS[config["VERSION"]](config) config["VERSION"] += 1 - Utils.save_to_disk(f"config/{guild}", config) - return config -def get_var(id, section, key=None, default=None): +async def get_var(id, section, key=None, default=None): + if id is None: + raise ValueError("Where is this coming from?") + if not id in SERVER_CONFIGS.keys(): + GearbotLogging.info(f"Config entry requested before config was loaded for guild {id}, loading config for it") + await load_config(id) + s = SERVER_CONFIGS[id].get(section, {}) + if key is not None: + s = s.get(key, default) + return s + +def legacy_get_var(id, section, key=None, default=None): if id is None: raise ValueError("Where is this coming from?") if not id in SERVER_CONFIGS.keys(): GearbotLogging.info(f"Config entry requested before config was loaded for guild {id}, loading config for it") - load_config(id) + asyncio.create_task(load_config(id)) + raise ConfigNotLoaded() s = SERVER_CONFIGS[id].get(section, {}) if key is not None: s = s.get(key, default) @@ -519,21 +534,25 @@ def get_var(id, section, key=None, default=None): def set_var(id, cat, key, value): SERVER_CONFIGS[id].get(cat, dict())[key] = value save(id) - Features.check_server(id) + asyncio.create_task(Features.check_server(id)) def set_cat(id, cat, value): SERVER_CONFIGS[id][cat] = value save(id) - Features.check_server(id) + asyncio.create_task(Features.check_server(id)) def save(id): - global SERVER_CONFIGS - with open(f'config/{id}.json', 'w') as jsonfile: - jsonfile.write((json.dumps(SERVER_CONFIGS[id], indent=4, skipkeys=True, sort_keys=True))) - Features.check_server(id) - + asyncio.create_task(real_save(id)) + +async def real_save(id): + conf = await GuildConfig.get_or_none(guild_id=id) + if conf is None: + await GuildConfig.create(guild_id=id, guild_config=SERVER_CONFIGS[id]) + else: + conf.guild_config = SERVER_CONFIGS[id] + await conf.save() def load_persistent(): global PERSISTENT_LOADED, PERSISTENT diff --git a/GearBot/Util/Converters.py b/GearBot/Util/Converters.py index d652d471..e5a64c9b 100644 --- a/GearBot/Util/Converters.py +++ b/GearBot/Util/Converters.py @@ -209,7 +209,7 @@ async def convert(self, ctx, argument): class LoggingChannel(Converter): async def convert(self, ctx, argument): - channels = Configuration.get_var(ctx.guild.id, "LOG_CHANNELS") + channels = Configuration.legacy_get_var(ctx.guild.id, "LOG_CHANNELS") match = CHANNEL_ID_MATCHER.match(argument) if match is not None: argument = match.group(1) diff --git a/GearBot/Util/DashConfig.py b/GearBot/Util/DashConfig.py index ab15a7b6..726e9293 100644 --- a/GearBot/Util/DashConfig.py +++ b/GearBot/Util/DashConfig.py @@ -147,7 +147,7 @@ def log_validator(guild, key, value, preview, *_): channel = BOT.get_channel(int(key)) if channel is None: return "Unknown channel" - if channel.guild != guild and channel.guild.id not in Configuration.get_var(guild.id, "SERVER_LINKS"): + if channel.guild != guild and channel.guild.id not in Configuration.legacy_get_var(guild.id, "SERVER_LINKS"): return "You can not log to this guild" perms = channel.permissions_for(guild.me) required = ["send_messages", "embed_links", "attach_files"] @@ -462,10 +462,10 @@ def convert_back(target): return target -def update_config_section(guild, section, new_values, user, replace=False): +async def update_config_section(guild, section, new_values, user, replace=False): fields = VALIDATORS[section] errors = dict() - guild_config = Configuration.get_var(guild.id, section) + guild_config = await Configuration.get_var(guild.id, section) new_values = convert_back(new_values) diff --git a/GearBot/Util/DashUtils.py b/GearBot/Util/DashUtils.py index 6bbcbd22..55692d4f 100644 --- a/GearBot/Util/DashUtils.py +++ b/GearBot/Util/DashUtils.py @@ -40,15 +40,15 @@ def get_guild_perms(member): permission = 0 user_lvl = Permissioncheckers.user_lvl(member) for k, v in mappings.items(): - if user_lvl >= Configuration.get_var(member.guild.id, "DASH_SECURITY", k): + if user_lvl >= Configuration.legacy_get_var(member.guild.id, "DASH_SECURITY", k): permission |= v return permission -def assemble_guild_info(bot, member): +async def assemble_guild_info(bot, member): return { - "guild_info": server_info.server_info_raw(bot, member.guild), + "guild_info": await server_info.server_info_raw(bot, member.guild), "user_perms": { "user_dash_perms": get_guild_perms(member), "user_level": Permissioncheckers.user_lvl(member) diff --git a/GearBot/Util/Features.py b/GearBot/Util/Features.py index 9711f5d1..6e681a2b 100644 --- a/GearBot/Util/Features.py +++ b/GearBot/Util/Features.py @@ -3,9 +3,9 @@ LOG_MAP = dict() -def check_server(guild_id): +async def check_server(guild_id): enabled = set() - for cid, info in Configuration.get_var(guild_id, "LOG_CHANNELS").items(): + for cid, info in (await Configuration.get_var(guild_id, "LOG_CHANNELS")).items(): enabled.update(info["CATEGORIES"]) LOG_MAP[guild_id] = enabled diff --git a/GearBot/Util/GearbotLogging.py b/GearBot/Util/GearbotLogging.py index f44a896d..81f2bace 100644 --- a/GearBot/Util/GearbotLogging.py +++ b/GearBot/Util/GearbotLogging.py @@ -414,7 +414,7 @@ def log_raw(guild_id, key, message=None, embed=None, file=None): # determine where it should be logged so we don't need to bother assembling everything when it's just gona be voided anyways targets = [] - channels = Configuration.get_var(guild_id, "LOG_CHANNELS") + channels = Configuration.legacy_get_var(guild_id, "LOG_CHANNELS") for cid, settings in channels.items(): if info.category in settings["CATEGORIES"] and info.config_key not in settings["DISABLED_KEYS"]: targets.append(cid) @@ -431,7 +431,7 @@ def log_key(guild_id, key, embed=None, file=None, can_stamp=True, tag_on=None, t # determine where it should be logged so we don't need to bother assembling everything when it's just gona be voided anyways targets = [] - channels = Configuration.get_var(guild_id, "LOG_CHANNELS") + channels = Configuration.legacy_get_var(guild_id, "LOG_CHANNELS") for cid, settings in channels.items(): if info.category in settings["CATEGORIES"] and info.config_key not in settings["DISABLED_KEYS"]: targets.append(cid) @@ -442,9 +442,9 @@ def log_key(guild_id, key, embed=None, file=None, can_stamp=True, tag_on=None, t message = MessageUtils.assemble(guild_id, info.emoji, key, **kwargs).replace('@', '@\u200b') - if can_stamp and Configuration.get_var(guild_id, 'GENERAL', "TIMESTAMPS"): + if can_stamp and Configuration.legacy_get_var(guild_id, 'GENERAL', "TIMESTAMPS"): s = datetime.datetime.strftime( - timestamp.now().astimezone(pytz.timezone(Configuration.get_var(guild_id, 'GENERAL', 'TIMEZONE'))), + timestamp.now().astimezone(pytz.timezone(Configuration.legacy_get_var(guild_id, 'GENERAL', 'TIMEZONE'))), '%H:%M:%S') stamp = f"[`{s}`] " message = Utils.trim_message(f'{stamp} {message}', 2000) diff --git a/GearBot/Util/HelpGenerator.py b/GearBot/Util/HelpGenerator.py index fa27e36b..9e9cd714 100644 --- a/GearBot/Util/HelpGenerator.py +++ b/GearBot/Util/HelpGenerator.py @@ -24,7 +24,7 @@ async def command_list(bot, member, guild): output += " " + command_name + (" " * (longest - len(command_name) + 2)) + info + "\n" output_tree[cog] = output # sometimes we get a null prefix for some reason? - prefix = Configuration.get_var(guild.id, "GENERAL", "PREFIX") if guild is not None else '!' + prefix = await Configuration.get_var(guild.id, "GENERAL", "PREFIX") if guild is not None else '!' return dict_to_pages(output_tree, f"You can get more info about a command (params and subcommands) by using '{prefix}help '\nCommands followed by ↪ have subcommands") @@ -75,7 +75,7 @@ async def gen_command_help(bot, member, guild, command): signature = f"{signature} [{command.name}|{aliases}]" else: signature = f"{signature} {command.name}" - prefix = Configuration.get_var(guild.id, "GENERAL", "PREFIX") if guild is not None else "!" + prefix = await Configuration.get_var(guild.id, "GENERAL", "PREFIX") if guild is not None else "!" usage = f"{prefix}{signature}" sub_info = None if isinstance(command, GroupMixin) and hasattr(command, "all_commands"): diff --git a/GearBot/Util/MessageUtils.py b/GearBot/Util/MessageUtils.py index 76524491..a9637964 100644 --- a/GearBot/Util/MessageUtils.py +++ b/GearBot/Util/MessageUtils.py @@ -4,6 +4,7 @@ import datetime from disnake import Object, HTTPException, MessageType, AllowedMentions +from disnake.utils import time_snowflake from Util import Translator, Emoji, Archive, GearbotLogging from database import DBUtils @@ -54,7 +55,7 @@ async def update_message(bot, message_id, content, pinned): if message_id in DBUtils.batch: old = DBUtils.batch[message_id] DBUtils.batch[message_id] = fakeLoggedMessage(message_id, content, old.author, old.channel, old.server, old.type, pinned, old.attachments) - else: + elif message_id > time_snowflake(datetime.datetime.utcfromtimestamp(time.time() - 60*60*24*7*6).replace(tzinfo=datetime.timezone.utc)): await LoggedMessage.filter(messageid=message_id).update(content=content, pinned=pinned) def assemble(destination, emoji, m, translate=True, **kwargs): diff --git a/GearBot/Util/Permissioncheckers.py b/GearBot/Util/Permissioncheckers.py index 015c47d1..26747301 100644 --- a/GearBot/Util/Permissioncheckers.py +++ b/GearBot/Util/Permissioncheckers.py @@ -37,8 +37,8 @@ def is_user(perm_type, member): if not hasattr(member, "roles"): return False - roles = Configuration.get_var(member.guild.id, "PERMISSIONS", f"{perm_type}_ROLES") - users = Configuration.get_var(member.guild.id, "PERMISSIONS", f"{perm_type}_USERS") + roles = Configuration.legacy_get_var(member.guild.id, "PERMISSIONS", f"{perm_type}_ROLES") + users = Configuration.legacy_get_var(member.guild.id, "PERMISSIONS", f"{perm_type}_USERS") if member.id in users: return True @@ -83,14 +83,14 @@ async def check_permission(command_object, guild, member, bot): if guild is None: return 0 >= get_required(command_object, command_object.cog.permissions) else: - overrides = Configuration.get_var(guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(guild.id, "PERM_OVERRIDES") cog_name = type(command_object.cog).__name__ required = -1 if cog_name in overrides: required = get_required(command_object, overrides[cog_name]) if required == -1: required = get_required(command_object, command_object.cog.permissions) - return get_user_lvl(guild, member, command_object) >= (command_object.cog.permissions["required"] if required == -1 else required) + return await get_user_lvl(guild, member, command_object) >= (command_object.cog.permissions["required"] if required == -1 else required) def get_command_pieces(command_object): @@ -134,7 +134,7 @@ def get_perm_dict(pieces, perm_dict, strict=False): return perm_dict -def get_user_lvl(guild, member, command_object=None): +async def get_user_lvl(guild, member, command_object=None): if guild.owner is not None and guild.owner.id == member.id: return 5 @@ -143,7 +143,7 @@ def get_user_lvl(guild, member, command_object=None): if command_object is not None: cog_name = type(command_object.cog).__name__ - overrides = Configuration.get_var(guild.id, "PERM_OVERRIDES") + overrides = await Configuration.get_var(guild.id, "PERM_OVERRIDES") if cog_name in overrides: target = overrides[cog_name] pieces = get_command_pieces(command_object) diff --git a/GearBot/Util/RaidHandling/RaidActions.py b/GearBot/Util/RaidHandling/RaidActions.py index 7ca1016c..6078770d 100644 --- a/GearBot/Util/RaidHandling/RaidActions.py +++ b/GearBot/Util/RaidHandling/RaidActions.py @@ -73,7 +73,7 @@ def is_reversable(self): class Mute(RaidAction): async def execute(self, bot, member, data, raid_id, raider_ids, shield): - role = member.guild.get_role(Configuration.get_var(member.guild.id, "ROLES", "MUTE_ROLE")) + role = member.guild.get_role(await Configuration.get_var(member.guild.id, "ROLES", "MUTE_ROLE")) if role is None: GearbotLogging.log_key(member.guild.id, 'raid_mute_failed_no_role') else: diff --git a/GearBot/Util/Selfroles.py b/GearBot/Util/Selfroles.py index 3417c934..f1001faf 100644 --- a/GearBot/Util/Selfroles.py +++ b/GearBot/Util/Selfroles.py @@ -4,7 +4,7 @@ def validate_self_roles(bot, guild): - roles = Configuration.get_var(guild.id, "ROLES", "SELF_ROLES") + roles = Configuration.legacy_get_var(guild.id, "ROLES", "SELF_ROLES") to_remove = set(role for role in roles if guild.get_role(role) is None) if len(to_remove) > 0: Configuration.set_var(guild.id, "ROLES", "SELF_ROLES", set(roles) - to_remove) @@ -13,7 +13,7 @@ def validate_self_roles(bot, guild): async def create_self_roles(bot, ctx): # create and send - pages = gen_role_pages(ctx.guild) + pages = await gen_role_pages(ctx.guild) embed = Embed(title=Translator.translate("assignable_roles", ctx, server_name=ctx.guild.name, page_num=1, page_count=len(pages)), colour=Colour(0xbffdd), description=pages[0]) message = await ctx.send(embed=embed) @@ -78,8 +78,8 @@ async def self_cleaner(bot, guild_id): return out -def gen_role_pages(guild): - roles = Configuration.get_var(guild.id, "ROLES", "SELF_ROLES") +async def gen_role_pages(guild): + roles = await Configuration.get_var(guild.id, "ROLES", "SELF_ROLES") current_roles = "" count = 1 for role in roles: diff --git a/GearBot/Util/Translator.py b/GearBot/Util/Translator.py index 80c3f835..3d2ebb4e 100644 --- a/GearBot/Util/Translator.py +++ b/GearBot/Util/Translator.py @@ -40,8 +40,10 @@ def translate(key, location, **kwargs): if lid is None or lid == 0 or lid == "@me": lang_key = "en_US" else: - lang_key = Configuration.get_var(lid, "GENERAL", "LANG") + lang_key = Configuration.legacy_get_var(lid, "GENERAL", "LANG") translated = key + if lang_key not in LANGS: + lang_key = "en_US" if key not in LANGS[lang_key]: if key not in untranlatable: BOT.loop.create_task(tranlator_log('WARNING', f'Untranslatable string detected in {lang_key}: {key}\n')) diff --git a/GearBot/Util/Utils.py b/GearBot/Util/Utils.py index af6fdff1..46929d1f 100644 --- a/GearBot/Util/Utils.py +++ b/GearBot/Util/Utils.py @@ -324,14 +324,14 @@ async def send_infraction(bot, user, guild, emoji, type, reason, **kwargs): if await get_member(bot, guild, user.id) is None: return try: - override = Configuration.get_var(guild.id, "INFRACTIONS", type.upper()) + override = await Configuration.get_var(guild.id, "INFRACTIONS", type.upper()) kwargs.update( reason=reason, server=guild.name, guild_id=guild.id ) if override is not None: - message = f"{Emoji.get_chat_emoji(emoji)} {format(override, kwargs, Configuration.get_var(guild.id, 'GENERAL', 'LANG'))}```{reason}```" + message = f"{Emoji.get_chat_emoji(emoji)} {format(override, kwargs, await Configuration.get_var(guild.id, 'GENERAL', 'LANG'))}```{reason}```" else: message = f"{Emoji.get_chat_emoji(emoji)} {Translator.translate(f'{type.lower()}_dm', guild.id, **kwargs)}```{reason}```" parts = message.split("```") diff --git a/GearBot/Util/server_info.py b/GearBot/Util/server_info.py index ae8bdc8f..8aaffd09 100644 --- a/GearBot/Util/server_info.py +++ b/GearBot/Util/server_info.py @@ -67,12 +67,12 @@ def server_info_embed(guild, request_guild=None): return embed -def server_info_raw(bot, guild): +async def server_info_raw(bot, guild): statuses = dict(online=0, idle=0, dnd=0, offline=0) for m in guild.members: statuses[str(m.status)] += 1 extra = dict() - for g in Configuration.get_var(guild.id, "SERVER_LINKS"): + for g in await Configuration.get_var(guild.id, "SERVER_LINKS"): extra.update(**{str(k): v for k, v in get_server_channels(bot.get_guild(g)).items()}) server_info = dict( name=guild.name, diff --git a/GearBot/database/DBUtils.py b/GearBot/database/DBUtils.py index bb9909ed..cf5a06ed 100644 --- a/GearBot/database/DBUtils.py +++ b/GearBot/database/DBUtils.py @@ -30,7 +30,7 @@ async def insert_message(message): # author=message.author.id, # channel=message.channel.id, server=message.guild.id, # type=message_type, pinned=message.pinned, attachments=[LoggedAttachment(id=a.id, name=a.filename, - # isImage=(a.width is not None or a.width is 0), + # isimage=(a.width is not None or a.width is 0), # message_id=message.id) for a in message.attachments]) # batch[message.id] = m # @@ -48,7 +48,7 @@ async def insert_message(message): reply_to=message.reference.message_id if is_reply else None) for a in message.attachments: await LoggedAttachment.create(id=a.id, name=a.filename, - isImage=(a.width is not None or a.width == 0), + isimage=(a.width is not None or a.width == 0), message=logged) except IntegrityError: diff --git a/GearBot/database/DatabaseConnector.py b/GearBot/database/DatabaseConnector.py index d78d116d..c0bc4d10 100644 --- a/GearBot/database/DatabaseConnector.py +++ b/GearBot/database/DatabaseConnector.py @@ -18,7 +18,7 @@ class LoggedMessage(Model): class LoggedAttachment(Model): id = fields.BigIntField(pk=True, generated=False) name = fields.CharField(max_length=100) - isImage = fields.BooleanField() + isimage = fields.BooleanField() message = fields.ForeignKeyField("models.LoggedMessage", related_name='attachments', source_field='message_id') @@ -83,6 +83,12 @@ class Node(Model): shard = fields.IntField() resource_version = fields.CharField(max_length=50) +class GuildConfig(Model): + guild_id = fields.BigIntField(pk=True) + guild_config = fields.JSONField() + + class Meta: + table = "guild_config" async def init(): GearbotLogging.info("Connecting to the database...") diff --git a/GearBot/views/SelfRole.py b/GearBot/views/SelfRole.py index 4cdbf367..c321131d 100644 --- a/GearBot/views/SelfRole.py +++ b/GearBot/views/SelfRole.py @@ -15,7 +15,7 @@ def __init__(self, guild, page): def set_buttons(view: disnake.ui.View, guild, page): view.children.clear() - roles = [role for role in (guild.get_role(r) for r in Configuration.get_var(guild.id, "ROLES", "SELF_ROLES")) if + roles = [role for role in (guild.get_role(r) for r in Configuration.legacy_get_var(guild.id, "ROLES", "SELF_ROLES")) if role is not None] pages = [p for p in Utils.chunks(roles, 20)] view.pages = len(pages) diff --git a/migration/add_config_table.sql b/migration/add_config_table.sql new file mode 100644 index 00000000..29709b40 --- /dev/null +++ b/migration/add_config_table.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS config +( + guild_id bigint NOT NULL, + config json NOT NULL, + PRIMARY KEY (guild_id) +);