VisionApp/features/custom.py

74 lines
2.9 KiB
Python
Raw Normal View History

from __future__ import annotations
import logging
import discord
from discord import app_commands
from discord.ext import commands
logger = logging.getLogger("vision")
class CustomMessages(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@app_commands.command(name="botstatus", description="Changer le statut du bot")
@app_commands.describe(text="Texte du statut", type_type="Type: playing, watching, listening")
@app_commands.checks.has_permissions(manage_guild=True)
async def botstatus(self, interaction: discord.Interaction, text: str, type_type: str = "playing"):
activities = {
"playing": discord.ActivityType.playing,
"watching": discord.ActivityType.watching,
"listening": discord.ActivityType.listening,
"streaming": discord.ActivityType.streaming,
}
activity_type = activities.get(type_type.lower(), discord.ActivityType.playing)
activity = discord.Activity(type=activity_type, name=text)
await self.bot.change_presence(activity=activity)
await interaction.response.send_message(f"Statut changé : **{text}**", ephemeral=True)
@app_commands.command(name="custom_send", description="Envoyer un message custom")
@app_commands.describe(channel="Canal", message="Contenu", title="Titre de l'embed")
@app_commands.checks.has_permissions(manage_guild=True)
async def custom_send(
self, interaction: discord.Interaction, channel: discord.TextChannel, message: str, title: str = ""
):
if title:
embed = discord.Embed(title=title, description=message, color=discord.Color.blurple())
await channel.send(embed=embed)
else:
await channel.send(message)
await interaction.response.send_message(f"Message envoyé dans {channel.mention}", ephemeral=True)
@app_commands.command(name="embed", description="Envoyer un embed personnalisé")
@app_commands.describe(
channel="Canal", title="Titre", description="Description", color="Couleur (hex)", image_url="Image"
)
@app_commands.checks.has_permissions(manage_guild=True)
async def embed(
self,
interaction: discord.Interaction,
channel: discord.TextChannel,
title: str,
description: str,
color: str = "#5865F2",
image_url: str = "",
):
try:
color_int = int(color.lstrip("#"), 16)
except ValueError:
color_int = 0x5865F2
embed = discord.Embed(title=title, description=description, color=color_int)
if image_url:
embed.set_image(url=image_url)
embed.set_footer(text=f"Envoyé par {interaction.user}")
await channel.send(embed=embed)
await interaction.response.send_message(f"Embed envoyé dans {channel.mention}", ephemeral=True)
async def setup(bot: commands.Bot):
await bot.add_cog(CustomMessages(bot))