feat(moderation): added ban and unban commands
All checks were successful
Pylint / Pylint (push) Successful in 1m12s
All checks were successful
Pylint / Pylint (push) Successful in 1m12s
This commit is contained in:
parent
27c12c6307
commit
aca705d073
1 changed files with 60 additions and 2 deletions
|
@ -6,6 +6,7 @@ import humanize
|
|||
import mysql.connector
|
||||
from pytimeparse2 import disable_dateutil, parse
|
||||
from redbot.core import app_commands, checks, Config, commands
|
||||
from redbot.core.app_commands import Choice
|
||||
|
||||
|
||||
class Moderation(commands.Cog):
|
||||
|
@ -192,7 +193,7 @@ class Moderation(commands.Cog):
|
|||
- 'log' - WIP
|
||||
- 'case' - WIP"""
|
||||
if embed_type == 'message':
|
||||
if moderation_type in ["kicked", "banned", "unbanned"]:
|
||||
if moderation_type in ["kicked", "banned", "tempbanned", "unbanned"]:
|
||||
guild_name = guild.name
|
||||
else:
|
||||
guild_name = f"[{guild.name}]({response.jump_url})"
|
||||
|
@ -265,7 +266,7 @@ class Moderation(commands.Cog):
|
|||
if reason:
|
||||
await target.timeout(None, reason=f"Unmuted by {interaction.user.id} for: {reason}")
|
||||
else:
|
||||
await target.timeout(None)
|
||||
await target.timeout(None, reason=f"Unbanned by {interaction.user.id}")
|
||||
reason = "No reason given."
|
||||
await interaction.response.send_message(content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`")
|
||||
try:
|
||||
|
@ -287,6 +288,63 @@ class Moderation(commands.Cog):
|
|||
await target.kick(f"Kicked by {interaction.user.id} for: {reason}")
|
||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'KICK', target.id, 'NULL', reason)
|
||||
|
||||
@app_commands.command(name="ban")
|
||||
@app_commands.choices(answer=[
|
||||
Choice(name="None", value=0),
|
||||
Choice(name='1 Hour', value=3600),
|
||||
Choice(name='12 Hours', value=43200),
|
||||
Choice(name='1 Day', value=86400),
|
||||
Choice(name='3 Days', value=259200),
|
||||
Choice(name='7 Days', value=604800),
|
||||
])
|
||||
async def ban(self, interaction: discord.Interaction, target: discord.User, reason: str, duration: str = None, delete_messages: Choice[int] = 0):
|
||||
"""Ban a user."""
|
||||
try:
|
||||
await interaction.guild.fetch_ban(target.id)
|
||||
await interaction.response.send_message(content=f"{target.mention} is already banned!", ephemeral=True)
|
||||
return
|
||||
except discord.errors.NotFound:
|
||||
pass
|
||||
if duration:
|
||||
try:
|
||||
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Please provide a valid duration!", ephemeral=True)
|
||||
return
|
||||
await interaction.response.send_message(content=f"{target.mention} has been banned for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`")
|
||||
try:
|
||||
embed = await self.embed_factory('message', interaction.guild, reason, 'tempbanned', await interaction.original_response())
|
||||
await target.send(embed=embed)
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
await interaction.guild.ban(target.id, reason=f"Tempbanned by {interaction.user.id} for: {reason} (Duration: {parsed_time})", delete_message_seconds=delete_messages)
|
||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'TEMPBAN', target.id, parsed_time, reason)
|
||||
else:
|
||||
await interaction.response.send_message(content=f"{target.mention} has been banned!\n**Reason** - `{reason}`")
|
||||
try:
|
||||
embed = await self.embed_factory('message', interaction.guild, reason, 'banned', await interaction.original_response())
|
||||
await target.send(embed=embed)
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
await interaction.guild.ban(target.id, reason=f"Banned by {interaction.user.id} for: {reason}", delete_message_seconds=delete_messages)
|
||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'BAN', target.id, 'NULL', reason)
|
||||
|
||||
@app_commands.command(name="unban")
|
||||
async def unban(self, interaction: discord.Interaction, target: discord.User, reason: str = None):
|
||||
"""Unban a user."""
|
||||
if reason:
|
||||
await interaction.guild.unban(target.id, reason=f"Unbanned by {interaction.user.id} for: {reason}")
|
||||
else:
|
||||
await interaction.guild.unban(target.id, reason=f"Unbanned by {interaction.user.id}")
|
||||
reason = "No reason given."
|
||||
await interaction.response.send_message(content=f"{target.mention} has been unbanned!\n**Reason** - `{reason}`")
|
||||
try:
|
||||
embed = await self.embed_factory('message', interaction.guild, reason, 'unbanned', await interaction.original_response())
|
||||
await target.send(embed=embed)
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason)
|
||||
|
||||
@commands.group(autohelp=True)
|
||||
@checks.admin()
|
||||
async def moderationset(self, ctx: commands.Context):
|
||||
|
|
Loading…
Reference in a new issue