From c0030b77b063ccc6f854e445a00b4fbca6620760 Mon Sep 17 00:00:00 2001 From: ctih1 Date: Sat, 26 Jul 2025 22:18:39 +0300 Subject: [PATCH] added restart --- assets/cogs/internal/base_commands.py | 16 ++++++++++++++++ updater.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 updater.py diff --git a/assets/cogs/internal/base_commands.py b/assets/cogs/internal/base_commands.py index 63d620c..4792c5a 100644 --- a/assets/cogs/internal/base_commands.py +++ b/assets/cogs/internal/base_commands.py @@ -11,6 +11,9 @@ from modules.settings import instance as settings_manager import requests import psutil import cpuinfo +import sys +import subprocess + settings = settings_manager.settings @@ -170,6 +173,19 @@ class BaseCommands(commands.Cog): await send_message(ctx, embed=embed) + @requires_admin() + @commands.command() + async def restart(self, ctx: commands.Context): + await ctx.send("Restarting...") + os.execv(sys.executable, [sys.executable] + sys.argv) + + @requires_admin() + @commands.command() + async def force_update(self, ctx: commands.Context): + await ctx.send("Forcefully updating...") + subprocess.run([sys.executable, sys.executable, "updater.py"]) + sys.exit() + @requires_admin() @commands.command() async def mem(self, ctx: commands.Context) -> None: diff --git a/updater.py b/updater.py new file mode 100644 index 0000000..29b002d --- /dev/null +++ b/updater.py @@ -0,0 +1,16 @@ +import subprocess +import time +import sys +import os + +def force_update() -> None: + print("Forcefully updating...") + stash = subprocess.run(["git", "stash"], capture_output=True) + print(stash) + pull = subprocess.run(["git", "pull", "origin", "main"], check=True, capture_output=True) + print(pull) + + print("Starting bot") + os.execv(sys.executable, [sys.executable, "bot.py"]) + +force_update() \ No newline at end of file