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

Merge branch 'dev' into 'main'

Add stats command

See merge request wlinator/Racu!31
This commit is contained in:
wlinator 2024-03-26 12:42:56 +00:00
commit fdda918c84
6 changed files with 94 additions and 38 deletions

View file

@ -1,5 +1,7 @@
{
"emotes_guild_id": 1038051105642401812,
"gitlab_url": "https://gitlab.com/wlinator/Racu",
"author_url": "<https://discord.com/users/784783517845946429>",
"guild_specific": {
"guild_id": 719227135151046699,
"intro_channel_id": 973619250507972618,
@ -20,7 +22,8 @@
"icons": {
"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_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": {
"emotes": {

View file

@ -136,40 +136,40 @@ class Economy(commands.Cog):
elif isinstance(error, commands.BadArgument):
await ctx.respond(embed=EconErrors.bad_bet_argument(ctx))
@commands.slash_command(
name="stats",
description="Display your stats (BETA)",
guild_only=True
)
@commands.guild_only()
@checks.allowed_in_channel()
async def stats_command(self, ctx, *, game: discord.Option(choices=["BlackJack", "Slots"])):
return await stats.cmd(self, ctx, game)
@commands.command(
name="stats",
aliases=["stat"],
help="Display your gambling stats, you can choose between \"blackjack\" or \"slots\"."
)
@commands.guild_only()
@checks.allowed_in_channel()
async def stats_command_prefix(self, ctx, *, game: str):
if game.lower() == "blackjack" or game.lower() == "bj":
game = "BlackJack"
elif game.lower() == "slots" or game.lower() == "slot":
game = "Slots"
else:
raise commands.BadArgument
return await stats.cmd(self, ctx, game)
@stats_command_prefix.error
async def on_command_error(self, ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.respond(embed=EconErrors.missing_bet(ctx))
elif isinstance(error, commands.BadArgument):
await ctx.respond(embed=EconErrors.bad_argument(ctx))
# @commands.slash_command(
# name="stats",
# description="Display your stats (BETA)",
# guild_only=True
# )
# @commands.guild_only()
# @checks.allowed_in_channel()
# async def stats_command(self, ctx, *, game: discord.Option(choices=["BlackJack", "Slots"])):
# return await stats.cmd(self, ctx, game)
#
# @commands.command(
# name="stats",
# aliases=["stat"],
# help="Display your gambling stats, you can choose between \"blackjack\" or \"slots\"."
# )
# @commands.guild_only()
# @checks.allowed_in_channel()
# async def stats_command_prefix(self, ctx, *, game: str):
#
# if game.lower() == "blackjack" or game.lower() == "bj":
# game = "BlackJack"
# elif game.lower() == "slots" or game.lower() == "slot":
# game = "Slots"
# else:
# raise commands.BadArgument
#
# return await stats.cmd(self, ctx, game)
#
# @stats_command_prefix.error
# async def on_command_error(self, ctx, error):
# if isinstance(error, commands.MissingRequiredArgument):
# await ctx.respond(embed=EconErrors.missing_bet(ctx))
# elif isinstance(error, commands.BadArgument):
# await ctx.respond(embed=EconErrors.bad_argument(ctx))
def setup(client):

View file

@ -4,8 +4,7 @@ import discord
from discord.ext import commands, bridge, tasks
from lib import checks
from lib.embeds.info import MiscInfo
from lib.embeds.error import IntroErrors
from modules.misc import introduction, invite, backup
from modules.misc import introduction, invite, backup, info
from modules.config import prefix
@ -60,6 +59,17 @@ class Misc(commands.Cog):
async def prefix_command(self, 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(
name="introduction",
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
pytz==2023.3
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,
"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)