Fix error in bans
This commit is contained in:
parent
11fdd09d01
commit
4159cbdfbd
2 changed files with 115 additions and 68 deletions
|
@ -31,6 +31,7 @@ class BanCog(CacheCog):
|
||||||
duration: int,
|
duration: int,
|
||||||
active: bool,
|
active: bool,
|
||||||
fields: list,
|
fields: list,
|
||||||
|
mtype: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Apply a Discord ban."""
|
"""Apply a Discord ban."""
|
||||||
await ctx.guild.ban(user, reason=reason)
|
await ctx.guild.ban(user, reason=reason)
|
||||||
|
@ -41,7 +42,7 @@ class BanCog(CacheCog):
|
||||||
reason=reason,
|
reason=reason,
|
||||||
admin=ctx.author.id,
|
admin=ctx.author.id,
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
type=type,
|
type=mtype,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
active=active,
|
active=active,
|
||||||
).save()
|
).save()
|
||||||
|
@ -103,14 +104,14 @@ class BanCog(CacheCog):
|
||||||
option_type=3,
|
option_type=3,
|
||||||
),
|
),
|
||||||
create_option(
|
create_option(
|
||||||
name="type",
|
name="btype",
|
||||||
description="Ban type",
|
description="Ban type",
|
||||||
option_type=3,
|
option_type=3,
|
||||||
required=False,
|
required=False,
|
||||||
choices=[
|
choices=[
|
||||||
create_choice(value="perm", name="Permanent"),
|
create_choice(value=0, name="Permanent"),
|
||||||
create_choice(value="temp", name="Temporary"),
|
create_choice(value=1, name="Temporary"),
|
||||||
create_choice(value="soft", name="Soft"),
|
create_choice(value=2, name="Soft"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
create_option(
|
create_option(
|
||||||
|
@ -127,19 +128,25 @@ class BanCog(CacheCog):
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
user: User = None,
|
user: User = None,
|
||||||
reason: str = None,
|
reason: str = None,
|
||||||
type: str = "perm",
|
btype: int = 0,
|
||||||
duration: int = 4,
|
duration: int = 4,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
if btype == 0:
|
||||||
|
btype = "perm"
|
||||||
|
elif btype == 1:
|
||||||
|
btype = "temp"
|
||||||
|
else:
|
||||||
|
btype = "soft"
|
||||||
if not user or user == ctx.author:
|
if not user or user == ctx.author:
|
||||||
await ctx.send("You cannot ban yourself.", hidden=True)
|
await ctx.send("You cannot ban yourself.", hidden=True)
|
||||||
return
|
return
|
||||||
if user == self.bot.user:
|
if user == self.bot.user:
|
||||||
await ctx.send("I'm afraid I can't let you do that", hidden=True)
|
await ctx.send("I'm afraid I can't let you do that", hidden=True)
|
||||||
return
|
return
|
||||||
if type == "temp" and duration < 0:
|
if btype == "temp" and duration < 0:
|
||||||
await ctx.send("You cannot set a temp ban to < 0 hours.", hidden=True)
|
await ctx.send("You cannot set a temp ban to < 0 hours.", hidden=True)
|
||||||
return
|
return
|
||||||
elif type == "temp" and duration > 744:
|
elif btype == "temp" and duration > 744:
|
||||||
await ctx.send("You cannot set a temp ban to > 1 month", hidden=True)
|
await ctx.send("You cannot set a temp ban to > 1 month", hidden=True)
|
||||||
return
|
return
|
||||||
if len(reason) > 100:
|
if len(reason) > 100:
|
||||||
|
@ -150,7 +157,7 @@ class BanCog(CacheCog):
|
||||||
|
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
||||||
mtype = type
|
mtype = btype
|
||||||
if mtype == "perm":
|
if mtype == "perm":
|
||||||
mtype = "perma"
|
mtype = "perma"
|
||||||
|
|
||||||
|
@ -190,13 +197,13 @@ class BanCog(CacheCog):
|
||||||
await ctx.guild.unban(user, reason="Ban was softban")
|
await ctx.guild.unban(user, reason="Ban was softban")
|
||||||
|
|
||||||
fields.append(Field(name="DM Sent?", value=str(not send_failed)))
|
fields.append(Field(name="DM Sent?", value=str(not send_failed)))
|
||||||
if type != "temp":
|
if btype != "temp":
|
||||||
duration = None
|
duration = None
|
||||||
active = True
|
active = True
|
||||||
if type == "soft":
|
if btype == "soft":
|
||||||
active = False
|
active = False
|
||||||
|
|
||||||
await self.discord_apply_ban(ctx, reason, user, duration, active, fields)
|
await self.discord_apply_ban(ctx, reason, user, duration, active, fields, mtype)
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
@cog_ext.cog_slash(
|
||||||
name="unban",
|
name="unban",
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
"""J.A.R.V.I.S. Role Giver Cog."""
|
"""J.A.R.V.I.S. Role Giver Cog."""
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from discord import Role
|
from discord import Role
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord_slash import SlashContext, cog_ext
|
from discord_slash import SlashContext, cog_ext
|
||||||
from discord_slash.utils.manage_commands import create_option
|
from discord_slash.utils.manage_commands import create_option
|
||||||
|
from discord_slash.utils.manage_components import (
|
||||||
|
create_actionrow,
|
||||||
|
create_select,
|
||||||
|
create_select_option,
|
||||||
|
wait_for_component,
|
||||||
|
)
|
||||||
|
|
||||||
from jarvis.db.models import Rolegiver
|
from jarvis.db.models import Rolegiver
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
|
@ -39,6 +47,10 @@ class RolegiverCog(commands.Cog):
|
||||||
if not setting:
|
if not setting:
|
||||||
setting = Rolegiver(guild=ctx.guild.id, roles=[])
|
setting = Rolegiver(guild=ctx.guild.id, roles=[])
|
||||||
|
|
||||||
|
if len(setting.roles) >= 20:
|
||||||
|
await ctx.send("You can only have 20 roles in the rolegiver", hidden=True)
|
||||||
|
return
|
||||||
|
|
||||||
setting.roles.append(role.id)
|
setting.roles.append(role.id)
|
||||||
setting.save()
|
setting.save()
|
||||||
|
|
||||||
|
@ -79,59 +91,84 @@ class RolegiverCog(commands.Cog):
|
||||||
base="rolegiver",
|
base="rolegiver",
|
||||||
name="remove",
|
name="remove",
|
||||||
description="Remove a role from rolegiver",
|
description="Remove a role from rolegiver",
|
||||||
options=[
|
|
||||||
create_option(
|
|
||||||
name="role",
|
|
||||||
description="Role to remove",
|
|
||||||
option_type=8,
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
@admin_or_permissions(manage_guild=True)
|
@admin_or_permissions(manage_guild=True)
|
||||||
async def _rolegiver_remove(self, ctx: SlashContext, role: Role) -> None:
|
async def _rolegiver_remove(self, ctx: SlashContext) -> None:
|
||||||
setting = Rolegiver.objects(guild=ctx.guild.id).first()
|
setting = Rolegiver.objects(guild=ctx.guild.id).first()
|
||||||
if not setting or (setting and not setting.roles):
|
if not setting or (setting and not setting.roles):
|
||||||
await ctx.send("Rolegiver has no roles", hidden=True)
|
await ctx.send("Rolegiver has no roles", hidden=True)
|
||||||
return
|
return
|
||||||
elif role.id not in setting.roles:
|
|
||||||
await ctx.send("Role not in rolegiver", hidden=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
setting.roles.remove(role.id)
|
options = []
|
||||||
setting.save()
|
for role in setting.roles:
|
||||||
|
role: Role = ctx.guild.get_role(role)
|
||||||
|
option = create_select_option(label=role.name, value=str(role.id))
|
||||||
|
options.append(option)
|
||||||
|
|
||||||
roles = []
|
select = create_select(
|
||||||
for role_id in setting.roles:
|
options=options,
|
||||||
e_role = ctx.guild.get_role(role_id)
|
custom_id="to_delete",
|
||||||
if not e_role:
|
placeholder="Select roles to remove",
|
||||||
continue
|
min_values=1,
|
||||||
roles.append(e_role)
|
max_values=len(options),
|
||||||
|
|
||||||
if roles:
|
|
||||||
roles.sort(key=lambda x: -x.position)
|
|
||||||
|
|
||||||
value = "\n".join([r.mention for r in roles]) if roles else "None"
|
|
||||||
fields = [
|
|
||||||
Field(name="Removed Role", value=f"{role.mention}"),
|
|
||||||
Field(name="Remaining Role(s)", value=value),
|
|
||||||
]
|
|
||||||
|
|
||||||
embed = build_embed(
|
|
||||||
title="Rolegiver Updated",
|
|
||||||
description="Role removed from rolegiver",
|
|
||||||
fields=fields,
|
|
||||||
)
|
)
|
||||||
|
components = [create_actionrow(select)]
|
||||||
|
|
||||||
embed.set_thumbnail(url=ctx.guild.icon_url)
|
message = await ctx.send(content="\u200b", components=components)
|
||||||
embed.set_author(
|
try:
|
||||||
name=ctx.author.nick if ctx.author.nick else ctx.author.name,
|
context = await wait_for_component(
|
||||||
icon_url=ctx.author.avatar_url,
|
self.bot,
|
||||||
)
|
check=lambda x: ctx.author.id == x.author.id,
|
||||||
|
message=message,
|
||||||
|
timeout=60 * 1,
|
||||||
|
)
|
||||||
|
for to_delete in context.selected_options:
|
||||||
|
setting.roles.remove(int(to_delete))
|
||||||
|
setting.save()
|
||||||
|
for row in components:
|
||||||
|
for component in row["components"]:
|
||||||
|
component["disabled"] = True
|
||||||
|
|
||||||
embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}")
|
roles = []
|
||||||
|
for role_id in setting.roles:
|
||||||
|
e_role = ctx.guild.get_role(role_id)
|
||||||
|
if not e_role:
|
||||||
|
continue
|
||||||
|
roles.append(e_role)
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
if roles:
|
||||||
|
roles.sort(key=lambda x: -x.position)
|
||||||
|
|
||||||
|
value = "\n".join([r.mention for r in roles]) if roles else "None"
|
||||||
|
fields = [
|
||||||
|
Field(name="Removed Role", value=f"{role.mention}"),
|
||||||
|
Field(name="Remaining Role(s)", value=value),
|
||||||
|
]
|
||||||
|
|
||||||
|
embed = build_embed(
|
||||||
|
title="Rolegiver Updated",
|
||||||
|
description="Role removed from rolegiver",
|
||||||
|
fields=fields,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
embed.set_author(
|
||||||
|
name=ctx.author.nick if ctx.author.nick else ctx.author.name,
|
||||||
|
icon_url=ctx.author.avatar_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}")
|
||||||
|
|
||||||
|
await context.edit_origin(
|
||||||
|
content=f"Removed {len(context.selected_options)} role(s)",
|
||||||
|
embed=embed,
|
||||||
|
components=components,
|
||||||
|
)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
for row in components:
|
||||||
|
for component in row["components"]:
|
||||||
|
component["disabled"] = True
|
||||||
|
await message.edit(components=components)
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="rolegiver",
|
base="rolegiver",
|
||||||
|
@ -176,27 +213,30 @@ class RolegiverCog(commands.Cog):
|
||||||
base="role",
|
base="role",
|
||||||
name="get",
|
name="get",
|
||||||
description="Get a role from rolegiver",
|
description="Get a role from rolegiver",
|
||||||
options=[
|
|
||||||
create_option(
|
|
||||||
name="role",
|
|
||||||
description="Role to add",
|
|
||||||
option_type=8,
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
@commands.cooldown(1, 10, commands.BucketType.user)
|
@commands.cooldown(1, 10, commands.BucketType.user)
|
||||||
async def _role_get(self, ctx: SlashContext, role: Role) -> None:
|
async def _role_get(self, ctx: SlashContext) -> None:
|
||||||
setting = Rolegiver.objects(guild=ctx.guild.id).first()
|
setting = Rolegiver.objects(guild=ctx.guild.id).first()
|
||||||
if not setting or (setting and not setting.roles):
|
if not setting or (setting and not setting.roles):
|
||||||
await ctx.send("Rolegiver has no roles", hidden=True)
|
await ctx.send("Rolegiver has no roles", hidden=True)
|
||||||
return
|
return
|
||||||
elif role.id not in setting.roles:
|
|
||||||
await ctx.send("Role not in rolegiver", hidden=True)
|
options = []
|
||||||
return
|
for role in setting.roles:
|
||||||
elif role in ctx.author.roles:
|
role: Role = ctx.guild.get_role(role)
|
||||||
await ctx.send("You already have that role", hidden=True)
|
option = create_select_option(label=role.name, value=str(role.id))
|
||||||
return
|
options.append(option)
|
||||||
|
|
||||||
|
select = create_select(
|
||||||
|
options=options,
|
||||||
|
custom_id="to_delete",
|
||||||
|
placeholder="Select roles to remove",
|
||||||
|
min_values=1,
|
||||||
|
max_values=len(options),
|
||||||
|
)
|
||||||
|
components = [create_actionrow(select)]
|
||||||
|
|
||||||
|
_ = await ctx.send(content="\u200b", components=components)
|
||||||
|
|
||||||
await ctx.author.add_roles(role, reason="Rolegiver")
|
await ctx.author.add_roles(role, reason="Rolegiver")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue