Migrate admin/kick, ref #91
This commit is contained in:
parent
7e4823a731
commit
12870bba17
1 changed files with 15 additions and 29 deletions
|
@ -1,42 +1,30 @@
|
||||||
"""J.A.R.V.I.S. KickCog."""
|
"""J.A.R.V.I.S. KickCog."""
|
||||||
from discord import User
|
from dis_snek import InteractionContext, Snek
|
||||||
from discord.ext.commands import Bot
|
from dis_snek.models.discord.embed import EmbedField
|
||||||
from discord_slash import SlashContext, cog_ext
|
from dis_snek.models.discord.user import User
|
||||||
from discord_slash.utils.manage_commands import create_option
|
from dis_snek.models.snek.application_commands import (
|
||||||
|
OptionTypes,
|
||||||
|
slash_command,
|
||||||
|
slash_option,
|
||||||
|
)
|
||||||
|
|
||||||
from jarvis.db.models import Kick
|
from jarvis.db.models import Kick
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
from jarvis.utils.field import Field
|
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class KickCog(CacheCog):
|
class KickCog(CacheCog):
|
||||||
"""J.A.R.V.I.S. KickCog."""
|
"""J.A.R.V.I.S. KickCog."""
|
||||||
|
|
||||||
def __init__(self, bot: Bot):
|
def __init__(self, bot: Snek):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
@slash_command(name="kick", description="Kick a user")
|
||||||
name="kick",
|
@slash_option(name="user", description="User to kick", option_type=OptionTypes.USER, required=True)
|
||||||
description="Kick a user",
|
@slash_option(name="reason", description="Kick reason", option_type=OptionTypes.STRING, required=True)
|
||||||
options=[
|
|
||||||
create_option(
|
|
||||||
name="user",
|
|
||||||
description="User to kick",
|
|
||||||
option_type=6,
|
|
||||||
required=True,
|
|
||||||
),
|
|
||||||
create_option(
|
|
||||||
name="reason",
|
|
||||||
description="Kick reason",
|
|
||||||
required=False,
|
|
||||||
option_type=3,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
@admin_or_permissions(kick_members=True)
|
@admin_or_permissions(kick_members=True)
|
||||||
async def _kick(self, ctx: SlashContext, user: User, reason: str = None) -> None:
|
async def _kick(self, ctx: InteractionContext, user: User, reason: str) -> None:
|
||||||
if not user or user == ctx.author:
|
if not user or user == ctx.author:
|
||||||
await ctx.send("You cannot kick yourself.", hidden=True)
|
await ctx.send("You cannot kick yourself.", hidden=True)
|
||||||
return
|
return
|
||||||
|
@ -46,8 +34,6 @@ class KickCog(CacheCog):
|
||||||
if len(reason) > 100:
|
if len(reason) > 100:
|
||||||
await ctx.send("Reason must be < 100 characters", hidden=True)
|
await ctx.send("Reason must be < 100 characters", hidden=True)
|
||||||
return
|
return
|
||||||
if not reason:
|
|
||||||
reason = "Mr. Stark is displeased with your presence. Please leave."
|
|
||||||
guild_name = ctx.guild.name
|
guild_name = ctx.guild.name
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title=f"You have been kicked from {guild_name}",
|
title=f"You have been kicked from {guild_name}",
|
||||||
|
@ -56,7 +42,7 @@ class KickCog(CacheCog):
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name=ctx.author.name + "#" + ctx.author.discriminator,
|
name=ctx.author.username + "#" + ctx.author.discriminator,
|
||||||
icon_url=ctx.author.avatar_url,
|
icon_url=ctx.author.avatar_url,
|
||||||
)
|
)
|
||||||
embed.set_thumbnail(url=ctx.guild.icon_url)
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
@ -68,7 +54,7 @@ class KickCog(CacheCog):
|
||||||
send_failed = True
|
send_failed = True
|
||||||
await ctx.guild.kick(user, reason=reason)
|
await ctx.guild.kick(user, reason=reason)
|
||||||
|
|
||||||
fields = [Field(name="DM Sent?", value=str(not send_failed))]
|
fields = [EmbedField(name="DM Sent?", value=str(not send_failed))]
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Kicked",
|
title="User Kicked",
|
||||||
description=f"Reason: {reason}",
|
description=f"Reason: {reason}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue