style: new code layout

This commit is contained in:
neoarz
2025-09-14 18:54:56 -04:00
parent e14eceffc5
commit 8d261089c0
29 changed files with 1464 additions and 1010 deletions

50
cogs/general/bitcoin.py Normal file
View File

@@ -0,0 +1,50 @@
"""
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 aiohttp
import discord
from discord.ext import commands
from discord.ext.commands import Context
class Bitcoin(commands.Cog, name="bitcoin"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="bitcoin",
description="Get the current price of bitcoin.",
)
async def bitcoin(self, context: Context) -> None:
"""
Get the current price of bitcoin.
:param context: The hybrid command context.
"""
async with aiohttp.ClientSession() as session:
async with session.get(
"https://api.coindesk.com/v1/bpi/currentprice/BTC.json"
) as request:
if request.status == 200:
data = await request.json()
embed = discord.Embed(
title="Bitcoin price",
description=f"The current price is {data['bpi']['USD']['rate']} :dollar:",
color=0xBEBEFE,
)
else:
embed = discord.Embed(
title="Error!",
description="There is something wrong with the API, please try again later",
color=0xE02B2B,
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Bitcoin(bot))

48
cogs/general/botinfo.py Normal file
View File

@@ -0,0 +1,48 @@
"""
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 platform
import discord
from discord.ext import commands
from discord.ext.commands import Context
class BotInfo(commands.Cog, name="botinfo"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="botinfo",
description="Get some useful (or not) information about the bot.",
)
async def botinfo(self, context: Context) -> None:
"""
Get some useful (or not) information about the bot.
:param context: The hybrid command context.
"""
embed = discord.Embed(
description="Used [Krypton's](https://krypton.ninja) template",
color=0xBEBEFE,
)
embed.set_author(name="Bot Information")
embed.add_field(name="Owner:", value="Krypton#7331", inline=True)
embed.add_field(
name="Python Version:", value=f"{platform.python_version()}", inline=True
)
embed.add_field(
name="Prefix:",
value=f"/ (Slash Commands) or {self.bot.bot_prefix} for normal commands",
inline=False,
)
embed.set_footer(text=f"Requested by {context.author}")
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(BotInfo(bot))

View File

@@ -0,0 +1,66 @@
"""
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
from discord import app_commands
from discord.ext import commands
class ContextMenus(commands.Cog, name="context_menus"):
def __init__(self, bot) -> None:
self.bot = bot
self.context_menu_user = app_commands.ContextMenu(
name="Grab ID", callback=self.grab_id
)
self.bot.tree.add_command(self.context_menu_user)
self.context_menu_message = app_commands.ContextMenu(
name="Remove spoilers", callback=self.remove_spoilers
)
self.bot.tree.add_command(self.context_menu_message)
async def remove_spoilers(
self, interaction: discord.Interaction, message: discord.Message
) -> None:
"""
Removes the spoilers from the message. This command requires the MESSAGE_CONTENT intent to work properly.
:param interaction: The application command interaction.
:param message: The message that is being interacted with.
"""
spoiler_attachment = None
for attachment in message.attachments:
if attachment.is_spoiler():
spoiler_attachment = attachment
break
embed = discord.Embed(
title="Message without spoilers",
description=message.content.replace("||", ""),
color=0xBEBEFE,
)
if spoiler_attachment is not None:
embed.set_image(url=attachment.url)
await interaction.response.send_message(embed=embed, ephemeral=True)
async def grab_id(
self, interaction: discord.Interaction, user: discord.User
) -> None:
"""
Grabs the ID of the user.
:param interaction: The application command interaction.
:param user: The user that is being interacted with.
"""
embed = discord.Embed(
description=f"The ID of {user.mention} is `{user.id}`.",
color=0xBEBEFE,
)
await interaction.response.send_message(embed=embed, ephemeral=True)
async def setup(bot) -> None:
await bot.add_cog(ContextMenus(bot))

64
cogs/general/eightball.py Normal file
View File

@@ -0,0 +1,64 @@
"""
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 random
import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
class EightBall(commands.Cog, name="8ball"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="8ball",
description="Ask any question to the bot.",
)
@app_commands.describe(question="The question you want to ask.")
async def eight_ball(self, context: Context, *, question: str) -> None:
"""
Ask any question to the bot.
:param context: The hybrid command context.
:param question: The question that should be asked by the user.
"""
answers = [
"It is certain.",
"It is decidedly so.",
"You may rely on it.",
"Without a doubt.",
"Yes - definitely.",
"As I see, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again later.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.",
]
embed = discord.Embed(
title="**My Answer:**",
description=f"{random.choice(answers)}",
color=0xBEBEFE,
)
embed.set_footer(text=f"The question was: {question}")
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(EightBall(bot))

65
cogs/general/feedback.py Normal file
View File

