Update ban
This commit is contained in:
parent
2a84d50c65
commit
fa33a79de3
1 changed files with 10 additions and 23 deletions
|
@ -1,8 +1,7 @@
|
||||||
"""J.A.R.V.I.S. BanCog."""
|
"""J.A.R.V.I.S. BanCog."""
|
||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
from dis_snek import InteractionContext, Permissions, Snake
|
from dis_snek import InteractionContext, Permissions, Scale
|
||||||
from dis_snek.client.utils.misc_utils import find, find_all
|
from dis_snek.client.utils.misc_utils import find, find_all
|
||||||
from dis_snek.ext.paginators import Paginator
|
from dis_snek.ext.paginators import Paginator
|
||||||
from dis_snek.models.discord.embed import EmbedField
|
from dis_snek.models.discord.embed import EmbedField
|
||||||
|
@ -18,16 +17,12 @@ from jarvis_core.db import q
|
||||||
from jarvis_core.db.models import Ban, Unban
|
from jarvis_core.db.models import Ban, Unban
|
||||||
|
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.cachecog import CacheCog
|
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class BanCog(CacheCog):
|
class BanCog(Scale):
|
||||||
"""J.A.R.V.I.S. BanCog."""
|
"""J.A.R.V.I.S. BanCog."""
|
||||||
|
|
||||||
def __init__(self, bot: Snake):
|
|
||||||
super().__init__(bot)
|
|
||||||
|
|
||||||
async def discord_apply_ban(
|
async def discord_apply_ban(
|
||||||
self,
|
self,
|
||||||
ctx: InteractionContext,
|
ctx: InteractionContext,
|
||||||
|
@ -40,7 +35,7 @@ class BanCog(CacheCog):
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Apply a Discord ban."""
|
"""Apply a Discord ban."""
|
||||||
await ctx.guild.ban(user, reason=reason)
|
await ctx.guild.ban(user, reason=reason)
|
||||||
_ = Ban(
|
b = Ban(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
username=user.username,
|
username=user.username,
|
||||||
discrim=user.discriminator,
|
discrim=user.discriminator,
|
||||||
|
@ -50,7 +45,8 @@ class BanCog(CacheCog):
|
||||||
type=mtype,
|
type=mtype,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
active=active,
|
active=active,
|
||||||
).save()
|
)
|
||||||
|
await b.commit()
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Banned",
|
title="User Banned",
|
||||||
|
@ -70,14 +66,15 @@ class BanCog(CacheCog):
|
||||||
async def discord_apply_unban(self, ctx: InteractionContext, user: User, reason: str) -> None:
|
async def discord_apply_unban(self, ctx: InteractionContext, user: User, reason: str) -> None:
|
||||||
"""Apply a Discord unban."""
|
"""Apply a Discord unban."""
|
||||||
await ctx.guild.unban(user, reason=reason)
|
await ctx.guild.unban(user, reason=reason)
|
||||||
_ = Unban(
|
u = Unban(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
username=user.username,
|
username=user.username,
|
||||||
discrim=user.discriminator,
|
discrim=user.discriminator,
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
admin=ctx.author.id,
|
admin=ctx.author.id,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
).save()
|
)
|
||||||
|
await u.commit()
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Unbanned",
|
title="User Unbanned",
|
||||||
|
@ -319,10 +316,10 @@ class BanCog(CacheCog):
|
||||||
search["active"] = True
|
search["active"] = True
|
||||||
if btype > 0:
|
if btype > 0:
|
||||||
search["type"] = types[btype]
|
search["type"] = types[btype]
|
||||||
bans = Ban.objects(**search).order_by("-created_at")
|
bans = Ban.find(search).sort([("created_at", -1)])
|
||||||
db_bans = []
|
db_bans = []
|
||||||
fields = []
|
fields = []
|
||||||
for ban in bans:
|
async for ban in bans:
|
||||||
if not ban.username:
|
if not ban.username:
|
||||||
user = await self.bot.fetch_user(ban.user)
|
user = await self.bot.fetch_user(ban.user)
|
||||||
ban.username = user.username if user else "[deleted user]"
|
ban.username = user.username if user else "[deleted user]"
|
||||||
|
@ -379,14 +376,4 @@ class BanCog(CacheCog):
|
||||||
|
|
||||||
paginator = Paginator.create_from_embeds(self.bot, *pages, timeout=300)
|
paginator = Paginator.create_from_embeds(self.bot, *pages, timeout=300)
|
||||||
|
|
||||||
self.cache[hash(paginator)] = {
|
|
||||||
"guild": ctx.guild.id,
|
|
||||||
"user": ctx.author.id,
|
|
||||||
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
|
||||||
"command": ctx.subcommand_name,
|
|
||||||
"btype": btype,
|
|
||||||
"active": active,
|
|
||||||
"paginator": paginator,
|
|
||||||
}
|
|
||||||
|
|
||||||
await paginator.send(ctx)
|
await paginator.send(ctx)
|
||||||
|
|
Loading…
Add table
Reference in a new issue