mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
refactor: moderation cogs && update embed styling
Removed template copyright headers from moderation cogs and database files. Improved embed styling and consistency in purge and warnings commands, including unified colors, author fields, and permission checks. Added a helper for sending embeds in warnings cog and replaced decorator-based permission checks with manual checks for better feedback. Updated comments in database files.
This commit is contained in:
@@ -1,11 +1,3 @@
|
|||||||
"""
|
|
||||||
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
|
|
||||||
Description:
|
|
||||||
🐍 A simple template to start to code your own and personalized Discord bot in Python
|
|
||||||
|
|
||||||
Version: 6.4.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@@ -33,9 +25,11 @@ class Purge(commands.Cog, name="purge"):
|
|||||||
await context.send("Deleting messages...")
|
await context.send("Deleting messages...")
|
||||||
purged_messages = await context.channel.purge(limit=amount + 1)
|
purged_messages = await context.channel.purge(limit=amount + 1)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
|
title="Purge",
|
||||||
description=f"**{context.author}** cleared **{len(purged_messages)-1}** messages!",
|
description=f"**{context.author}** cleared **{len(purged_messages)-1}** messages!",
|
||||||
color=0xBEBEFE,
|
color=0x7289DA,
|
||||||
)
|
)
|
||||||
|
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
"""
|
|
||||||
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
|
|
||||||
Description:
|
|
||||||
🐍 A simple template to start to code your own and personalized Discord bot in Python
|
|
||||||
|
|
||||||
Version: 6.4.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@@ -16,29 +8,45 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
def __init__(self, bot) -> None:
|
def __init__(self, bot) -> None:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if interaction.response.is_done():
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed)
|
||||||
|
|
||||||
@commands.hybrid_group(
|
@commands.hybrid_group(
|
||||||
name="warning",
|
name="warning",
|
||||||
description="Manage warnings of a user on a server.",
|
description="Manage warnings of a user on a server.",
|
||||||
)
|
)
|
||||||
@commands.has_permissions(manage_messages=True)
|
|
||||||
async def warning(self, context: Context) -> None:
|
async def warning(self, context: Context) -> None:
|
||||||
"""
|
"""
|
||||||
Manage warnings of a user on a server.
|
Manage warnings of a user on a server.
|
||||||
|
|
||||||
:param context: The hybrid command context.
|
:param context: The hybrid command context.
|
||||||
"""
|
"""
|
||||||
|
if not context.author.guild_permissions.manage_messages:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Missing Permissions!",
|
||||||
|
description="You are missing the permission(s) `manage_messages` to execute this command!",
|
||||||
|
color=0xE02B2B,
|
||||||
|
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
return await self.send_embed(context, embed, ephemeral=True)
|
||||||
|
|
||||||
if context.invoked_subcommand is None:
|
if context.invoked_subcommand is None:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
description="Please specify a subcommand.\n\n**Subcommands:**\n`add` - Add a warning to a user.\n`remove` - Remove a warning from a user.\n`list` - List all warnings of a user.",
|
description="Please specify a subcommand.\n\n**Subcommands:**\n`add` - Add a warning to a user.\n`remove` - Remove a warning from a user.\n`list` - List all warnings of a user.",
|
||||||
color=0xE02B2B,
|
color=0x7289DA,
|
||||||
)
|
)
|
||||||
await context.send(embed=embed)
|
await self.send_embed(context, embed)
|
||||||
|
|
||||||
@warning.command(
|
@warning.command(
|
||||||
name="add",
|
name="add",
|
||||||
description="Adds a warning to a user in the server.",
|
description="Adds a warning to a user in the server.",
|
||||||
)
|
)
|
||||||
@commands.has_permissions(manage_messages=True)
|
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
user="The user that should be warned.",
|
user="The user that should be warned.",
|
||||||
reason="The reason why the user should be warned.",
|
reason="The reason why the user should be warned.",
|
||||||
@@ -53,6 +61,13 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
:param user: The user that should be warned.
|
:param user: The user that should be warned.
|
||||||
:param reason: The reason for the warn. Default is "Not specified".
|
:param reason: The reason for the warn. Default is "Not specified".
|
||||||
"""
|
"""
|
||||||
|
if not context.author.guild_permissions.manage_messages:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Missing Permissions!",
|
||||||
|
description="You are missing the permission(s) `manage_messages` to execute this command!",
|
||||||
|
color=0xE02B2B,
|
||||||
|
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
return await self.send_embed(context, embed, ephemeral=True)
|
||||||
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
@@ -60,25 +75,32 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
user.id, context.guild.id, context.author.id, reason
|
user.id, context.guild.id, context.author.id, reason
|
||||||
)
|
)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
|
title="Warning",
|
||||||
description=f"**{member}** was warned by **{context.author}**!\nTotal warns for this user: {total}",
|
description=f"**{member}** was warned by **{context.author}**!\nTotal warns for this user: {total}",
|
||||||
color=0xBEBEFE,
|
color=0x7289DA,
|
||||||
)
|
)
|
||||||
|
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
embed.add_field(name="Reason:", value=reason)
|
embed.add_field(name="Reason:", value=reason)
|
||||||
await context.send(embed=embed)
|
await self.send_embed(context, embed)
|
||||||
try:
|
try:
|
||||||
await member.send(
|
dm_embed = discord.Embed(
|
||||||
f"You were warned by **{context.author}** in **{context.guild.name}**!\nReason: {reason}"
|
title="Warning",
|
||||||
|
description=f"You were warned by **{context.author}** in **{context.guild.name}**!\nReason: {reason}",
|
||||||
|
color=0xE02B2B,
|
||||||
)
|
)
|
||||||
|
dm_embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
await member.send(embed=dm_embed)
|
||||||
except:
|
except:
|
||||||
await context.send(
|
fallback = discord.Embed(
|
||||||
f"{member.mention}, you were warned by **{context.author}**!\nReason: {reason}"
|
description=f"{member.mention}, you were warned by **{context.author}**!\nReason: {reason}",
|
||||||
|
color=0xE02B2B,
|
||||||
)
|
)
|
||||||
|
await self.send_embed(context, fallback)
|
||||||
|
|
||||||
@warning.command(
|
@warning.command(
|
||||||
name="remove",
|
name="remove",
|
||||||
description="Removes a warning from a user in the server.",
|
description="Removes a warning from a user in the server.",
|
||||||
)
|
)
|
||||||
@commands.has_permissions(manage_messages=True)
|
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
user="The user that should get their warning removed.",
|
user="The user that should get their warning removed.",
|
||||||
warn_id="The ID of the warning that should be removed.",
|
warn_id="The ID of the warning that should be removed.",
|
||||||
@@ -93,21 +115,28 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
:param user: The user that should get their warning removed.
|
:param user: The user that should get their warning removed.
|
||||||
:param warn_id: The ID of the warning that should be removed.
|
:param warn_id: The ID of the warning that should be removed.
|
||||||
"""
|
"""
|
||||||
|
if not context.author.guild_permissions.manage_messages:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Missing Permissions!",
|
||||||
|
description="You are missing the permission(s) `manage_messages` to execute this command!",
|
||||||
|
color=0xE02B2B,
|
||||||
|
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
return await self.send_embed(context, embed, ephemeral=True)
|
||||||
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
total = await self.bot.database.remove_warn(warn_id, user.id, context.guild.id)
|
total = await self.bot.database.remove_warn(warn_id, user.id, context.guild.id)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
description=f"I've removed the warning **#{warn_id}** from **{member}**!\nTotal warns for this user: {total}",
|
description=f"I've removed the warning **#{warn_id}** from **{member}**!\nTotal warns for this user: {total}",
|
||||||
color=0xBEBEFE,
|
color=0x7289DA,
|
||||||
)
|
)
|
||||||
await context.send(embed=embed)
|
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
await self.send_embed(context, embed)
|
||||||
|
|
||||||
@warning.command(
|
@warning.command(
|
||||||
name="list",
|
name="list",
|
||||||
description="Shows the warnings of a user in the server.",
|
description="Shows the warnings of a user in the server.",
|
||||||
)
|
)
|
||||||
@commands.has_guild_permissions(manage_messages=True)
|
|
||||||
@app_commands.describe(user="The user you want to get the warnings of.")
|
@app_commands.describe(user="The user you want to get the warnings of.")
|
||||||
async def warning_list(self, context: Context, user: discord.User) -> None:
|
async def warning_list(self, context: Context, user: discord.User) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -116,8 +145,16 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
:param context: The hybrid command context.
|
:param context: The hybrid command context.
|
||||||
:param user: The user you want to get the warnings of.
|
:param user: The user you want to get the warnings of.
|
||||||
"""
|
"""
|
||||||
|
if not context.author.guild_permissions.manage_messages:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Missing Permissions!",
|
||||||
|
description="You are missing the permission(s) `manage_messages` to execute this command!",
|
||||||
|
color=0xE02B2B,
|
||||||
|
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
return await self.send_embed(context, embed, ephemeral=True)
|
||||||
warnings_list = await self.bot.database.get_warnings(user.id, context.guild.id)
|
warnings_list = await self.bot.database.get_warnings(user.id, context.guild.id)
|
||||||
embed = discord.Embed(title=f"Warnings of {user}", color=0xBEBEFE)
|
embed = discord.Embed(title=f"Warnings of {user}", color=0x7289DA)
|
||||||
|
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
description = ""
|
description = ""
|
||||||
if len(warnings_list) == 0:
|
if len(warnings_list) == 0:
|
||||||
description = "This user has no warnings."
|
description = "This user has no warnings."
|
||||||
@@ -125,7 +162,8 @@ class Warnings(commands.Cog, name="warnings"):
|
|||||||
for warning in warnings_list:
|
for warning in warnings_list:
|
||||||
description += f"• Warned by <@{warning[2]}>: **{warning[3]}** (<t:{warning[4]}>) - Warn ID #{warning[5]}\n"
|
description += f"• Warned by <@{warning[2]}>: **{warning[3]}** (<t:{warning[4]}>) - Warn ID #{warning[5]}\n"
|
||||||
embed.description = description
|
embed.description = description
|
||||||
await context.send(embed=embed)
|
await self.send_embed(context, embed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
async def setup(bot) -> None:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn/Python-Discord-Bot-Template/blob/main/database/__init__.py
|
# Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn/Python-Discord-Bot-Template/blob/main/database/__init__.py
|
||||||
# Used/Edited by neoarz
|
# Used by neoarz
|
||||||
|
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn/Python-Discord-Bot-Template/blob/main/database/schema.sql
|
-- Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn/Python-Discord-Bot-Template/blob/main/database/schema.sql
|
||||||
-- Used/Edited by neoarz
|
-- Used by neoarz
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `warns` (
|
CREATE TABLE IF NOT EXISTS `warns` (
|
||||||
`id` int(11) NOT NULL,
|
`id` int(11) NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user