mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-02 16:43:12 +00:00
feat(console.py): add new console.py file to handle bot commands from console
refactor(console.py): replace ThreadPoolExecutor with aioconsole.ainput for non-blocking input fix(console.py): handle ValueError when channel ID is not an integer in send_message function refactor(console.py): remove unused close_executor function feat(console.py): add shutdown_bot function to initiate bot shutdown from console style(console.py): improve code readability and comments feat: add command_func() to enhance functionality feat(pagination.py): add new file for handling pagination in discord interactions This new file includes a class for creating interactive list menus in discord. It allows for navigation through a list of items (either strings or discord.Embed objects) using buttons in the discord UI. The list menu can be set to be ephemeral (disappears after a certain timeout) or persistent. The class also includes methods for handling user interactions with the list menu, such as jumping to the first or last item, or navigating to the next or previous item. feat(rolecount.py): add new RoleCount cog to count users in each role This new feature allows users to see the number of users in each role. It supports distro, language, DE/WM, misc, and vanity roles. The role count is displayed in an embed with pagination support. feat(moderation): add ModerationCogBase class to handle moderation tasks This class includes methods for creating and sending embeds, and sending direct messages to users. This will help in managing moderation tasks more efficiently.
This commit is contained in:
parent
73943b1e98
commit
bf08491c5a
4 changed files with 64 additions and 0 deletions
|
@ -0,0 +1,64 @@
|
|||
from datetime import datetime
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from loguru import logger
|
||||
|
||||
from tux.database.controllers import DatabaseController
|
||||
from tux.utils.embeds import create_embed_footer
|
||||
|
||||
# TODO: Move command permission checks to the base class
|
||||
|
||||
|
||||
class ModerationCogBase(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot = bot
|
||||
self.db = DatabaseController()
|
||||
self.config = DatabaseController().guild_config
|
||||
|
||||
async def create_embed(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
title: str,
|
||||
fields: list[tuple[str, str, bool]],
|
||||
color: int,
|
||||
icon_url: str,
|
||||
timestamp: datetime | None = None,
|
||||
) -> discord.Embed:
|
||||
embed = discord.Embed(color=color, timestamp=timestamp or ctx.message.created_at)
|
||||
embed.set_author(name=title, icon_url=icon_url)
|
||||
footer_text, footer_icon_url = create_embed_footer(ctx)
|
||||
embed.set_footer(text=footer_text, icon_url=footer_icon_url)
|
||||
for name, value, inline in fields:
|
||||
embed.add_field(name=name, value=value, inline=inline)
|
||||
return embed
|
||||
|
||||
async def send_embed(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
embed: discord.Embed,
|
||||
log_type: str,
|
||||
) -> None:
|
||||
if ctx.guild:
|
||||
log_channel_id = await self.config.get_log_channel(ctx.guild.id, log_type)
|
||||
if log_channel_id:
|
||||
log_channel = ctx.guild.get_channel(log_channel_id)
|
||||
if isinstance(log_channel, discord.TextChannel):
|
||||
await log_channel.send(embed=embed)
|
||||
|
||||
async def send_dm(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
silent: bool,
|
||||
target: discord.Member,
|
||||
reason: str,
|
||||
action: str,
|
||||
) -> None:
|
||||
if not silent:
|
||||
try:
|
||||
await target.send(
|
||||
f"You have been {action} from {ctx.guild} for the following reason:\n> {reason}",
|
||||
)
|
||||
except (discord.Forbidden, discord.HTTPException) as e:
|
||||
logger.warning(f"Failed to send DM to {target}. {e}")
|
||||
await ctx.send(f"Failed to send DM to {target}. {e}", delete_after=10, ephemeral=True)
|
Loading…
Reference in a new issue