Skip to content

Commit c0fa213

Browse files
committed
refactor: add more cogs to basic cog and refactor search with componentv2
1 parent ac1f7f0 commit c0fa213

File tree

14 files changed

+490
-181
lines changed

14 files changed

+490
-181
lines changed

rosetta/__main__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import logging
2-
import os
3-
from pathlib import Path
42

53
import discord
64
from discord.ext import commands
75

6+
from .commands import LLM, Basics, Music, Mygo
7+
from .utils.config import BotConfig, EmojiConfig
88
from .utils.embeds import ErrorEmbed
9-
10-
from .commands import LLM, Admin, Basics, Music, Mygo
119
from .utils.log import LogContext, PydanticAdapter, setup_logging
12-
from .utils.config import BotConfig, EmojiConfig
1310

1411
setup_logging(dev_mode=BotConfig.DEBUG)
1512
logger = logging.getLogger("rosetta")
@@ -76,7 +73,6 @@ async def on_app_command_error(
7673

7774

7875
async def setup_hook():
79-
await bot.add_cog(Admin(bot))
8076
await bot.add_cog(Basics(bot))
8177
await bot.add_cog(Music(bot))
8278
await bot.add_cog(Mygo(bot))

rosetta/commands/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .admin import Admin
21
from .basics import Basics
32
from .llm import LLM
43
from .music import Music

rosetta/commands/admin.py

Lines changed: 0 additions & 129 deletions
This file was deleted.

rosetta/commands/basics.py

Lines changed: 152 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import os
2+
import platform
3+
import sys
4+
from datetime import datetime
25

36
import discord
7+
import pomice
48
from discord import app_commands
59
from discord.ext import commands
6-
from yt_dlp.version import __version__
710

8-
from ..utils.embeds import InfoEmbed, PingEmbed
11+
from ..utils.cog import Cog
12+
from ..utils.embeds import PingEmbed
13+
from ..utils.player import CustomPlayer
914

1015

11-
class Basics(commands.Cog):
16+
class Basics(Cog):
1217
def __init__(self, bot: commands.Bot):
13-
self.bot = bot
18+
super().__init__(bot=bot)
1419

1520
@app_commands.command(name="ping", description="Ping the bot")
1621
async def ping(self, interaction: discord.Interaction):
17-
voice_client = interaction.guild.voice_client if interaction.guild else None
22+
voice_client: CustomPlayer | None = (
23+
interaction.guild.voice_client if interaction.guild else None
24+
)
1825
if voice_client:
1926
await interaction.response.send_message(
20-
embed=PingEmbed(self.bot.user, voice_client.latency)
27+
embed=PingEmbed(self.bot.user, voice_client.node.latency)
2128
)
2229
else:
2330
await interaction.response.send_message(
@@ -26,7 +33,143 @@ async def ping(self, interaction: discord.Interaction):
2633

2734
@app_commands.command(name="version", description="Show version information")
2835
async def version(self, interaction: discord.Interaction):
29-
embed = InfoEmbed(self.bot.user, "")
30-
embed.add_field(name="version", value=os.getenv("ROSETTA_VERSION"))
31-
embed.add_field(name="yt-dlp version", value=__version__)
36+
embed = await self.generate_version_embed(
37+
interaction, is_admin=await self.bot.is_owner(interaction.user)
38+
)
3239
await interaction.response.send_message(embed=embed)
40+
41+
@commands.is_owner()
42+
@commands.command(name="version", description="Show version information")
43+
async def admin(self, ctx: commands.Context):
44+
embed = await self.generate_version_embed(ctx, is_admin=True)
45+
46+
await ctx.reply(embed=embed)
47+
48+
@commands.is_owner()
49+
@commands.command(name="guilds", description="Show all guilds the bot is in")
50+
async def guilds(self, ctx: commands.Context):
51+
"""Display all guilds the bot is currently in"""
52+
from ..utils.views import GuildsView
53+
54+
view = GuildsView(self.bot)
55+
await ctx.reply(view=view)
56+
57+
async def generate_version_embed(
58+
self, ctx: discord.Interaction | commands.Context, is_admin: bool = False
59+
):
60+
embed = discord.Embed(
61+
title=":information_source: Info",
62+
color=discord.Color.blurple(),
63+
timestamp=datetime.now(),
64+
)
65+
66+
# Gather bot statistics
67+
total_guilds = len(self.bot.guilds)
68+
total_users = sum(guild.member_count for guild in self.bot.guilds)
69+
total_channels = sum(len(guild.channels) for guild in self.bot.guilds)
70+
total_voice_channels = sum(
71+
len(guild.voice_channels) for guild in self.bot.guilds
72+
)
73+
74+
# Version information
75+
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
76+
discord_version = discord.__version__
77+
78+
# System information
79+
os_info = f"{platform.system()} {platform.release()}"
80+
81+
# Create embed
82+
embed = discord.Embed(
83+
title="🛡️ Admin Panel",
84+
description="Bot Statistics and Information",
85+
color=discord.Color.blue(),
86+
timestamp=datetime.now(),
87+
)
88+
89+
# Versions
90+
embed.add_field(
91+
name="Version",
92+
value=os.getenv("ROSETTA_VERSION"),
93+
inline=True,
94+
)
95+
embed.add_field(
96+
name="Python",
97+
value=python_version,
98+
inline=True,
99+
)
100+
embed.add_field(
101+
name="Discord.py",
102+
value=discord_version,
103+
inline=True,
104+
)
105+
106+
if is_admin:
107+
# Bot Statistics
108+
embed.add_field(
109+
name="Statistics",
110+
value=f"**Guilds:** {total_guilds:,}\n"
111+
f"**Users:** {total_users:,}\n"
112+
f"**Channels:** {total_channels:,}\n"
113+
f"**Voice Channels:** {total_voice_channels:,}",
114+
inline=True,
115+
)
116+
117+
# System Information
118+
embed.add_field(
119+
name="System",
120+
value=f"**OS:** {os_info}\n**Platform:** {platform.machine()}",
121+
inline=True,
122+
)
123+
124+
# Cog Information
125+
cog_count = len(self.bot.cogs)
126+
command_count = len(self.bot.tree.get_commands())
127+
embed.add_field(
128+
name="Loaded Modules",
129+
value=f"**Cogs:** {cog_count}\n**Slash Commands:** {command_count}",
130+
inline=True,
131+
)
132+
133+
# Lavalink Node Information
134+
try:
135+
node_pool = pomice.NodePool()
136+
nodes = node_pool.nodes
137+
138+
if nodes:
139+
node_info_lines = []
140+
for node in nodes.values():
141+
status = (
142+
"🟢 Connected" if node.is_connected else "🔴 Disconnected"
143+
)
144+
latency_ms = (
145+
round(node.latency * 1000, 2) if node.latency else 0
146+
)
147+
node_info_lines.append(
148+
f"- **{node._identifier}** {status}{latency_ms}ms"
149+
)
150+
151+
embed.add_field(
152+
name=f"🎵 Lavalink Nodes ({len(nodes)})",
153+
value="\n".join(node_info_lines)
154+
if node_info_lines
155+
else "No nodes available",
156+
inline=False,
157+
)
158+
else:
159+
embed.add_field(
160+
name="🎵 Lavalink Nodes",
161+
value="No nodes available",
162+
inline=False,
163+
)
164+
except Exception as e:
165+
embed.add_field(
166+
name="🎵 Lavalink Nodes",
167+
value=f"Error fetching nodes: {str(e)}",
168+
inline=False,
169+
)
170+
171+
embed.set_thumbnail(
172+
url=self.bot.user.avatar.url if self.bot.user.avatar else None
173+
)
174+
175+
return embed

rosetta/commands/llm.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from discord.ext import commands
44
from langfuse import get_client, openai
55

6-
from rosetta.utils.views.LLM import LLMView
7-
6+
from ..utils.cog import Cog
87
from ..utils.config import LLMConfig
98
from ..utils.embeds import InfoEmbed
10-
from ..utils.cog import Cog
9+
from ..utils.views.LLM import LLMView
1110

1211
client = openai.AsyncOpenAI(
1312
base_url=LLMConfig.BASE_URL,
@@ -24,19 +23,23 @@
2423
async def get_models_autocomplete(
2524
interaction: discord.Interaction, current: str
2625
) -> list[app_commands.Choice[str]]:
27-
if await interaction.client.is_owner(interaction.user):
28-
models_list = await client.models.list()
29-
models = [m.id for m in models_list.data]
30-
else:
31-
models = [LLMConfig.get("DEFAULT_MODEL")]
26+
models_list = await client.models.list()
27+
models = [m.id for m in models_list.data]
3228
return [app_commands.Choice(name=m, value=m) for m in models if current in m][:25]
3329

3430

3531
class LLM(Cog):
3632
def __init__(self, bot: commands.Bot):
3733
super().__init__(bot)
3834

39-
llm_group = app_commands.Group(name="llm", description="LLM commands")
35+
llm_group = app_commands.Group(
36+
name="llm",
37+
description="LLM commands",
38+
allowed_installs=app_commands.AppInstallationType(guild=True, user=True),
39+
allowed_contexts=app_commands.AppCommandContext(
40+
guild=True, dm_channel=True, private_channel=True
41+
),
42+
)
4043

4144
@llm_group.command(name="list", description="List all models")
4245
async def list_models(self, interaction: discord.Interaction):

0 commit comments

Comments
 (0)