From 9d02988cdb7b6c4438b2d9d5de7f1d86c92ddfe2 Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Sun, 30 Mar 2025 19:39:53 +0200 Subject: [PATCH] update webserver cog --- cogs/styles.css | 118 ---------- cogs/webserver.py | 532 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 425 insertions(+), 225 deletions(-) delete mode 100644 cogs/styles.css diff --git a/cogs/styles.css b/cogs/styles.css deleted file mode 100644 index 0395689..0000000 --- a/cogs/styles.css +++ /dev/null @@ -1,118 +0,0 @@ - -.topnav { - background-color: rgb(95, 27, 27); - overflow: hidden; - display: flex; - flex-wrap: wrap; - justify-content: center; - padding: 10px; - gap: 20px; -} - -.topnav a { - color: #f2f2f2; - text-align: center; - text-decoration: none; - font-size: 17px; -} - -.topnav a:hover { - background-color: #ddd; - color: black; -} - -.stat-item { - display: flex; - align-items: center; - gap: 5px; - color: white; - font-size: 14px; -} - -.stat-title { - font-weight: bold; - color: #ccc; -} - -body { - background-color: black; - color: white; - font-family: Arial, sans-serif; -} - -a { - color: red; -} - -.stats-container { - max-width: 800px; - margin: 20px auto; - padding: 20px; - background-color: #1a1a1a; - border-radius: 8px; - text-align: left; -} - -.balls { - text-align: right; -} - -.stat-card { - background-color: #2a2a2a; - padding: 15px; - margin: 10px 0; - border-radius: 5px; - border-left: 4px solid rgb(95, 27, 27); -} - -.guild-list { - max-height: 300px; - overflow-y: auto; - background-color: #2a2a2a; - padding: 10px; - border-radius: 5px; -} - -.guild-item { - padding: 5px 0; - border-bottom: 1px solid #444; -} - -.guild-item:last-child { - border-bottom: none; -} - -hr { - border-color: rgb(95, 27, 27); - margin: 20px 0; -} - -.center { - text-align: center; -} - -.stat-container-row { - display: flex; - justify-content: space-between; - gap: 20px; - margin-bottom: 10px; -} - -.bot-info { - display: flex; - align-items: center; - justify-content: center; - gap: 10px; -} - -.bot-avatar { - width: 50px; - height: 50px; - border-radius: 0%; -} - -button { - background-color:black; - color: white; - cursor: pointer; -} \ No newline at end of file diff --git a/cogs/webserver.py b/cogs/webserver.py index 04c9cc1..ffd3582 100644 --- a/cogs/webserver.py +++ b/cogs/webserver.py @@ -33,6 +33,48 @@ class GooberWeb(commands.Cog): self.bot.loop.create_task(self.start_web_server()) self.update_clients.start() + async def get_blacklisted_users(self): + blacklisted_ids = os.getenv("BLACKLISTED_USERS", "").split(",") + blacklisted_users = [] + + for user_id in blacklisted_ids: + if not user_id.strip(): + continue + + try: + user = await self.bot.fetch_user(int(user_id)) + blacklisted_users.append({ + "name": f"{user.name}#{user.discriminator}", + "avatar_url": str(user.avatar.url) if user.avatar else str(user.default_avatar.url), + "id": user.id + }) + except discord.NotFound: + blacklisted_users.append({ + "name": f"Unknown User ({user_id})", + "avatar_url": "", + "id": user_id + }) + except discord.HTTPException as e: + print(f"Error fetching user {user_id}: {e}") + continue + + return blacklisted_users + + async def get_enhanced_guild_info(self): + guilds = sorted(self.bot.guilds, key=lambda g: g.member_count, reverse=True) + guild_info = [] + + for guild in guilds: + icon_url = str(guild.icon.url) if guild.icon else "" + guild_info.append({ + "name": guild.name, + "member_count": guild.member_count, + "icon_url": icon_url, + "id": guild.id + }) + + return guild_info + async def start_web_server(self): self.runner = web.AppRunner(self.app) await self.runner.setup() @@ -115,8 +157,8 @@ class GooberWeb(commands.Cog): if os.path.exists("memory.json"): memory_json_size = f"{os.path.getsize('memory.json') / 1024:.2f} KB" - guilds = sorted(self.bot.guilds, key=lambda g: g.member_count, reverse=True) - guild_info = [f"{g.name} ({g.member_count} members)" for g in guilds] + guild_info = await self.get_enhanced_guild_info() + blacklisted_users = await self.get_blacklisted_users() uptime_seconds = int(time.time() - self.start_time) uptime_str = f"{uptime_seconds // 86400}d {(uptime_seconds % 86400) // 3600}h {(uptime_seconds % 3600) // 60}m {uptime_seconds % 60}s" @@ -126,8 +168,10 @@ class GooberWeb(commands.Cog): "cpu_usage": f"{process_cpu}%", "system_cpu": f"{cpu_percent}%", "memory_json_size": memory_json_size, - "guild_count": len(guilds), + "guild_count": len(guild_info), + "bl_count": len(blacklisted_users), "guilds": guild_info, + "blacklisted_users": blacklisted_users, "last_command": self.last_command, "last_command_time": self.last_command_time, "bot_uptime": uptime_str, @@ -158,114 +202,388 @@ class GooberWeb(commands.Cog): async def handle_index(self, request): stats = await self.get_bot_stats() + guild_list_html = "" + for guild in stats['guilds']: + icon_html = f'guild icon' if guild["icon_url"] else '
' + guild_list_html += f""" +
+ {icon_html} +
+
{guild["name"]}
+
{guild["member_count"]} members
+
+
+ """ + blacklisted_users_html = "" + for user in stats['blacklisted_users']: + avatar_html = f'user avatar' if user["avatar_url"] else '
' + blacklisted_users_html += f""" +
+ {avatar_html} +
+
{user["name"]}
+
ID: {user["id"]}
+
+
+ """ + html_content = f""" - - - - goobs central - - - -
-
- RAM: - {stats['ram_usage']} -
-
- CPU: - {stats['cpu_usage']} -
-
- System CPU: - {stats['system_cpu']} -
-
- Latency: - {stats['latency']} -
-
- JSON Size: - {stats['memory_json_size']} -
-
- Uptime: - {stats['bot_uptime']} -
-
- -
-

-
- botvatar - {stats['bot_name']} -
-

-
-

your stupid little goober that learns off other people's messages

-
- -
-
-
Last Command
-
{stats['last_command']}
-
at {stats['last_command_time']}
-
-
Logged into goober central
-
{stats['authenticated']}
-
-
Last generated message
-
{stats['lastmsg']}
-
-
Change song
-
- - -
-
- -
-
Servers ({stats['guild_count']})
-
- {"".join(f'
{guild}
' for guild in stats['guilds'])} -
-
-
- - - + .stat-item {{ + display: flex; + gap: 5px; + color: white; + font-size: 14px; + }} + + .stat-title {{ + font-weight: bold; + color: #ccc; + }} + + .center {{ + text-align: center; + max-width: 800px; + margin: 20px auto; + padding: 0 20px; + }} + + .bot-info {{ + display: flex; + align-items: center; + justify-content: center; + gap: 15px; + margin-bottom: 10px; + }} + + .bot-avatar {{ + width: 80px; + height: 80px; + border-radius: 50%; + border: 3px solid rgb(95, 27, 27); + }} + + hr {{ + border: 1px solid rgb(95, 27, 27); + margin: 20px 0; + }} + + .stat-container-row {{ + display: flex; + justify-content: space-between; + gap: 30px; + max-width: 1200px; + margin: 0 auto; + padding: 0 20px; + }} + + .stat-container {{ + flex: 1; + background-color: #1a1a1a; + padding: 20px; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); + }} + + .guild-item {{ + display: flex; + align-items: center; + gap: 15px; + padding: 10px; + margin: 10px 0; + background-color: #2a2a2a; + border-radius: 5px; + transition: background-color 0.2s; + }} + + .guild-item:hover {{ + background-color: #333; + }} + + .guild-icon {{ + width: 48px; + height: 48px; + border-radius: 50%; + }} + + .guild-icon-placeholder {{ + width: 48px; + height: 48px; + border-radius: 50%; + background-color: #7289da; + display: flex; + align-items: center; + justify-content: center; + color: white; + font-weight: bold; + }} + + .guild-info {{ + display: flex; + flex-direction: column; + }} + + .guild-name {{ + font-weight: bold; + }} + + .guild-members {{ + font-size: 0.8em; + color: #99aab5; + }} + + .blacklisted-user {{ + display: flex; + align-items: center; + gap: 15px; + padding: 10px; + margin: 10px 0; + background-color: #2a2a2a; + border-radius: 5px; + border-left: 4px solid #f04747; + }} + + .user-avatar {{ + width: 48px; + height: 48px; + border-radius: 50%; + }} + + .user-avatar-placeholder {{ + width: 48px; + height: 48px; + border-radius: 50%; + background-color: #7289da; + display: flex; + align-items: center; + justify-content: center; + color: white; + font-weight: bold; + }} + + .user-info {{ + display: flex; + flex-direction: column; + }} + + .user-name {{ + font-weight: bold; + color: #f04747; + }} + + .user-id {{ + font-size: 0.8em; + color: #99aab5; + }} + + input[type="text"] {{ + background-color: #2a2a2a; + color: white; + border: 1px solid #444; + padding: 8px; + border-radius: 4px; + margin-right: 10px; + }} + + button {{ + background-color: rgb(95, 27, 27); + color: white; + border: none; + padding: 8px 15px; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.2s; + }} + + button:hover {{ + background-color: rgb(120, 40, 40); + }} + + #guild-list, #blacklisted-users {{ + max-height: 400px; + overflow-y: auto; + padding-right: 10px; + }} + + #guild-list::-webkit-scrollbar, #blacklisted-users::-webkit-scrollbar {{ + width: 6px; + }} + + #guild-list::-webkit-scrollbar-track, #blacklisted-users::-webkit-scrollbar-track {{ + background: #1a1a1a; + }} + + #guild-list::-webkit-scrollbar-thumb, #blacklisted-users::-webkit-scrollbar-thumb {{ + background: rgb(95, 27, 27); + border-radius: 3px; + }} + + + +
+
+ RAM: + {stats['ram_usage']} +
+
+ CPU: + {stats['cpu_usage']} +
+
+ System CPU: + {stats['system_cpu']} +
+
+ Latency: + {stats['latency']} +
+
+ JSON Size: + {stats['memory_json_size']} +
+
+ Uptime: + {stats['bot_uptime']} +
+
+ +
+

+
+ botvatar + {stats['bot_name']} +
+

+

your stupid little goober that learns off other people's messages

+
+ +
+
+
Last Command
+
{stats['last_command']}
+
at {stats['last_command_time']}
+
+
Logged into goober central
+
{stats['authenticated']}
+
+
Last generated message
+
{stats['lastmsg']}
+
+
Change song
+
+ + +
+
+ +
+
Servers ({stats['guild_count']})
+
+ {guild_list_html} +
+
+
Blacklisted Users ({stats['bl_count']})
+
+ {blacklisted_users_html if stats['blacklisted_users'] else "
No blacklisted users
"} +
+
+
+ + + """ return web.Response(text=html_content, content_type='text/html')