2020-10-28 11:47:39 +00:00
|
|
|
import discord
|
|
|
|
import asyncio
|
2020-10-31 02:03:22 +00:00
|
|
|
import telnet
|
|
|
|
import time
|
2020-10-31 20:05:39 +00:00
|
|
|
import events
|
2020-11-21 12:54:42 +00:00
|
|
|
import os
|
2020-10-28 11:47:39 +00:00
|
|
|
|
2020-10-31 02:03:22 +00:00
|
|
|
from datetime import datetime
|
2020-10-28 11:47:39 +00:00
|
|
|
from discord.ext import commands
|
|
|
|
from checks import *
|
2020-10-31 20:05:39 +00:00
|
|
|
from functions import *
|
2020-10-28 11:47:39 +00:00
|
|
|
|
|
|
|
class Miscellaneous(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@is_dev()
|
2020-10-31 02:03:22 +00:00
|
|
|
@commands.command()
|
2020-10-28 11:47:39 +00:00
|
|
|
async def killbot(self, ctx):
|
|
|
|
em = discord.Embed()
|
|
|
|
em.description = 'Bot offline.'
|
|
|
|
await ctx.send(embed=em)
|
|
|
|
await self.bot.logout()
|
2020-10-28 12:24:24 +00:00
|
|
|
return
|
|
|
|
|
2020-11-24 19:35:48 +00:00
|
|
|
@is_tf_developer()
|
2020-10-31 02:03:22 +00:00
|
|
|
@commands.command()
|
|
|
|
async def telnetconfig(self, ctx, *args):
|
|
|
|
em = discord.Embed()
|
|
|
|
em.title = 'Telnet config'
|
|
|
|
if not args or args[0] in ['reconnect', 'connect']:
|
|
|
|
try:
|
|
|
|
self.bot.telnet_object.connect()
|
|
|
|
except Exception as e:
|
|
|
|
em.description = f'Failed reconnection: {e}'
|
|
|
|
em.colour = 0xFF0000
|
|
|
|
else:
|
|
|
|
em.description = 'Reconnection successful'
|
|
|
|
em.colour = 0x00FF00
|
|
|
|
elif args[0] == 'name':
|
|
|
|
try:
|
2020-10-31 20:05:39 +00:00
|
|
|
self.bot.telnet_object.session.close()
|
2020-10-31 02:03:22 +00:00
|
|
|
self.bot.telnet_object.connect(args[1])
|
2020-10-31 20:05:39 +00:00
|
|
|
events.telnet_username = self.bot.telnet_object.username
|
|
|
|
config = read_json('config')
|
|
|
|
config['TELNET_USERNAME'] = self.bot.telnet_object.username
|
|
|
|
write_json('config', config)
|
2020-10-31 02:03:22 +00:00
|
|
|
except Exception as e:
|
|
|
|
em.description = f'Failed config edit: {e}'
|
|
|
|
em.colour = 0xFF0000
|
|
|
|
else:
|
|
|
|
em.description = 'Configuration successful'
|
|
|
|
em.colour = 0x00FF00
|
|
|
|
|
|
|
|
elif args[0] == 'test':
|
|
|
|
command = ''
|
|
|
|
for x in range(1, len(args)):
|
|
|
|
command += f'{args[x]} '
|
|
|
|
time_sent = str(datetime.utcnow().replace(microsecond=0))[11:]
|
|
|
|
|
|
|
|
self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
|
|
|
|
self.bot.telnet_object.session.read_until(bytes(f'{time_sent} INFO]:', 'ascii'), 2)
|
2020-11-24 19:52:00 +00:00
|
|
|
if ctx.channel == ctx.guild.get_channel(server_chat):
|
2020-11-24 19:46:32 +00:00
|
|
|
self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
|
2020-10-31 02:03:22 +00:00
|
|
|
next_line = self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
|
|
|
|
em.description = f"Response from server: {next_line.decode('utf-8')}"
|
2020-11-24 19:53:33 +00:00
|
|
|
else:
|
|
|
|
em.description = f'Command **{args[0]}** not found.'
|
|
|
|
em.colour = 0xFF0000
|
2020-10-31 02:03:22 +00:00
|
|
|
|
2020-11-24 19:53:33 +00:00
|
|
|
await ctx.send(embed=em)
|
2020-10-31 02:03:22 +00:00
|
|
|
|
|
|
|
@is_dev()
|
|
|
|
@commands.command()
|
2020-10-28 11:47:39 +00:00
|
|
|
async def debug(self, ctx, *, cmd):
|
|
|
|
'Executes a line of code'
|
|
|
|
try:
|
|
|
|
result = eval(cmd)
|
|
|
|
if asyncio.iscoroutine(result):
|
|
|
|
result = await result
|
|
|
|
await ctx.send(f'''```py
|
|
|
|
{result}```''')
|
|
|
|
except Exception as e:
|
|
|
|
await ctx.send(f'''```py
|
|
|
|
{type(e).__name__}: {e}```''')
|
|
|
|
|
|
|
|
def setup(bot):
|
2020-10-28 12:24:24 +00:00
|
|
|
bot.add_cog(Miscellaneous(bot))
|