mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2025-08-06 12:33:22 +00:00
Various formatting
Hopefully this will make the static analysis tool happier
This commit is contained in:
parent
2d2bde604d
commit
866054884a
14 changed files with 202 additions and 147 deletions
|
@ -4,12 +4,13 @@ import discord
|
|||
from discord.ext import commands
|
||||
from functions import get_avatar
|
||||
|
||||
|
||||
class Help(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.bot.remove_command('help')
|
||||
|
||||
@commands.command(aliases=['h','?'])
|
||||
|
||||
@commands.command(aliases=['h', '?'])
|
||||
async def help(self, ctx, page=1):
|
||||
'Displays the help command'
|
||||
em = discord.Embed()
|
||||
|
@ -17,12 +18,12 @@ class Help(commands.Cog):
|
|||
command_list = ''
|
||||
cog_list = [c for c in self.bot.cogs.keys()]
|
||||
page_count = math.ceil(len(cog_list) / 4)
|
||||
|
||||
|
||||
page = int(page)
|
||||
if page > page_count or page<1:
|
||||
if page > page_count or page < 1:
|
||||
await ctx.send(f'Page number \'{page}\' not found.')
|
||||
return
|
||||
|
||||
|
||||
cogs_needed = []
|
||||
for i in range(4):
|
||||
x = i + (int(page) - 1) * 4
|
||||
|
@ -30,7 +31,7 @@ class Help(commands.Cog):
|
|||
cogs_needed.append(cog_list[x])
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
for cog in cogs_needed:
|
||||
command_list = ''
|
||||
for command in self.bot.get_cog(cog).get_commands():
|
||||
|
@ -38,18 +39,20 @@ class Help(commands.Cog):
|
|||
if command.hidden:
|
||||
showcommand = False
|
||||
if command.parent:
|
||||
showcommand = False
|
||||
showcommand = False
|
||||
for check in command.checks:
|
||||
try:
|
||||
check(ctx)
|
||||
except:
|
||||
showcommand = False
|
||||
if showcommand:
|
||||
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
|
||||
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
|
||||
if command_list:
|
||||
em.add_field(name=cog, value=command_list, inline=False)
|
||||
em.set_footer(text=f'Requested by {ctx.message.author}', icon_url=get_avatar(ctx.message.author))
|
||||
em.add_field(name=cog, value=command_list, inline=False)
|
||||
em.set_footer(text=f'Requested by {ctx.message.author}', icon_url=get_avatar(
|
||||
ctx.message.author))
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Help(bot))
|
||||
|
|
|
@ -10,6 +10,7 @@ from discord.ext import commands
|
|||
from checks import *
|
||||
from functions import *
|
||||
|
||||
|
||||
class Miscellaneous(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
@ -22,7 +23,7 @@ class Miscellaneous(commands.Cog):
|
|||
await ctx.send(embed=em)
|
||||
await self.bot.logout()
|
||||
return
|
||||
|
||||
|
||||
@is_tf_developer()
|
||||
@commands.command()
|
||||
async def telnetconfig(self, ctx, *args):
|
||||
|
@ -51,25 +52,29 @@ class Miscellaneous(commands.Cog):
|
|||
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.write(
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
self.bot.telnet_object.session.read_until(
|
||||
bytes(f'{time_sent} INFO]:', 'ascii'), 2)
|
||||
if ctx.channel == ctx.guild.get_channel(server_chat):
|
||||
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)
|
||||
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')}"
|
||||
else:
|
||||
em.description = f'Command **{args[0]}** not found.'
|
||||
em.colour = 0xFF0000
|
||||
|
||||
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@is_dev()
|
||||
@commands.command()
|
||||
async def debug(self, ctx, *, cmd):
|
||||
|
@ -84,5 +89,6 @@ class Miscellaneous(commands.Cog):
|
|||
await ctx.send(f'''```py
|
||||
{type(e).__name__}: {e}```''')
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Miscellaneous(bot))
|
||||
|
|
|
@ -7,11 +7,12 @@ from functions import *
|
|||
|
||||
muted_role_id = 769659653121900546
|
||||
|
||||
|
||||
class Moderation(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.moderator_role_id = 769659653129896023
|
||||
|
||||
|
||||
@commands.command()
|
||||
@commands.has_permissions(kick_members=True)
|
||||
async def kick(self, ctx, user: discord.Member, *, reason="No reason specified"):
|
||||
|
@ -36,7 +37,7 @@ class Moderation(commands.Cog):
|
|||
await ctx.send(embed=discord.Embed(description=f'{user.name} has been unbanned by: {ctx.author.name} for reason: {reason}'))
|
||||
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Banned {user.name} from {ctx.guild.name}")
|
||||
|
||||
@commands.command(aliases=['massdelete','purge'])
|
||||
@commands.command(aliases=['massdelete', 'purge'])
|
||||
@commands.has_permissions(manage_messages=True)
|
||||
async def prune(self, ctx, msgs):
|
||||
"""Purge messages from a channel."""
|
||||
|
@ -50,7 +51,7 @@ class Moderation(commands.Cog):
|
|||
async def mute(self, ctx, member: discord.Member, *, reason=''):
|
||||
"""Mutes a member of the server."""
|
||||
muted_role = ctx.guild.get_role(muted_role_id)
|
||||
await member.add_roles(muted_role, reason = f'{reason} || by {ctx.author.name}')
|
||||
await member.add_roles(muted_role, reason=f'{reason} || by {ctx.author.name}')
|
||||
if reason == '':
|
||||
reason = 'No reason specified'
|
||||
await ctx.send(embed=discord.Embed(description=f'{member} muted by: {ctx.author.name} for: {reason}'))
|
||||
|
@ -61,20 +62,21 @@ class Moderation(commands.Cog):
|
|||
async def unmute(self, ctx, member: discord.Member, *, reason=''):
|
||||
"""Unmutes a member of the server."""
|
||||
muted_role = ctx.guild.get_role(muted_role_id)
|
||||
await member.remove_roles(muted_role, reason = f'{reason} || by {ctx.author.name}')
|
||||
await member.remove_roles(muted_role, reason=f'{reason} || by {ctx.author.name}')
|
||||
await ctx.send(embed=discord.Embed(description=f'{member} unmuted by {ctx.author.name}'))
|
||||
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Unmuted {member} in {ctx.guild.name}')
|
||||
|
||||
|
||||
@commands.command()
|
||||
@commands.has_permissions(manage_roles=True)
|
||||
async def setreaction(self, ctx, role : discord.Role=None, msg : discord.Message=None, emoji=None):
|
||||
if role and msg and emoji :
|
||||
async def setreaction(self, ctx, role: discord.Role = None, msg: discord.Message = None, emoji=None):
|
||||
if role and msg and emoji:
|
||||
await msg.add_reaction(emoji)
|
||||
self.bot.reaction_roles.append([role.id,msg.id,emoji])
|
||||
self.bot.reaction_roles.append([role.id, msg.id, emoji])
|
||||
data = read_json('config')
|
||||
data['reaction_roles'].append([role.id,msg.id,emoji])
|
||||
data['reaction_roles'].append([role.id, msg.id, emoji])
|
||||
print(data['reaction_roles'])
|
||||
write_json('config', data)
|
||||
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Moderation(bot))
|
||||
|
|
|
@ -7,10 +7,11 @@ from datetime import datetime
|
|||
from functions import *
|
||||
from unicode import *
|
||||
|
||||
|
||||
class ServerCommands(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_liaison()
|
||||
async def eventhost(self, ctx, user: discord.Member):
|
||||
|
@ -22,7 +23,7 @@ class ServerCommands(commands.Cog):
|
|||
else:
|
||||
await user.add_roles(eventhostrole)
|
||||
await ctx.send(f'```Succesfully added {eventhostrole.name} to {user.name}```')
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_creative_designer()
|
||||
async def masterbuilder(self, ctx, user: discord.Member):
|
||||
|
@ -34,7 +35,7 @@ class ServerCommands(commands.Cog):
|
|||
else:
|
||||
await user.add_roles(master_builder_role)
|
||||
await ctx.send(f'```Succesfully added {master_builder_role.name} to {user.name}```')
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_staff()
|
||||
async def serverban(self, ctx, user: discord.Member):
|
||||
|
@ -46,7 +47,7 @@ class ServerCommands(commands.Cog):
|
|||
else:
|
||||
await user.add_roles(serverbannedrole)
|
||||
await ctx.send(f'Added Server Banned role to {user.name}')
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_staff()
|
||||
async def start(self, ctx):
|
||||
|
@ -55,23 +56,23 @@ class ServerCommands(commands.Cog):
|
|||
try:
|
||||
attempt = hit_endpoint('start')
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description='Something went wrong'
|
||||
em.description = 'Something went wrong'
|
||||
print(f'Error while starting server: {e}')
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
if 'error' in attempt.lower():
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description=f'{attempt}'
|
||||
em.description = f'{attempt}'
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
em.title = 'Success'
|
||||
em.colour = 0x00FF00
|
||||
em.description = f'{attempt}'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command()
|
||||
async def uptime(self, ctx):
|
||||
"Returns the uptime of the VPS"
|
||||
|
@ -79,7 +80,7 @@ class ServerCommands(commands.Cog):
|
|||
em.title = 'VPS Uptime Information'
|
||||
em.description = hit_endpoint('uptime')
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_staff()
|
||||
async def stop(self, ctx):
|
||||
|
@ -88,23 +89,23 @@ class ServerCommands(commands.Cog):
|
|||
try:
|
||||
attempt = hit_endpoint('stop')
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description='Something went wrong'
|
||||
em.description = 'Something went wrong'
|
||||
print(f'Error while stopping server: {e}')
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
if 'error' in attempt.lower():
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description=f'{attempt}'
|
||||
em.description = f'{attempt}'
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
em.title = 'Success'
|
||||
em.colour = 0x00FF00
|
||||
em.description = f'{attempt}'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command(aliases=['adminconsole', 'ac'])
|
||||
@is_staff()
|
||||
async def telnet(self, ctx, *args):
|
||||
|
@ -114,17 +115,19 @@ class ServerCommands(commands.Cog):
|
|||
for arg in args:
|
||||
command += f'{arg} '
|
||||
try:
|
||||
if args[0] in ['mute', 'stfu', 'gtfo', 'ban', 'unban', 'unmute', 'smite', 'noob', 'tban', 'tempban', 'warn', 'mv', 'kick', 'cc','say']:
|
||||
self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
|
||||
if args[0] in ['mute', 'stfu', 'gtfo', 'ban', 'unban', 'unmute', 'smite', 'noob', 'tban', 'tempban', 'warn', 'mv', 'kick', 'cc', 'say']:
|
||||
self.bot.telnet_object.session.write(
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
elif args[0] == 'slconfig':
|
||||
if args[1] not in ['add', 'remove']:
|
||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||
else:
|
||||
self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
|
||||
self.bot.telnet_object.session.write(
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
else:
|
||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description = f'{e}'
|
||||
await ctx.send(embed=em)
|
||||
|
@ -133,7 +136,7 @@ class ServerCommands(commands.Cog):
|
|||
em.colour = 0x00FF00
|
||||
em.description = 'Command sent.'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_senior()
|
||||
async def kill(self, ctx):
|
||||
|
@ -142,16 +145,16 @@ class ServerCommands(commands.Cog):
|
|||
try:
|
||||
attempt = hit_endpoint('kill')
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description='Something went wrong'
|
||||
em.description = 'Something went wrong'
|
||||
print(f'Error while killing server: {e}')
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
if 'error' in attempt.lower():
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description='{attempt}'
|
||||
em.description = '{attempt}'
|
||||
print(f'Error while killing server: {e}')
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
|
@ -159,19 +162,19 @@ class ServerCommands(commands.Cog):
|
|||
em.colour = 0x00FF00
|
||||
em.description = f'{attempt}'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_staff()
|
||||
async def restart(self, ctx):
|
||||
'Restarts the server'
|
||||
em = discord.Embed()
|
||||
try:
|
||||
self.bot.telnet_object.session.write(bytes('restart', 'ascii') + b"\r\n")
|
||||
self.bot.telnet_object.session.write(
|
||||
bytes('restart', 'ascii') + b"\r\n")
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description='Something went wrong'
|
||||
em.description = 'Something went wrong'
|
||||
print(f'Error while restarting server: {e}')
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
|
@ -179,17 +182,18 @@ class ServerCommands(commands.Cog):
|
|||
em.colour = 0x00FF00
|
||||
em.description = 'Server restarting.'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_senior()
|
||||
async def console(self, ctx,*, command):
|
||||
async def console(self, ctx, *, command):
|
||||
'Send a command as console'
|
||||
'''await ctx.send(f'```:[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: {ctx.author.name} issued server command: /{command}```')'''
|
||||
em = discord.Embed()
|
||||
try:
|
||||
self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
|
||||
self.bot.telnet_object.session.write(
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
except Exception as e:
|
||||
em.title='Command error'
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
em.description = f'{e}'
|
||||
await ctx.send(embed=em)
|
||||
|
@ -198,13 +202,14 @@ class ServerCommands(commands.Cog):
|
|||
em.colour = 0x00FF00
|
||||
em.description = 'Command sent.'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command(aliases=['status'])
|
||||
async def state(self, ctx):
|
||||
'Gets the current status of the Server'
|
||||
em = discord.Embed()
|
||||
try:
|
||||
requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||
try:
|
||||
requests.get(
|
||||
"http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||
except:
|
||||
em.description = 'Server is offline'
|
||||
em.colour = 0xFF0000
|
||||
|
@ -212,14 +217,15 @@ class ServerCommands(commands.Cog):
|
|||
em.description = 'Server is online'
|
||||
em.colour = 0x00FF00
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
@commands.command(name='list')
|
||||
async def online(self, ctx):
|
||||
'Gives a list of online players.'
|
||||
em = discord.Embed()
|
||||
em.title = "Player List"
|
||||
try:
|
||||
json = requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||
try:
|
||||
json = requests.get(
|
||||
"http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||
if json["online"] == 0:
|
||||
em.description = "There are no online players"
|
||||
else:
|
||||
|
@ -230,24 +236,27 @@ class ServerCommands(commands.Cog):
|
|||
rank = rank.split('_')
|
||||
for word in range(len(rank)):
|
||||
rank[word] = rank[word].capitalize()
|
||||
em = format_list_entry(em, json[rank], f'{" ".join(rank)}')
|
||||
|
||||
em = format_list_entry(
|
||||
em, json[rank], f'{" ".join(rank)}')
|
||||
|
||||
except:
|
||||
em.description = 'Server is offline'
|
||||
await ctx.send(embed=em)
|
||||
|
||||
@commands.command()
|
||||
async def ip(self, ctx):
|
||||
'Returns the server IP'
|
||||
await ctx.send(embed=discord.Embed(description='play.totalfreedom.me',title='Server IP'))
|
||||
#pass #discordSRV responds already.
|
||||
|
||||
await ctx.send(embed=discord.Embed(description='play.totalfreedom.me', title='Server IP'))
|
||||
# pass #discordSRV responds already.
|
||||
|
||||
@commands.command()
|
||||
@is_staff()
|
||||
async def archivereports(self, ctx):
|
||||
"""Archive all in-game reports older than 24 hours"""
|
||||
count = 0
|
||||
reports_channel = self.bot.get_channel(reports_channel_id)
|
||||
archived_reports_channel = self.bot.get_channel(archived_reports_channel_id)
|
||||
archived_reports_channel = self.bot.get_channel(
|
||||
archived_reports_channel_id)
|
||||
await ctx.channel.trigger_typing()
|
||||
async for report in reports_channel.history(limit=100):
|
||||
try:
|
||||
|
@ -261,7 +270,7 @@ class ServerCommands(commands.Cog):
|
|||
await archived_reports_channel.send("Message archived because it is older than 24 hours", embed=embed)
|
||||
count += 1
|
||||
await ctx.send("Archived **{}** reports that are older than 24 hours".format(count))
|
||||
|
||||
|
||||
@commands.command()
|
||||
@is_mod_or_has_perms()
|
||||
async def fixreports(self, ctx):
|
||||
|
@ -275,5 +284,6 @@ class ServerCommands(commands.Cog):
|
|||
fixed += 1
|
||||
await ctx.send(f'Fixed **{fixed}** reports')
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(ServerCommands(bot))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue