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

View File

@@ -0,0 +1,99 @@
"""
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
from discord.ext.commands import Context
class CogManagement(commands.Cog, name="cog_management"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="load",
description="Load a cog",
)
@app_commands.describe(cog="The name of the cog to load")
@commands.is_owner()
async def load(self, context: Context, cog: str) -> None:
"""
The bot will load the given cog.
:param context: The hybrid command context.
:param cog: The name of the cog to load.
"""
try:
await self.bot.load_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not load the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully loaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
@commands.hybrid_command(
name="unload",
description="Unloads a cog.",
)
@app_commands.describe(cog="The name of the cog to unload")
@commands.is_owner()
async def unload(self, context: Context, cog: str) -> None:
"""
The bot will unload the given cog.
:param context: The hybrid command context.
:param cog: The name of the cog to unload.
"""
try:
await self.bot.unload_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not unload the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully unloaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
@commands.hybrid_command(
name="reload",
description="Reloads a cog.",
)
@app_commands.describe(cog="The name of the cog to reload")
@commands.is_owner()
async def reload(self, context: Context, cog: str) -> None:
"""
The bot will reload the given cog.
:param context: The hybrid command context.
:param cog: The name of the cog to reload.
"""
try:
await self.bot.reload_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not reload the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(CogManagement(bot))

52
cogs/owner/say.py Normal file
View File

@@ -0,0 +1,52 @@
"""
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
from discord.ext.commands import Context
class Say(commands.Cog, name="say"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="say",
description="The bot will say anything you want.",
)
@app_commands.describe(message="The message that should be repeated by the bot")
@commands.is_owner()
async def say(self, context: Context, *, message: str) -> None:
"""
The bot will say anything you want.
:param context: The hybrid command context.
:param message: The message that should be repeated by the bot.
"""
await context.send(message)
@commands.hybrid_command(
name="embed",
description="The bot will say anything you want, but within embeds.",
)
@app_commands.describe(message="The message that should be repeated by the bot")
@commands.is_owner()
async def embed(self, context: Context, *, message: str) -> None:
"""
The bot will say anything you want, but using embeds.
:param context: The hybrid command context.
:param message: The message that should be repeated by the bot.
"""
embed = discord.Embed(description=message, color=0xBEBEFE)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Say(bot))

35
cogs/owner/shutdown.py Normal file
View File

@@ -0,0 +1,35 @@
"""
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 Shutdown(commands.Cog, name="shutdown"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="shutdown",
description="Make the bot shutdown.",
)
@commands.is_owner()
async def shutdown(self, context: Context) -> None:
"""
Shuts down the bot.
:param context: The hybrid command context.
"""
embed = discord.Embed(description="Shutting down. Bye! :wave:", color=0xBEBEFE)
await context.send(embed=embed)
await self.bot.close()
async def setup(bot) -> None:
await bot.add_cog(Shutdown(bot))

94
cogs/owner/sync.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 import app_commands
from discord.ext import commands
from discord.ext.commands import Context
class Sync(commands.Cog, name="sync"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.command(
name="sync",
description="Synchonizes the slash commands.",
)
@app_commands.describe(scope="The scope of the sync. Can be `global` or `guild`")
@commands.is_owner()
async def sync(self, context: Context, scope: str) -> None:
"""
Synchonizes the slash commands.
:param context: The command context.
:param scope: The scope of the sync. Can be `global` or `guild`.
"""
if scope == "global":
await context.bot.tree.sync()
embed = discord.Embed(
description="Slash commands have been globally synchronized.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
elif scope == "guild":
context.bot.tree.copy_global_to(guild=context.guild)
await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed(
description="Slash commands have been synchronized in this guild.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B
)
await context.send(embed=embed)
@commands.command(
name="unsync",
description="Unsynchonizes the slash commands.",
)
@app_commands.describe(
scope="The scope of the sync. Can be `global`, `current_guild` or `guild`"
)
@commands.is_owner()
async def unsync(self, context: Context, scope: str) -> None:
"""
Unsynchonizes the slash commands.
:param context: The command context.
:param scope: The scope of the sync. Can be `global`, `current_guild` or `guild`.
"""
if scope == "global":
context.bot.tree.clear_commands(guild=None)
await context.bot.tree.sync()
embed = discord.Embed(
description="Slash commands have been globally unsynchronized.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
elif scope == "guild":
context.bot.tree.clear_commands(guild=context.guild)
await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed(
description="Slash commands have been unsynchronized in this guild.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Sync(bot))