diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 7c4cddc..dea4964 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -159,6 +159,11 @@ async def on_message(message: Message): text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}" ) await message.channel.send(embed=embed) + autopurge = db.jarvis.autopurge.find_one( + {"guild": message.guild.id, "channel": message.channel.id} + ) + if autopurge: + await message.delete(delay=autopurge["delay"]) await jarvis.process_commands(message) diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index ee4a1e2..4aa34d5 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -890,6 +890,7 @@ class AdminCog(commands.Cog): ) ], ) + @commands.has_permissions(administrator=True) async def _roleping_block(self, ctx: SlashContext, role: Role): roles = self.db.jarvis.settings.find_one( {"guild": ctx.guild.id, "setting": "roleping"} @@ -922,6 +923,7 @@ class AdminCog(commands.Cog): ) ], ) + @commands.has_permissions(administrator=True) async def _roleping_allow(self, ctx: SlashContext, role: Role): roles = self.db.jarvis.settings.find_one( {"guild": ctx.guild.id, "setting": "roleping"} @@ -941,6 +943,111 @@ class AdminCog(commands.Cog): ) await ctx.send(f"Role `{role.name}` removed blocklist.") + @cog_ext.cog_subcommand( + base="autopurge", + name="add", + description="Automatically purge messages after x seconds", + guild_ids=[418094694325813248, 578757004059738142, 862402786116763668], + options=[ + create_option( + name="channel", + description="Channel to autopurge", + option_type=7, + required=True, + ), + create_option( + name="delay", + description="Seconds to keep message before purge, default 30", + option_type=4, + required=False, + ), + ], + ) + @admin_or_permissions(manage_messages=True) + async def _autopurge_add( + self, ctx: SlashContext, channel: TextChannel, delay: int = 30 + ): + autopurge = self.db.jarvis.autopurge.find( + {"guild": ctx.guild.id, "channel": channel.id} + ) + if autopurge: + await ctx.send("Autopurge already exists.") + return + autopurge = { + "guild": ctx.guild.id, + "channel": channel.id, + "admin": ctx.author.id, + "delay": delay, + "time": datetime.utcnow(), + } + self.db.jarvis.autopurge.insert_one(autopurge) + await ctx.send( + f"Autopurge set up on {channel.mention}, " + + f"delay is {delay} seconds" + ) + + @cog_ext.cog_subcommand( + base="autopurge", + name="remove", + description="Remove an autopurge", + guild_ids=[418094694325813248, 578757004059738142, 862402786116763668], + options=[ + create_option( + name="channel", + description="Channel to remove from autopurge", + option_type=7, + required=True, + ), + ], + ) + @admin_or_permissions(manage_messages=True) + async def _autopurge_remove(self, ctx: SlashContext, channel: TextChannel): + autopurge = self.db.jarvis.autopurge.find( + {"guild": ctx.guild.id, "channel": channel.id} + ) + if not autopurge: + await ctx.send("Autopurge does not exist.") + return + self.db.jarvis.autopurge.delete_one({"_id": autopurge["_id"]}) + await ctx.send(f"Autopurge removed from {channel.mention}.") + + @cog_ext.cog_subcommand( + base="autopurge", + name="update", + description="Update autopurge on a channel", + guild_ids=[418094694325813248, 578757004059738142, 862402786116763668], + options=[ + create_option( + name="channel", + description="Channel to update", + option_type=7, + required=True, + ), + create_option( + name="delay", + description="New time to save", + option_type=4, + required=True, + ), + ], + ) + @admin_or_permissions(manage_messages=True) + async def _autopurge_update( + self, ctx: SlashContext, channel: TextChannel, delay: int + ): + autopurge = self.db.jarvis.autopurge.find( + {"guild": ctx.guild.id, "channel": channel.id} + ) + if not autopurge: + await ctx.send("Autopurge does not exist.") + return + self.db.jarvis.autopurge.update_one( + {"_id": autopurge["_id"]}, {"$set": {"delay": delay}} + ) + await ctx.send( + f"Autopurge delay updated to {delay} seconds on {channel.mention}." + ) + def setup(bot): bot.add_cog(AdminCog(bot))