BotManagement: add rfoo server
This commit is contained in:
parent
eba6a289f8
commit
4eb68360ed
@ -2,9 +2,17 @@
|
||||
from formatting import format_table
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
import rfoo
|
||||
from rfoo.utils import rconsole
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class BotManagement(commands.Cog):
|
||||
rfoo_server_thread: Optional[Thread] = None
|
||||
rfoo_server: Optional[rfoo.InetServer] = None
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@ -20,6 +28,32 @@ class BotManagement(commands.Cog):
|
||||
text_table = format_table(((it.guild.name,) for it in self.bot.voice_clients))
|
||||
await ctx.channel.send(text_table)
|
||||
|
||||
@commands.is_owner()
|
||||
@commands.command('rfooStart')
|
||||
async def start(self, ctx: Context):
|
||||
if self.rfoo_server_thread is None:
|
||||
self.rfoo_server = rfoo.InetServer(rconsole.ConsoleHandler, {'bot': self.bot})
|
||||
self.rfoo_server_thread = Thread(target=lambda: self.rfoo_server.start(rfoo.LOOPBACK, 54321))
|
||||
self.rfoo_server_thread.daemon = True
|
||||
self.rfoo_server_thread.start()
|
||||
logger.info('Rfoo thread started by msg')
|
||||
await ctx.send('Rfoo thread started')
|
||||
|
||||
else:
|
||||
await ctx.send('Rfoo thread already started')
|
||||
|
||||
@commands.is_owner()
|
||||
@commands.command('rfooStop')
|
||||
async def stop(self, ctx: Context):
|
||||
if self.rfoo_server_thread is not None:
|
||||
self.rfoo_server.stop()
|
||||
del self.rfoo_server_thread
|
||||
logger.info('Rfoo thread stopped by msg')
|
||||
await ctx.send('Rfoo server stopped')
|
||||
|
||||
else:
|
||||
await ctx.send('Rfoo server already stopped')
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(BotManagement(bot))
|
||||
|
Loading…
x
Reference in New Issue
Block a user