diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/rolegiver.py index 8f8f604..3f0db65 100644 --- a/jarvis/cogs/rolegiver.py +++ b/jarvis/cogs/rolegiver.py @@ -72,13 +72,6 @@ class RolegiverCog(commands.Cog): await ctx.send(embed=embed) - guild_roles = await ctx.guild.fetch_roles() - guild_role_ids = [x.id for x in guild_roles] - for role_id in setting.value: - if role_id not in guild_role_ids: - setting.value.remove(role_id) - setting.save() - @cog_ext.cog_subcommand( base="rolegiver", name="remove", @@ -137,13 +130,6 @@ class RolegiverCog(commands.Cog): await ctx.send(embed=embed) - guild_roles = await ctx.guild.fetch_roles() - guild_role_ids = [x.id for x in guild_roles] - for role_id in setting.value: - if role_id not in guild_role_ids: - setting.value.remove(role_id) - setting.save() - @cog_ext.cog_subcommand( base="rolegiver", name="list", @@ -182,12 +168,6 @@ class RolegiverCog(commands.Cog): embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}") await ctx.send(embed=embed) - guild_roles = await ctx.guild.fetch_roles() - guild_role_ids = [x.id for x in guild_roles] - for role_id in setting.value: - if role_id not in guild_role_ids: - setting.value.remove(role_id) - setting.save() @cog_ext.cog_subcommand( base="role", @@ -299,6 +279,25 @@ class RolegiverCog(commands.Cog): await ctx.send(embed=embed) + @cog_ext.cog_subcommand( + base="rolegiver", + name="cleanup", + description="Cleanup rolegiver roles", + ) + @admin_or_permissions(manage_guild=True) + async def _rolegiver_cleanup(self, ctx: SlashContext) -> None: + setting = Setting.objects(guild_id=ctx.guild.id, setting="rolegiver").first() + if not setting or not setting.value: + await ctx.send("Rolegiver has no roles", hidden=True) + guild_roles = await ctx.guild.fetch_roles() + guild_role_ids = [x.id for x in guild_roles] + for role_id in setting.value: + if role_id not in guild_role_ids: + setting.value.remove(role_id) + setting.save() + + await ctx.send("Rolegiver cleanup finished") + def setup(bot: commands.Bot) -> None: """Add RolegiverCog to J.A.R.V.I.S.""" diff --git a/jarvis/cogs/settings.py b/jarvis/cogs/settings.py index 3b45533..622a1d7 100644 --- a/jarvis/cogs/settings.py +++ b/jarvis/cogs/settings.py @@ -147,7 +147,7 @@ class SettingsCog(commands.Cog): options=[ create_option( name="role", - description="Unverified role role", + description="Unverified role", option_type=8, required=True, ) @@ -159,6 +159,26 @@ class SettingsCog(commands.Cog): self.update_settings("unverified", role.id, ctx.guild.id) await ctx.send(f"Settings applied. New unverified role is `{role.name}`") + @cog_ext.cog_subcommand( + base="settings", + subcommand_group="set", + name="noinvite", + description="Set if invite deletion should happen", + options=[ + create_option( + name="active", + description="Active?", + option_type=4, + required=True, + ) + ], + ) + @admin_or_permissions(manage_guild=True) + async def _set_invitedel(self, ctx: SlashContext, active: int) -> None: + await ctx.defer() + self.update_settings("noinvite", bool(active), ctx.guild.id) + await ctx.send(f"Settings applied. Automatic invite active: {bool(active)}") + @cog_ext.cog_subcommand( base="settings", subcommand_group="unset", diff --git a/jarvis/events/message.py b/jarvis/events/message.py index acefe2d..2b8a5b6 100644 --- a/jarvis/events/message.py +++ b/jarvis/events/message.py @@ -50,6 +50,10 @@ class MessageEventHandler(object): ) content = re.sub(r"\s+", "", message.content) match = invites.search(content) + setting = Setting.objects(guild_id=message.guild.id, setting="noinvite").first() + if not setting: + setting = Setting(guild_id=message.guild.id, setting="noinvite", value=True) + setting.save() if match: guild_invites = await message.guild.invites() allowed = [x.code for x in guild_invites] + [ @@ -57,7 +61,7 @@ class MessageEventHandler(object): "VtgZntXcnZ", "gPfYGbvTCE", ] - if match.group(1) not in allowed: + if match.group(1) not in allowed and setting.value: await message.delete() _ = Warning( active=True,