Skip to content

Commit

Permalink
Implement lavalink stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Mar 22, 2024
1 parent 403a0c3 commit ae9d111
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions extensions/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from discord import ButtonStyle, Interaction, ui
from discord.ext import commands

import utils
from core import config
from core.bot import Substiify

Expand Down Expand Up @@ -222,6 +223,31 @@ async def players(self, ctx: commands.Context):
embed.description = players_string
await ctx.send(embed=embed, delete_after=60)

@commands.is_owner()
@commands.command(name="lavalink", aliases=["lv"], hidden=True)
async def lavalink_stats(self, ctx: commands.Context):
"""
Shows the Lavalink stats.
"""
stats: wavelink.StatsResponsePayload = await wavelink.Pool.get_node().fetch_stats()
info: wavelink.InfoResponsePayload = await wavelink.Pool.get_node().fetch_info()

players_str = f"[` {stats.players} -> {stats.playing} `]"
version_str = f"[` {info.version} `]"
uptime_str = f"[` {utils.seconds_to_human_readable(stats.uptime/1000)} `]"
memory_used = utils.bytes_to_human_readable(stats.memory.used)
memory_free = utils.bytes_to_human_readable(stats.memory.free)
memory_str = f"[` {memory_used}MB | {memory_free}MB `]"
cpu_str = f"[` {stats.cpu.cores} | {stats.cpu.system_load} `]"

embed = discord.Embed(title="Lavalink Info", color=EMBED_COLOR)
embed.add_field(name="Players", value=players_str)
embed.add_field(name="Version", value=version_str)
embed.add_field(name="Uptime", value=uptime_str)
embed.add_field(name="Memory", value=memory_str)
embed.add_field(name="CPU Usage", value=cpu_str)
await ctx.send(embed=embed)

@commands.hybrid_command()
@commands.check_any(commands.has_permissions(manage_channels=True), commands.is_owner())
async def cleanup(self, ctx: commands.Context, enable: bool = None):
Expand Down

0 comments on commit ae9d111

Please sign in to comment.