@@ -0,0 +1,65 @@
"""
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
from discord import app_commands
from discord.ext import commands
class FeedbackForm(discord.ui.Modal, title="Feeedback"):
feedback = discord.ui.TextInput(
label="What do you think about this bot?",
style=discord.TextStyle.long,
placeholder="Type your answer here...",
required=True,
max_length=256,
)
async def on_submit(self, interaction: discord.Interaction):
self.interaction = interaction
self.answer = str(self.feedback)
self.stop()
class Feedback(commands.Cog, name="feedback"):
def __init__(self, bot) -> None:
self.bot = bot
@app_commands.command(
name="feedback", description="Submit a feedback for the owners of the bot"
)
async def feedback(self, interaction: discord.Interaction) -> None:
"""
Submit a feedback for the owners of the bot.
:param interaction: The application command interaction.
"""
feedback_form = FeedbackForm()
await interaction.response.send_modal(feedback_form)
await feedback_form.wait()
interaction = feedback_form.interaction
await interaction.response.send_message(
embed=discord.Embed(
description="Thank you for your feedback, the owners have been notified about it.",
color=0xBEBEFE,
)
)
app_owner = (await self.bot.application_info()).owner
await app_owner.send(
embed=discord.Embed(
title="New Feedback",
description=f"{interaction.user} (<@{interaction.user.id}>) has submitted a new feedback:\n```\n{feedback_form.answer}\n```",
color=0xBEBEFE,
)
)
async def setup(bot) -> None:
await bot.add_cog(Feedback(bot))

94
cogs/general/help.py Normal file
View File

@@ -0,0 +1,94 @@
"""
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
from discord.ext import commands
from discord.ext.commands import Context
class Help(commands.Cog, name="help"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="help", description="List all commands the bot has loaded."
)
async def help(self, context: Context) -> None:
embed = discord.Embed(
title="Help", description="List of available commands:", color=0xBEBEFE
)
category_mapping = {
"help": "General",
"botinfo": "General",
"serverinfo": "General",
"ping": "General",
"invite": "General",
"server": "General",
"8ball": "General",
"bitcoin": "General",
"feedback": "General",
"context_menus": "General",
"randomfact": "Fun",
"coinflip": "Fun",
"rps": "Fun",
"kick": "Moderation",
"ban": "Moderation",
"nick": "Moderation",
"purge": "Moderation",
"hackban": "Moderation",
"warnings": "Moderation",
"archive": "Moderation",
"sync": "Owner",
"cog_management": "Owner",
"shutdown": "Owner",
"say": "Owner",
"testcommand": "Template"
}
categories = {}
for cog_name in self.bot.cogs:
cog = self.bot.get_cog(cog_name)
if cog:
commands_list = cog.get_commands()
for command in commands_list:
category = category_mapping.get(cog_name.lower(), "Other")
if category == "Owner" and not (await self.bot.is_owner(context.author)):
continue
if category not in categories:
categories[category] = []
description = command.description.partition("\n")[0] if command.description else "No description available"
categories[category].append((command.name, description))
category_order = ["General", "Fun", "Moderation", "Template", "Owner", "Other"]
for category in category_order:
if category in categories and categories[category]:
data = []
for command_name, description in sorted(categories[category]):
data.append(f"{command_name} - {description}")
help_text = "\n".join(data)
embed.add_field(
name=category, value=f"```{help_text}```", inline=False
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Help(bot))

40
cogs/general/invite.py Normal file
View File

@@ -0,0 +1,40 @@
"""
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
from discord.ext import commands
from discord.ext.commands import Context
class Invite(commands.Cog, name="invite"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="invite",
description="Get the invite link of the bot to be able to invite it.",
)
async def invite(self, context: Context) -> None:
"""
Get the invite link of the bot to be able to invite it.
:param context: The hybrid command context.
"""
embed = discord.Embed(
description=f"Invite me by clicking [here]({self.bot.invite_link}).",
color=0xD75BF4,
)
try:
await context.author.send(embed=embed)
await context.send("I sent you a private message!")
except discord.Forbidden:
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Invite(bot))

37
cogs/general/ping.py Normal file
View File

@@ -0,0 +1,37 @@
"""
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
from discord.ext import commands
from discord.ext.commands import Context
class Ping(commands.Cog, name="ping"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="ping",
description="Check if the bot is alive.",
)
async def ping(self, context: Context) -> None:
"""
Check if the bot is alive.
:param context: The hybrid command context.
"""
embed = discord.Embed(
title="🏓 Pong!",
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
color=0xBEBEFE,
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Ping(bot))

40
cogs/general/server.py Normal file
View File

@@ -0,0 +1,40 @@
"""
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
from discord.ext import commands
from discord.ext.commands import Context
class Server(commands.Cog, name="server"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="server",
description="Get the invite link of the discord server of the bot for some support.",
)
async def server(self, context: Context) -> None:
"""
Get the invite link of the discord server of the bot for some support.
:param context: The hybrid command context.
"""
embed = discord.Embed(
description=f"Join the support server for the bot by clicking [here](https://discord.gg/mTBrXyWxAF).",
color=0xD75BF4,
)
try:
await context.author.send(embed=embed)
await context.send("I sent you a private message!")
except discord.Forbidden:
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Server(bot))

View File

@@ -0,0 +1,51 @@
"""
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
from discord.ext import commands
from discord.ext.commands import Context
class ServerInfo(commands.Cog, name="serverinfo"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="serverinfo",
description="Get some useful (or not) information about the server.",
)
async def serverinfo(self, context: Context) -> None:
"""
Get some useful (or not) information about the server.
:param context: The hybrid command context.
"""
roles = [role.name for role in context.guild.roles]
num_roles = len(roles)
if num_roles > 50:
roles = roles[:50]
roles.append(f">>>> Displaying [50/{num_roles}] Roles")
roles = ", ".join(roles)
embed = discord.Embed(
title="**Server Name:**", description=f"{context.guild}", color=0xBEBEFE
)
if context.guild.icon is not None:
embed.set_thumbnail(url=context.guild.icon.url)
embed.add_field(name="Server ID", value=context.guild.id)
embed.add_field(name="Member Count", value=context.guild.member_count)
embed.add_field(
name="Text/Voice Channels", value=f"{len(context.guild.channels)}"
)
embed.add_field(name=f"Roles ({len(context.guild.roles)})", value=roles)
embed.set_footer(text=f"Created at: {context.guild.created_at}")
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(ServerInfo(bot))