Add rolegiver cleanup, noinvite setting
This commit is contained in:
parent
a79c15ac76
commit
042094be15
3 changed files with 45 additions and 22 deletions
|
@ -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."""
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue