1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00

Add stats command

This commit is contained in:
wlinator 2024-03-26 13:42:30 +01:00
parent c58b0dfcf3
commit 1187d93735
5 changed files with 60 additions and 4 deletions

View file

@ -1,5 +1,7 @@
{ {
"emotes_guild_id": 1038051105642401812, "emotes_guild_id": 1038051105642401812,
"gitlab_url": "https://gitlab.com/wlinator/Racu",
"author_url": "<https://discord.com/users/784783517845946429>",
"guild_specific": { "guild_specific": {
"guild_id": 719227135151046699, "guild_id": 719227135151046699,
"intro_channel_id": 973619250507972618, "intro_channel_id": 973619250507972618,
@ -20,7 +22,8 @@
"icons": { "icons": {
"racu_exclam": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_exclam.png", "racu_exclam": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_exclam.png",
"racu_question": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_question.png", "racu_question": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_question.png",
"racu_streak": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_streak.png" "racu_streak": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_streak.png",
"racu_logo": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_logo.png"
}, },
"blackjack": { "blackjack": {
"emotes": { "emotes": {

View file

@ -4,8 +4,7 @@ import discord
from discord.ext import commands, bridge, tasks from discord.ext import commands, bridge, tasks
from lib import checks from lib import checks
from lib.embeds.info import MiscInfo from lib.embeds.info import MiscInfo
from lib.embeds.error import IntroErrors from modules.misc import introduction, invite, backup, info
from modules.misc import introduction, invite, backup
from modules.config import prefix from modules.config import prefix
@ -60,6 +59,17 @@ class Misc(commands.Cog):
async def prefix_command(self, ctx): async def prefix_command(self, ctx):
return await prefix.get_cmd(ctx) return await prefix.get_cmd(ctx)
@bridge.bridge_command(
name="info",
aliases=["stats"]
)
async def info_command(self, ctx):
"""
Shows basic stats for Racu.
"""
unix_timestamp = int(round(self.start_time.timestamp()))
return await info.cmd(self, ctx, unix_timestamp)
@bridge.bridge_command( @bridge.bridge_command(
name="introduction", name="introduction",
aliases=["intro", "introduce"], aliases=["intro", "introduce"],

33
modules/misc/info.py Normal file
View file

@ -0,0 +1,33 @@
import logging
import discord
from config.parser import JsonCache
from lib import metadata
from services.BlackJackStats import BlackJackStats
from services.Currency import Currency
import psutil
_logs = logging.getLogger('Racu.Core')
_data = JsonCache.read_json("resources")
async def cmd(command, ctx, unix_timestamp):
memory_usage = psutil.Process().memory_info().rss
memory_usage_in_mb = memory_usage / (1024 * 1024)
total_rows = BlackJackStats.get_total_rows_count()
total_rows = Currency.format(total_rows)
embed = discord.Embed(
color=discord.Color.orange()
)
embed.set_author(name=f"{metadata.__title__} v{metadata.__version__}",
url=_data["gitlab_url"],
icon_url=_data["icons"]["racu_logo"])
embed.add_field(name="Author", value=f"[{metadata.__author__}]({_data['author_url']})", inline=False)
embed.add_field(name="Uptime", value=f"<t:{unix_timestamp}:R>", inline=False)
embed.add_field(name="Latency", value=f"{round(1000 * command.client.latency)}ms", inline=False)
embed.add_field(name="Memory", value=f"{memory_usage_in_mb:.2f} MB", inline=False)
embed.add_field(name="Database", value=f"{total_rows} records", inline=False)
return await ctx.respond(embed=embed)

View file

@ -3,4 +3,5 @@ python-dotenv==1.0.0
setuptools==67.8.0 setuptools==67.8.0
pytz==2023.3 pytz==2023.3
dropbox==11.36.2 dropbox==11.36.2
mysql-connector-python==8.1.0 mysql-connector-python==8.1.0
psutil==5.9.8

View file

@ -44,3 +44,12 @@ class BlackJackStats:
"winning_amount": winning_amount, "winning_amount": winning_amount,
"losing_amount": losing_amount "losing_amount": losing_amount
} }
@staticmethod
def get_total_rows_count():
query = """
SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
"""
return database.select_query_one(query)