Compare commits
2 commits
1ff7f35785
...
aca705d073
Author | SHA1 | Date | |
---|---|---|---|
aca705d073 | |||
27c12c6307 |
1 changed files with 76 additions and 3 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})"
|
||||
|
@ -200,13 +201,28 @@ class Moderation(commands.Cog):
|
|||
embed_duration = f" for {humanize.precisedelta(duration)}"
|
||||
else:
|
||||
embed_duration = ""
|
||||
embed = discord.Embed(title=str.title(moderation_type), description=f"You have been {moderation_type}{embed_duration} in {guild_name}.", color=await self.bot.get_embed_color(None), timestamp=datetime.now())
|
||||
if moderation_type == "note":
|
||||
embed_desc = "recieved a"
|
||||
else:
|
||||
embed_desc = "been"
|
||||
embed = discord.Embed(title=str.title(moderation_type), description=f"You have {embed_desc} {moderation_type}{embed_duration} in {guild_name}.", color=await self.bot.get_embed_color(None), timestamp=datetime.now())
|
||||
embed.add_field(name='Reason', value=f"`{reason}`")
|
||||
embed.set_author(name=guild.name, icon_url=guild.icon.url)
|
||||
embed.set_footer(text=f"Case #{await self.get_next_case_number(guild.id)}", icon_url="https://cdn.discordapp.com/attachments/1070822161389994054/1159469476773904414/arrow-right-circle-icon-512x512-2p1e2aaw.png?ex=65312319&is=651eae19&hm=3cebdd28e805c13a79ec48ef87c32ca532ffa6b9ede2e48d0cf8e5e81f3a6818&")
|
||||
return embed
|
||||
raise(TypeError("'type' argument is invalid!"))
|
||||
|
||||
@app_commands.command(name="note")
|
||||
async def note(self, interaction: discord.Interaction, target: discord.Member, reason: str):
|
||||
"""Add a note to a user."""
|
||||
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
||||
try:
|
||||
embed = await self.embed_factory('message', interaction.guild, reason, 'note', await interaction.original_response())
|
||||
await target.send(embed=embed)
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 'NULL', reason)
|
||||
|
||||
@app_commands.command(name="warn")
|
||||
async def warn(self, interaction: discord.Interaction, target: discord.Member, reason: str):
|
||||
"""Warn a user."""
|
||||
|
@ -250,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:
|
||||
|
@ -272,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