diff --git a/bot.py b/bot.py index 42fcacd..bc15b43 100644 --- a/bot.py +++ b/bot.py @@ -5,6 +5,7 @@ from discord.ext import commands, tasks import asyncio import os, datetime +import sys import logging, logging.handlers import urllib import validators @@ -128,6 +129,22 @@ def predicate(interaction: discord.Interaction): raise discord.app_commands.BotMissingPermissions(missing_permissions=missing_permissions) return discord.app_commands.checks.check(predicate) +@bot.tree.command( + name='restart', + description="Restarts the whole bot, bot maintainer use only!" +) +@discord.app_commands.checks.cooldown(rate=1, per=5) +@bot_has_channel_permissions(permissions=discord.Permissions(send_messages=True)) +async def retart(interaction: discord.Interaction): + if (await bot.is_owner(interaction.user)): + await interaction.response.send_message(f"Restarting Bot! You better be freaking sure about this!") + logger.info("Daddy Initiated Bot Restart....") + await restart_bot() + else: + logger.info("Pleb tried to restart me....") + await interaction.response.send_message(f"Awww look at you, how cute") + + @bot.tree.command( name='play', description="Begin playback of a shoutcast/icecast stream" @@ -626,6 +643,10 @@ async def on_command_error(interaction: discord.Interaction, error): def is_valid_url(url): return validators.url(url) +def restart_bot(): + logger.warning("Red Button Pushed!") + os.execv(sys.executable, ['python'] + sys.argv) + # Find information about the playing station & send that as an embed to the original text channel async def send_song_info(guild_id: int): url = get_state(guild_id, 'current_stream_url')