From 4850ac8f3bd561eadd708fc9d2b9e138f2b99178 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 15 Jan 2023 05:44:46 +0000 Subject: [PATCH] Format Python code with psf/black push --- cogs/commands.py | 24 +++++++-- cogs/moderations_service_cog.py | 96 +++++++++++++++++++++++++-------- cogs/text_service_cog.py | 3 +- services/moderations_service.py | 8 ++- 4 files changed, 103 insertions(+), 28 deletions(-) diff --git a/cogs/commands.py b/cogs/commands.py index 67f7cae..4e3ef23 100644 --- a/cogs/commands.py +++ b/cogs/commands.py @@ -228,10 +228,28 @@ class Commands(discord.Cog, name="Commands"): ) @discord.guild_only() async def config( - self, ctx: discord.ApplicationContext, type: str, hate: str, hate_threatening: str, self_harm: str, sexual: str, sexual_minors: str, violence: str, violence_graphic: str + self, + ctx: discord.ApplicationContext, + type: str, + hate: str, + hate_threatening: str, + self_harm: str, + sexual: str, + sexual_minors: str, + violence: str, + violence_graphic: str, ): - await self.moderations_cog.config_command(ctx, type, hate, hate_threatening, self_harm, sexual, sexual_minors, violence, violence_graphic) - + await self.moderations_cog.config_command( + ctx, + type, + hate, + hate_threatening, + self_harm, + sexual, + sexual_minors, + violence, + violence_graphic, + ) """ GPT commands diff --git a/cogs/moderations_service_cog.py b/cogs/moderations_service_cog.py index 9fe9288..a0cf2ea 100644 --- a/cogs/moderations_service_cog.py +++ b/cogs/moderations_service_cog.py @@ -61,15 +61,19 @@ class ModerationsService(discord.Cog, name="ModerationsService"): guild_id = str(guild_id) key = guild_id + "_warn_set" if key not in MOD_DB: - MOD_DB[key] = zip(self.default_warn_set.keys, self.default_warn_set.thresholds) + MOD_DB[key] = zip( + self.default_warn_set.keys, self.default_warn_set.thresholds + ) MOD_DB.commit() return dict(MOD_DB[key]) def get_or_set_delete_set(self, guild_id): - guild_id=str(guild_id) + guild_id = str(guild_id) key = guild_id + "_delete_set" if key not in MOD_DB: - MOD_DB[key] = zip(self.default_delete_set.keys, self.default_delete_set.thresholds) + MOD_DB[key] = zip( + self.default_delete_set.keys, self.default_delete_set.thresholds + ) MOD_DB.commit() return dict(MOD_DB[key]) @@ -85,7 +89,6 @@ class ModerationsService(discord.Cog, name="ModerationsService"): MOD_DB[key] = zip(threshold_set.keys, threshold_set.thresholds) MOD_DB.commit() - def set_guild_moderated(self, guild_id, status=True): if guild_id not in MOD_DB: MOD_DB[guild_id] = {"moderated": status, "alert_channel": 0} @@ -115,8 +118,12 @@ class ModerationsService(discord.Cog, name="ModerationsService"): Moderation.moderation_tasks[guild_id] = asyncio.ensure_future( Moderation.process_moderation_queue( - Moderation.moderation_queues[guild_id], 1, 1, moderations_channel, - warn_set, delete_set + Moderation.moderation_queues[guild_id], + 1, + 1, + moderations_channel, + warn_set, + delete_set, ) ) print("Launched the moderations service for guild " + str(guild_id)) @@ -142,13 +149,17 @@ class ModerationsService(discord.Cog, name="ModerationsService"): return # Create the moderations service. - await self.start_moderations_service(guild_id=ctx.guild_id, alert_channel_id=alert_channel_id) + await self.start_moderations_service( + guild_id=ctx.guild_id, alert_channel_id=alert_channel_id + ) await ctx.respond("Moderations is now enabled for this guild") elif status == "off": # Cancel the moderations service. await self.stop_moderations_service(ctx.guild_id) - await ctx.respond("Moderations is now disabled for this guild", ephemeral=True) + await ctx.respond( + "Moderations is now disabled for this guild", ephemeral=True + ) async def stop_moderations_service(self, guild_id): self.set_guild_moderated(guild_id, False) @@ -157,7 +168,6 @@ class ModerationsService(discord.Cog, name="ModerationsService"): Moderation.moderation_queues[guild_id] = None Moderation.moderations_launched.remove(guild_id) - async def start_moderations_service(self, guild_id, alert_channel_id=None): self.set_guild_moderated(guild_id) moderations_channel = await self.check_and_launch_moderations( @@ -169,18 +179,30 @@ class ModerationsService(discord.Cog, name="ModerationsService"): self.set_moderated_alert_channel(guild_id, moderations_channel.id) async def restart_moderations_service(self, ctx): - await ctx.respond(f"The moderations service is being restarted...", ephemeral=True, delete_after=30) + await ctx.respond( + f"The moderations service is being restarted...", + ephemeral=True, + delete_after=30, + ) await self.stop_moderations_service(ctx.guild_id) - await ctx.send_followup("The moderations service was stopped..", ephemeral=True, delete_after=30) - await self.start_moderations_service(ctx.guild_id, self.get_moderated_alert_channel(ctx.guild_id)) - await ctx.send_followup("The moderations service was restarted successfully.", ephemeral=True, delete_after=30) + await ctx.send_followup( + "The moderations service was stopped..", ephemeral=True, delete_after=30 + ) + await self.start_moderations_service( + ctx.guild_id, self.get_moderated_alert_channel(ctx.guild_id) + ) + await ctx.send_followup( + "The moderations service was restarted successfully.", + ephemeral=True, + delete_after=30, + ) - async def build_moderation_settings_embed(self,type, mod_set): + async def build_moderation_settings_embed(self, type, mod_set): embed = discord.Embed( title="Moderation Settings", description="The moderation settings for this guild for the type: " + type, - color=discord.Color.yellow() if type=="warn" else discord.Color.red(), + color=discord.Color.yellow() if type == "warn" else discord.Color.red(), ) # Add each key_value pair in the mod_set to the embed, make them fairly small @@ -189,19 +211,45 @@ class ModerationsService(discord.Cog, name="ModerationsService"): return embed - - async def config_command(self, ctx: discord.ApplicationContext, config_type: str, hate, hate_threatening, self_harm, sexual, sexual_minors, violence, violence_graphic): + async def config_command( + self, + ctx: discord.ApplicationContext, + config_type: str, + hate, + hate_threatening, + self_harm, + sexual, + sexual_minors, + violence, + violence_graphic, + ): config_type = config_type.lower().strip() if config_type not in ["warn", "delete"]: await ctx.respond("Invalid config type, please use `warn` or `delete`") return - all_args = [hate, hate_threatening, self_harm, sexual, sexual_minors, violence, violence_graphic] + all_args = [ + hate, + hate_threatening, + self_harm, + sexual, + sexual_minors, + violence, + violence_graphic, + ] await ctx.defer(ephemeral=True) # Case for printing the current config if not any(all_args): - await ctx.respond(ephemeral=True, embed=await self.build_moderation_settings_embed(config_type, self.get_or_set_warn_set(ctx.guild_id) if config_type=="warn" else self.get_or_set_delete_set(ctx.guild_id))) + await ctx.respond( + ephemeral=True, + embed=await self.build_moderation_settings_embed( + config_type, + self.get_or_set_warn_set(ctx.guild_id) + if config_type == "warn" + else self.get_or_set_delete_set(ctx.guild_id), + ), + ) return if config_type == "warn": @@ -225,18 +273,20 @@ class ModerationsService(discord.Cog, name="ModerationsService"): new_delete_set = ThresholdSet( hate if hate else delete_set["hate"], - hate_threatening if hate_threatening else delete_set["hate/threatening"], + hate_threatening + if hate_threatening + else delete_set["hate/threatening"], self_harm if self_harm else delete_set["self-harm"], sexual if sexual else delete_set["sexual"], sexual_minors if sexual_minors else delete_set["sexual/minors"], violence if violence else delete_set["violence"], - violence_graphic if violence_graphic else delete_set["violence/graphic"], + violence_graphic + if violence_graphic + else delete_set["violence/graphic"], ) self.set_delete_set(ctx.guild_id, new_delete_set) await self.restart_moderations_service(ctx) - - async def moderations_test_command( self, ctx: discord.ApplicationContext, prompt: str ): diff --git a/cogs/text_service_cog.py b/cogs/text_service_cog.py index b882923..2668185 100644 --- a/cogs/text_service_cog.py +++ b/cogs/text_service_cog.py @@ -530,7 +530,8 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): # Moderations service is done here. if ( - hasattr(message, "guild") and message.guild.id in Moderation.moderation_queues + hasattr(message, "guild") + and message.guild.id in Moderation.moderation_queues and Moderation.moderation_queues[message.guild.id] is not None ): # Create a timestamp that is 0.5 seconds from now diff --git a/services/moderations_service.py b/services/moderations_service.py index ab6e163..11dff74 100644 --- a/services/moderations_service.py +++ b/services/moderations_service.py @@ -40,6 +40,7 @@ class ThresholdSet: v_t, vg_t, ] + # The string representation is just the keys alongside the threshold values def __str__(self): @@ -150,7 +151,12 @@ class Moderation: # This function will be called by the bot to process the message queue @staticmethod async def process_moderation_queue( - moderation_queue, PROCESS_WAIT_TIME, EMPTY_WAIT_TIME, moderations_alert_channel, warn_set, delete_set + moderation_queue, + PROCESS_WAIT_TIME, + EMPTY_WAIT_TIME, + moderations_alert_channel, + warn_set, + delete_set, ): print("The warn and delete sets are ", warn_set, delete_set) while True: