mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 15:44:57 +00:00
Update checks.py
This commit is contained in:
parent
31dea5a04f
commit
816088b3c7
1 changed files with 102 additions and 79 deletions
181
checks.py
181
checks.py
|
@ -1,84 +1,107 @@
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
|
||||||
import telnet
|
|
||||||
import time
|
|
||||||
import events
|
|
||||||
import os
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from checks import *
|
|
||||||
from functions import *
|
|
||||||
|
|
||||||
class Miscellaneous(commands.Cog):
|
server_liaison = 769659653096472634
|
||||||
def __init__(self, bot):
|
event_host = 769659653096472629
|
||||||
self.bot = bot
|
server_banned = 769659653096472636
|
||||||
|
senior_admin = 769659653129896016
|
||||||
@is_dev()
|
admin = 769659653121900553
|
||||||
@commands.command()
|
master_builder = 769659653121900550
|
||||||
async def killbot(self, ctx):
|
reports_channel_id = 769659654791233585
|
||||||
em = discord.Embed()
|
archived_reports_channel_id = 769659655033978900
|
||||||
em.description = 'Bot offline.'
|
guild_id = 769659653096472627
|
||||||
await ctx.send(embed=em)
|
mentions_channel_id = 769659654027739151
|
||||||
await self.bot.logout()
|
discord_admin = 769659653129896025
|
||||||
return
|
discord_mod = 769659653129896023
|
||||||
|
devs = [114348811995840515, 147765181903011840]
|
||||||
@is_tf_developer()
|
bot_logs_channel_id = 771391406609662013
|
||||||
@commands.command()
|
executive = 769659653129896019
|
||||||
async def telnetconfig(self, ctx, *args):
|
asst_exec = 769659653129896018
|
||||||
em = discord.Embed()
|
developer = 769659653129896017
|
||||||
em.title = 'Telnet config'
|
creative_designer = 771748500576141332
|
||||||
if not args or args[0] in ['reconnect', 'connect']:
|
master_builder = 769659653121900550
|
||||||
try:
|
server_chat = 769843495045169163
|
||||||
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:
|
|
||||||
self.bot.telnet_object.session.close()
|
|
||||||
self.bot.telnet_object.connect(args[1])
|
|
||||||
events.telnet_username = self.bot.telnet_object.username
|
|
||||||
config = read_json('config')
|
|
||||||
config['TELNET_USERNAME'] = self.bot.telnet_object.username
|
|
||||||
write_json('config', config)
|
|
||||||
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)
|
|
||||||
self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
|
|
||||||
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')}"
|
|
||||||
await ctx.send(embed=em)
|
|
||||||
|
|
||||||
|
|
||||||
@is_dev()
|
|
||||||
@commands.command()
|
|
||||||
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):
|
class no_permission(commands.MissingPermissions):
|
||||||
bot.add_cog(Miscellaneous(bot))
|
pass
|
||||||
|
|
||||||
|
def is_staff():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id in [admin, senior_admin]:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_STAFF_MEMBER'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_dev():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
if user.id in devs:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['BOT_DEVELOPER'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_mod_or_has_perms(**permissions):
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id in [discord_mod, discord_admin] or permissions:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_MOD_OR_HAS_PERMS'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_executive():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id in [executive, asst_exec]:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_EXECUTIVE'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
|
def is_tf_developer():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id == developer:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_TOTALFREEDOM_DEVELOPER'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_liaison():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id == server_liaison:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_SERVER_LIAISON'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_creative_designer():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id == creative_designer:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_CREATIVE_DESIGNER'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
def is_senior():
|
||||||
|
def predicate(ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
for role in user.roles:
|
||||||
|
if role.id == senior_admin:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
Loading…
Reference in a new issue