From d22e61991f097607c85f9a4fa188effccdc1b32f Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:44:30 +0000 Subject: [PATCH 1/2] Add economy library function to get total user count --- cogs/economy.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cogs/economy.py b/cogs/economy.py index d7eb8eee..a12ef615 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -64,6 +64,12 @@ def new_bank(id: int): currency['bank'][str(id)] = 0 return 0 else: return 1 + +def get_user_count(): + users = 0 + for x in currency["wallet"].keys(): + users += 1 + return users # Commands class Economy(commands.Cog): From 63557f3c254d96e9193d7fd23f22eb378ebfe010 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 6 Mar 2023 03:53:43 +0000 Subject: [PATCH 2/2] Move `/status` from main file to utils cog --- cogs/utils.py | 23 ++++++++++++++++++++++- main.py | 20 -------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cogs/utils.py b/cogs/utils.py index 69576db2..a018dc69 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -1,9 +1,11 @@ # Imports import discord +import os +import psutil import framework.isobot.embedengine from discord import option, ApplicationContext from discord.ext import commands -from cogs.economy import get_wallet, get_bank, get_user_networth +from cogs.economy import get_wallet, get_bank, get_user_networth, get_user_count from cogs.levelling import get_level, get_xp # Variables @@ -62,6 +64,25 @@ async def profile(self, ctx: ApplicationContext, user: discord.User = None): # More stats will be added later # Maybe I should make a userdat system for collecting statistical data to process and display here, coming in a future update. await ctx.respond(embed=localembed) + + @commands.slash_command( + name="status", + description="Shows the current client info" + ) + async def status(self, ctx: ApplicationContext): + os_name = os.name + sys_ram = str(f"{psutil.virtual_memory()[2]}GiB") + sys_cpu = str(f"{psutil.cpu_percent(1)}%") + bot_users = get_user_count() + localembed = discord.Embed(title="Client Info") + localembed.add_field(name="OS Name", value=os_name) + localembed.add_field(name="RAM Available", value=sys_ram) + localembed.add_field(name="CPU Usage", value=sys_cpu) + localembed.add_field(name="Registered Users", value=f"{bot_users} users", inline=True) + localembed.add_field(name="Uptime History", value="[here](https://stats.uptimerobot.com/PlKOmI0Aw8)") + localembed.add_field(name="Release Notes", value="[latest](https://github.com/PyBotDevs/isobot/releases/latest)") + localembed.set_footer(text=f"Requested by {ctx.author.name}", icon_url=ctx.author.avatar_url) + await ctx.respond(embed=localembed) # Cog Initialization def setup(bot): bot.add_cog(Utils(bot)) diff --git a/main.py b/main.py index 27a0da26..a8b6c852 100644 --- a/main.py +++ b/main.py @@ -291,26 +291,6 @@ async def sync(ctx: ApplicationContext): @option(name="question", description="What do you want to predict?", type=str) async def prediction(ctx: ApplicationContext, question:str): await ctx.respond(f"My prediction is... **{random.choice(['Yes', 'No'])}!**") -@client.slash_command( - name="status", - description="Shows the current client info" -) -async def status(ctx: ApplicationContext): - os_name = os.name - sys_ram = str(f"{psutil.virtual_memory()[2]}GiB") - sys_cpu = str(f"{psutil.cpu_percent(1)}%") - bot_users = 0 - for x in levels.keys(): bot_users += 1 - localembed = discord.Embed(title="Client Info") - localembed.add_field(name="OS Name", value=os_name) - localembed.add_field(name="RAM Available", value=sys_ram) - localembed.add_field(name="CPU Usage", value=sys_cpu) - localembed.add_field(name="Registered Users", value=f"{bot_users} users", inline=True) - localembed.add_field(name="Uptime History", value="[here](https://stats.uptimerobot.com/PlKOmI0Aw8)") - localembed.add_field(name="Release Notes", value="[latest](https://github.com/PyBotDevs/isobot/releases/latest)") - localembed.set_footer(text=f"Requested by {ctx.author.name}", icon_url=ctx.author.avatar_url) - await ctx.respond(embed=localembed) - # Cog Commands (these cannot be moved into a cog) cogs = client.create_group("cog", "Commands for working with isobot cogs.")