From 005678640f11a2af672704be2abb5a787b0cb3e8 Mon Sep 17 00:00:00 2001 From: GaMeNu <98153342+GaMeNu@users.noreply.github.com> Date: Thu, 16 Nov 2023 20:06:14 +0200 Subject: [PATCH] v2.2.4 Added info command, along with organized way to save client data --- README.md | 6 +++-- botinfo.json | 4 +++ botinfo.py | 7 +++++ cog_notificator.py | 54 ++++++++++++++++++++++++++++++++++++- requirements-new-python.txt | 4 ++- requirements.txt | 8 +++--- 6 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 botinfo.json create mode 100644 botinfo.py diff --git a/README.md b/README.md index 5404b3c..7f5c1b2 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,16 @@ Alternatively, you can DM the bot to receive alerts directly to your DMs! Please do note that the bot instance listed here is hosted on a private machine, and may be a bit slow. ## Command documentation -#### /about -Get some info about the bot #### /register Run in a channel to register it to receive alerts #### /unregister Run in a registered channel to stop it from receiving alerts #### /latest \ \ \[page\] Get the latest alerts from up to a certain time back. +#### /about +Get some info about the bot itself +#### /info +Get info about the system and client ### Location commands #### /locations add \ diff --git a/botinfo.json b/botinfo.json new file mode 100644 index 0000000..14cd972 --- /dev/null +++ b/botinfo.json @@ -0,0 +1,4 @@ +{ + "version": "2.2.4", + "maintainer": "GaMeNu (@gamenu)" +} \ No newline at end of file diff --git a/botinfo.py b/botinfo.py new file mode 100644 index 0000000..a0c4bc5 --- /dev/null +++ b/botinfo.py @@ -0,0 +1,7 @@ +import json + +with open('botinfo.json', 'r') as f: + botinfo_dict = json.loads(f.read()) + +version = botinfo_dict["version"] +maintainer = botinfo_dict["maintainer"] diff --git a/cog_notificator.py b/cog_notificator.py index 728173c..5593ae2 100644 --- a/cog_notificator.py +++ b/cog_notificator.py @@ -1,13 +1,18 @@ import datetime +import platform import re import sys +import time +import psutil import requests import discord from discord.ext import commands, tasks from discord import app_commands +import cpuinfo +import botinfo import db_access import errlogging from db_access import * @@ -101,6 +106,8 @@ class Notificator(commands.Cog): if not self.check_for_updates.is_running(): self.check_for_updates.start() + self.start_time = time.time() + @staticmethod async def setup(bot: commands.Bot, handler: logging.Handler): """ @@ -523,7 +530,52 @@ class Notificator(commands.Cog): return ret_str - @app_commands.command(name='about', description='Info about the bot') + @app_commands.command(name='info', description='Get client and system info') + async def botinfo(self, intr: discord.Interaction): + + def format_timedelta(timedelta: datetime.timedelta): + return f'{timedelta.days} days, {((timedelta.seconds // 3600) % 24)}:{((timedelta.seconds // 60) % 60)}:{(timedelta.seconds % 60)}' + + curtime = time.time() + client_uptime = datetime.timedelta(seconds=int(round(curtime - self.start_time))) + client_uptime_format = format_timedelta(client_uptime) + + print(curtime) + print(psutil.boot_time()) + print(curtime - psutil.boot_time()) + + system_uptime = datetime.timedelta(seconds=int(round(curtime - psutil.boot_time()))) + system_uptime_format = format_timedelta(system_uptime) + + uname = platform.uname() + + b_to_mb = 1000000 + + e = discord.Embed(color=discord.Color.orange()) + e.title = 'Home Front Command Notificator' + e.description = 'Info about this bot instance' + + e.add_field(name='', value=f'''```asciidoc +==== Instance and Client Information ==== +Version :: {botinfo.version} +Uptime :: {client_uptime_format} +Instance Maintainer(s) :: {botinfo.maintainer} + +Guilds Joined :: {len(self.bot.guilds)} +Registered channels :: {len(self.db.get_all_channels())} + +==== System Information ==== +OS :: {uname.system} {uname.release} +Uptime :: {system_uptime_format} + +Processor :: {cpuinfo.get_cpu_info()["brand_raw"]} +Proc.Usage :: {psutil.cpu_percent()}% + +RAM Usage :: {(psutil.virtual_memory().used / b_to_mb):.2f} MB / {(psutil.virtual_memory().total / b_to_mb):.2f} MB ({psutil.virtual_memory().percent}%) +```''', inline=False) + await intr.response.send_message(embed=e) + + @app_commands.command(name='about', description='About the bot') async def about_bot(self, intr: discord.Interaction): e = discord.Embed(color=discord.Color.orange()) e.title = 'Home Front Command Notificator' diff --git a/requirements-new-python.txt b/requirements-new-python.txt index b676d0f..4cc934d 100644 --- a/requirements-new-python.txt +++ b/requirements-new-python.txt @@ -2,4 +2,6 @@ aiohttp==3.9.0b0 discord.py mysql-connector-python requests -python-dotenv \ No newline at end of file +python-dotenv +py-cpuinfo +psutil~=5.9.6 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9ad72be..02f364a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ discord.py -mysql-connector-python -requests -python-dotenv \ No newline at end of file +mysql-connector-python~=8.2.0 +requests~=2.31.0 +python-dotenv~=1.0.0 +py-cpuinfo~=9.0.0 +psutil~=5.9.6 \ No newline at end of file