Update checks.py

This commit is contained in:
Elmon11 2020-11-24 20:43:27 +01:00 committed by GitHub
parent a9d6e1d0f7
commit 31dea5a04f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

164
checks.py
View file

@ -1,106 +1,84 @@
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 *
server_liaison = 769659653096472634 class Miscellaneous(commands.Cog):
event_host = 769659653096472629 def __init__(self, bot):
server_banned = 769659653096472636 self.bot = bot
senior_admin = 769659653129896016
admin = 769659653121900553
master_builder = 769659653121900550
reports_channel_id = 769659654791233585
archived_reports_channel_id = 769659655033978900
guild_id = 769659653096472627
mentions_channel_id = 769659654027739151
discord_admin = 769659653129896025
discord_mod = 769659653129896023
devs = [114348811995840515, 147765181903011840]
bot_logs_channel_id = 771391406609662013
executive = 769659653129896019
asst_exec = 769659653129896018
developer = 769659653129896017
creative_designer = 771748500576141332
master_builder = 769659653121900550
class no_permission(commands.MissingPermissions): @is_dev()
pass @commands.command()
async def killbot(self, ctx):
em = discord.Embed()
em.description = 'Bot offline.'
await ctx.send(embed=em)
await self.bot.logout()
return
def is_staff(): @is_tf_developer()
def predicate(ctx): @commands.command()
user = ctx.message.author async def telnetconfig(self, ctx, *args):
for role in user.roles: em = discord.Embed()
if role.id in [admin, senior_admin]: em.title = 'Telnet config'
return True 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: else:
raise no_permission(['IS_STAFF_MEMBER']) em.description = 'Reconnection successful'
return commands.check(predicate) em.colour = 0x00FF00
elif args[0] == 'name':
def is_dev(): try:
def predicate(ctx): self.bot.telnet_object.session.close()
user = ctx.message.author self.bot.telnet_object.connect(args[1])
if user.id in devs: events.telnet_username = self.bot.telnet_object.username
return True 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: else:
raise no_permission(['BOT_DEVELOPER']) em.description = 'Configuration successful'
return commands.check(predicate) em.colour = 0x00FF00
def is_mod_or_has_perms(**permissions): elif args[0] == 'test':
def predicate(ctx): command = ''
user = ctx.message.author for x in range(1, len(args)):
for role in user.roles: command += f'{args[x]} '
if role.id in [discord_mod, discord_admin] or permissions: time_sent = str(datetime.utcnow().replace(microsecond=0))[11:]
return True
else:
raise no_permission(['IS_MOD_OR_HAS_PERMS'])
return commands.check(predicate)
def is_executive(): self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
def predicate(ctx): self.bot.telnet_object.session.read_until(bytes(f'{time_sent} INFO]:', 'ascii'), 2)
user = ctx.message.author self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
for role in user.roles: next_line = self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
if role.id in [executive, asst_exec]: em.description = f"Response from server: {next_line.decode('utf-8')}"
return True await ctx.send(embed=em)
else:
raise no_permission(['IS_EXECUTIVE'])
return commands.check(predicate)
def is_tf_developer(): @is_dev()
def predicate(ctx): @commands.command()
user = ctx.message.author async def debug(self, ctx, *, cmd):
for role in user.roles: 'Executes a line of code'
if role.id == developer: try:
return True result = eval(cmd)
else: if asyncio.iscoroutine(result):
raise no_permission(['IS_TOTALFREEDOM_DEVELOPER']) result = await result
return commands.check(predicate) await ctx.send(f'''```py
{result}```''')
except Exception as e:
await ctx.send(f'''```py
{type(e).__name__}: {e}```''')
def is_liaison(): def setup(bot):
def predicate(ctx): bot.add_cog(Miscellaneous(bot))
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)