EmperorFred/twitch_bot/commands/restart.py

26 lines
771 B
Python
Raw Normal View History

2025-12-06 02:21:47 +00:00
import os
import asyncio
from twitchio.ext import commands as twitch_commands
class RestartComponent(twitch_commands.Component):
def __init__(self, bot: twitch_commands.Bot) -> None:
self.bot = bot
@twitch_commands.Component.guard()
def is_moderator(self, ctx: twitch_commands.Context) -> bool:
return ctx.chatter.moderator
@twitch_commands.command(name="restart")
async def restart(self, ctx: twitch_commands.Context):
controller = ctx.bot.restart_controller or None
if not controller:
await ctx.send("Restart controller not available.")
return
await ctx.send("Restarting Twitch bot...")
controller.request()
await asyncio.sleep(0.2)
await ctx.bot.close()