From 2e0c0bb70eb9e5fe34d2f1bbf7b01f58b5df4681 Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Mon, 31 Mar 2025 12:29:54 +0200 Subject: [PATCH] i slept on my shoulder wrong murder me --- bot.py | 1 + cogs/webserver.py | 143 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index baf3ccb..aec0cd0 100644 --- a/bot.py +++ b/bot.py @@ -317,6 +317,7 @@ async def on_ready(): def ping_server(): if ALIVEPING == "false": print(f"{YELLOW}{get_translation(LOCALE, 'pinging_disabled')}{RESET}") + os.environ['gooberauthenticated'] = 'No' return file_info = get_file_info(MEMORY_FILE) payload = { diff --git a/cogs/webserver.py b/cogs/webserver.py index 6083c64..5be9bfe 100644 --- a/cogs/webserver.py +++ b/cogs/webserver.py @@ -8,8 +8,11 @@ import json from datetime import datetime import time import aiohttp +import re from aiohttp import WSMsgType from config import VERSION_URL +import sys +import subprocess class GooberWeb(commands.Cog): def __init__(self, bot): @@ -29,11 +32,23 @@ class GooberWeb(commands.Cog): web.get('/data', self.handle_json_data), web.get('/ws', self.handle_websocket), web.get('/styles.css', self.handle_css), + web.get('/settings', self.handle_settings), + web.post('/update_settings', self.handle_update_settings), + web.post('/restart_bot', self.handle_restart_bot), ]) self.bot.loop.create_task(self.start_web_server()) self.update_clients.start() - + + async def restart_bot(self): + await asyncio.sleep(1) + python = sys.executable + os.execl(python, python, *sys.argv) + + async def handle_restart_bot(self, request): + asyncio.create_task(self.restart_bot()) + return web.Response(text="Bot is restarting...") + async def get_blacklisted_users(self): blacklisted_ids = os.getenv("BLACKLISTED_USERS", "").split(",") blacklisted_users = [] @@ -202,7 +217,133 @@ class GooberWeb(commands.Cog): if os.path.exists("goob/changes.txt"): return web.FileResponse("goob/changes.txt") return web.Response(text="Changelog not found", status=404) + + async def read_env_file(self): + env_vars = {} + try: + with open('.env', 'r') as f: + for line in f: + line = line.strip() + if not line or line.startswith('#') or '=' not in line: + continue + + key, value = line.split('=', 1) + key = key.strip() + if key in ['splashtext', 'DISCORD_BOT_TOKEN']: + continue + + env_vars[key] = value.strip('"\'') + except FileNotFoundError: + print(".env file not found") + return env_vars + + async def handle_settings(self, request): + env_vars = await self.read_env_file() + + # Get config.py variables + config_vars = {} + try: + with open('config.py', 'r') as f: + for line in f: + if line.startswith('VERSION_URL'): + config_vars['VERSION_URL'] = line.split('=', 1)[1].strip().strip('"') + except FileNotFoundError: + pass + + settings_html = """ + + +
+