mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 23:54:58 +00:00
Merge pull request #2 from AtlasMediaGroup/formatting
Various formatting
This commit is contained in:
commit
620fdf0849
14 changed files with 202 additions and 147 deletions
4
.github/workflows/codacy-analysis.yml
vendored
4
.github/workflows/codacy-analysis.yml
vendored
|
@ -10,9 +10,9 @@ name: Codacy Security Scan
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
codacy-security-scan:
|
codacy-security-scan:
|
||||||
|
|
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
|
@ -13,12 +13,12 @@ name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '29 1 * * 1'
|
- cron: "29 1 * * 1"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
|
@ -28,7 +28,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'python' ]
|
language: ["python"]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
# Learn more:
|
# Learn more:
|
||||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
|
@ -21,9 +21,11 @@ creative_designer = 771748500576141332
|
||||||
master_builder = 769659653121900550
|
master_builder = 769659653121900550
|
||||||
server_chat = 769843495045169163
|
server_chat = 769843495045169163
|
||||||
|
|
||||||
|
|
||||||
class no_permission(commands.MissingPermissions):
|
class no_permission(commands.MissingPermissions):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def is_staff():
|
def is_staff():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -34,6 +36,7 @@ def is_staff():
|
||||||
raise no_permission(['IS_STAFF_MEMBER'])
|
raise no_permission(['IS_STAFF_MEMBER'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_dev():
|
def is_dev():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -43,6 +46,7 @@ def is_dev():
|
||||||
raise no_permission(['BOT_DEVELOPER'])
|
raise no_permission(['BOT_DEVELOPER'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_mod_or_has_perms(**permissions):
|
def is_mod_or_has_perms(**permissions):
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -53,6 +57,7 @@ def is_mod_or_has_perms(**permissions):
|
||||||
raise no_permission(['IS_MOD_OR_HAS_PERMS'])
|
raise no_permission(['IS_MOD_OR_HAS_PERMS'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_executive():
|
def is_executive():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -74,6 +79,7 @@ def is_tf_developer():
|
||||||
raise no_permission(['IS_TOTALFREEDOM_DEVELOPER'])
|
raise no_permission(['IS_TOTALFREEDOM_DEVELOPER'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_liaison():
|
def is_liaison():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -84,6 +90,7 @@ def is_liaison():
|
||||||
raise no_permission(['IS_SERVER_LIAISON'])
|
raise no_permission(['IS_SERVER_LIAISON'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_creative_designer():
|
def is_creative_designer():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -94,6 +101,7 @@ def is_creative_designer():
|
||||||
raise no_permission(['IS_CREATIVE_DESIGNER'])
|
raise no_permission(['IS_CREATIVE_DESIGNER'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_senior():
|
def is_senior():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
|
|
@ -4,12 +4,13 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from functions import get_avatar
|
from functions import get_avatar
|
||||||
|
|
||||||
|
|
||||||
class Help(commands.Cog):
|
class Help(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.bot.remove_command('help')
|
self.bot.remove_command('help')
|
||||||
|
|
||||||
@commands.command(aliases=['h','?'])
|
@commands.command(aliases=['h', '?'])
|
||||||
async def help(self, ctx, page=1):
|
async def help(self, ctx, page=1):
|
||||||
'Displays the help command'
|
'Displays the help command'
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
|
@ -19,7 +20,7 @@ class Help(commands.Cog):
|
||||||
page_count = math.ceil(len(cog_list) / 4)
|
page_count = math.ceil(len(cog_list) / 4)
|
||||||
|
|
||||||
page = int(page)
|
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.')
|
await ctx.send(f'Page number \'{page}\' not found.')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -48,8 +49,10 @@ class Help(commands.Cog):
|
||||||
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
|
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
|
||||||
if command_list:
|
if command_list:
|
||||||
em.add_field(name=cog, value=command_list, inline=False)
|
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.set_footer(text=f'Requested by {ctx.message.author}', icon_url=get_avatar(
|
||||||
|
ctx.message.author))
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Help(bot))
|
bot.add_cog(Help(bot))
|
||||||
|
|
|
@ -10,6 +10,7 @@ from discord.ext import commands
|
||||||
from checks import *
|
from checks import *
|
||||||
from functions import *
|
from functions import *
|
||||||
|
|
||||||
|
|
||||||
class Miscellaneous(commands.Cog):
|
class Miscellaneous(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -58,11 +59,15 @@ class Miscellaneous(commands.Cog):
|
||||||
command += f'{args[x]} '
|
command += f'{args[x]} '
|
||||||
time_sent = str(datetime.utcnow().replace(microsecond=0))[11:]
|
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.write(
|
||||||
self.bot.telnet_object.session.read_until(bytes(f'{time_sent} INFO]:', 'ascii'), 2)
|
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):
|
if ctx.channel == ctx.guild.get_channel(server_chat):
|
||||||
self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
|
self.bot.telnet_object.session.read_until(
|
||||||
next_line = self.bot.telnet_object.session.read_until(bytes('\r\n', 'ascii'), 2)
|
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')}"
|
em.description = f"Response from server: {next_line.decode('utf-8')}"
|
||||||
else:
|
else:
|
||||||
em.description = f'Command **{args[0]}** not found.'
|
em.description = f'Command **{args[0]}** not found.'
|
||||||
|
@ -84,5 +89,6 @@ class Miscellaneous(commands.Cog):
|
||||||
await ctx.send(f'''```py
|
await ctx.send(f'''```py
|
||||||
{type(e).__name__}: {e}```''')
|
{type(e).__name__}: {e}```''')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Miscellaneous(bot))
|
bot.add_cog(Miscellaneous(bot))
|
||||||
|
|
|
@ -7,6 +7,7 @@ from functions import *
|
||||||
|
|
||||||
muted_role_id = 769659653121900546
|
muted_role_id = 769659653121900546
|
||||||
|
|
||||||
|
|
||||||
class Moderation(commands.Cog):
|
class Moderation(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -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}'))
|
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}")
|
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)
|
@commands.has_permissions(manage_messages=True)
|
||||||
async def prune(self, ctx, msgs):
|
async def prune(self, ctx, msgs):
|
||||||
"""Purge messages from a channel."""
|
"""Purge messages from a channel."""
|
||||||
|
@ -50,7 +51,7 @@ class Moderation(commands.Cog):
|
||||||
async def mute(self, ctx, member: discord.Member, *, reason=''):
|
async def mute(self, ctx, member: discord.Member, *, reason=''):
|
||||||
"""Mutes a member of the server."""
|
"""Mutes a member of the server."""
|
||||||
muted_role = ctx.guild.get_role(muted_role_id)
|
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 == '':
|
if reason == '':
|
||||||
reason = 'No reason specified'
|
reason = 'No reason specified'
|
||||||
await ctx.send(embed=discord.Embed(description=f'{member} muted by: {ctx.author.name} for: {reason}'))
|
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=''):
|
async def unmute(self, ctx, member: discord.Member, *, reason=''):
|
||||||
"""Unmutes a member of the server."""
|
"""Unmutes a member of the server."""
|
||||||
muted_role = ctx.guild.get_role(muted_role_id)
|
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}'))
|
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}')
|
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Unmuted {member} in {ctx.guild.name}')
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.has_permissions(manage_roles=True)
|
@commands.has_permissions(manage_roles=True)
|
||||||
async def setreaction(self, ctx, role : discord.Role=None, msg : discord.Message=None, emoji=None):
|
async def setreaction(self, ctx, role: discord.Role = None, msg: discord.Message = None, emoji=None):
|
||||||
if role and msg and emoji :
|
if role and msg and emoji:
|
||||||
await msg.add_reaction(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 = 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'])
|
print(data['reaction_roles'])
|
||||||
write_json('config', data)
|
write_json('config', data)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Moderation(bot))
|
bot.add_cog(Moderation(bot))
|
||||||
|
|
|
@ -7,6 +7,7 @@ from datetime import datetime
|
||||||
from functions import *
|
from functions import *
|
||||||
from unicode import *
|
from unicode import *
|
||||||
|
|
||||||
|
|
||||||
class ServerCommands(commands.Cog):
|
class ServerCommands(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -55,16 +56,16 @@ class ServerCommands(commands.Cog):
|
||||||
try:
|
try:
|
||||||
attempt = hit_endpoint('start')
|
attempt = hit_endpoint('start')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description='Something went wrong'
|
em.description = 'Something went wrong'
|
||||||
print(f'Error while starting server: {e}')
|
print(f'Error while starting server: {e}')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
if 'error' in attempt.lower():
|
if 'error' in attempt.lower():
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description=f'{attempt}'
|
em.description = f'{attempt}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
em.title = 'Success'
|
em.title = 'Success'
|
||||||
|
@ -88,16 +89,16 @@ class ServerCommands(commands.Cog):
|
||||||
try:
|
try:
|
||||||
attempt = hit_endpoint('stop')
|
attempt = hit_endpoint('stop')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description='Something went wrong'
|
em.description = 'Something went wrong'
|
||||||
print(f'Error while stopping server: {e}')
|
print(f'Error while stopping server: {e}')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
if 'error' in attempt.lower():
|
if 'error' in attempt.lower():
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description=f'{attempt}'
|
em.description = f'{attempt}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
em.title = 'Success'
|
em.title = 'Success'
|
||||||
|
@ -114,17 +115,19 @@ class ServerCommands(commands.Cog):
|
||||||
for arg in args:
|
for arg in args:
|
||||||
command += f'{arg} '
|
command += f'{arg} '
|
||||||
try:
|
try:
|
||||||
if args[0] in ['mute', 'stfu', 'gtfo', 'ban', 'unban', 'unmute', 'smite', 'noob', 'tban', 'tempban', 'warn', 'mv', 'kick', 'cc','say']:
|
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")
|
self.bot.telnet_object.session.write(
|
||||||
|
bytes(command, 'ascii') + b"\r\n")
|
||||||
elif args[0] == 'slconfig':
|
elif args[0] == 'slconfig':
|
||||||
if args[1] not in ['add', 'remove']:
|
if args[1] not in ['add', 'remove']:
|
||||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||||
else:
|
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:
|
else:
|
||||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description = f'{e}'
|
em.description = f'{e}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
@ -142,16 +145,16 @@ class ServerCommands(commands.Cog):
|
||||||
try:
|
try:
|
||||||
attempt = hit_endpoint('kill')
|
attempt = hit_endpoint('kill')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description='Something went wrong'
|
em.description = 'Something went wrong'
|
||||||
print(f'Error while killing server: {e}')
|
print(f'Error while killing server: {e}')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
if 'error' in attempt.lower():
|
if 'error' in attempt.lower():
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description='{attempt}'
|
em.description = '{attempt}'
|
||||||
print(f'Error while killing server: {e}')
|
print(f'Error while killing server: {e}')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
|
@ -160,18 +163,18 @@ class ServerCommands(commands.Cog):
|
||||||
em.description = f'{attempt}'
|
em.description = f'{attempt}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_staff()
|
@is_staff()
|
||||||
async def restart(self, ctx):
|
async def restart(self, ctx):
|
||||||
'Restarts the server'
|
'Restarts the server'
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description='Something went wrong'
|
em.description = 'Something went wrong'
|
||||||
print(f'Error while restarting server: {e}')
|
print(f'Error while restarting server: {e}')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
else:
|
else:
|
||||||
|
@ -182,14 +185,15 @@ class ServerCommands(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_senior()
|
@is_senior()
|
||||||
async def console(self, ctx,*, command):
|
async def console(self, ctx, *, command):
|
||||||
'Send a command as console'
|
'Send a command as console'
|
||||||
'''await ctx.send(f'```:[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: {ctx.author.name} issued server command: /{command}```')'''
|
'''await ctx.send(f'```:[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: {ctx.author.name} issued server command: /{command}```')'''
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
em.title='Command error'
|
em.title = 'Command error'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
em.description = f'{e}'
|
em.description = f'{e}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
@ -204,7 +208,8 @@ class ServerCommands(commands.Cog):
|
||||||
'Gets the current status of the Server'
|
'Gets the current status of the Server'
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
try:
|
try:
|
||||||
requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
requests.get(
|
||||||
|
"http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||||
except:
|
except:
|
||||||
em.description = 'Server is offline'
|
em.description = 'Server is offline'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
|
@ -219,7 +224,8 @@ class ServerCommands(commands.Cog):
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
em.title = "Player List"
|
em.title = "Player List"
|
||||||
try:
|
try:
|
||||||
json = requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
json = requests.get(
|
||||||
|
"http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
|
||||||
if json["online"] == 0:
|
if json["online"] == 0:
|
||||||
em.description = "There are no online players"
|
em.description = "There are no online players"
|
||||||
else:
|
else:
|
||||||
|
@ -230,16 +236,18 @@ class ServerCommands(commands.Cog):
|
||||||
rank = rank.split('_')
|
rank = rank.split('_')
|
||||||
for word in range(len(rank)):
|
for word in range(len(rank)):
|
||||||
rank[word] = rank[word].capitalize()
|
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:
|
except:
|
||||||
em.description = 'Server is offline'
|
em.description = 'Server is offline'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def ip(self, ctx):
|
async def ip(self, ctx):
|
||||||
'Returns the server IP'
|
'Returns the server IP'
|
||||||
await ctx.send(embed=discord.Embed(description='play.totalfreedom.me',title='Server IP'))
|
await ctx.send(embed=discord.Embed(description='play.totalfreedom.me', title='Server IP'))
|
||||||
#pass #discordSRV responds already.
|
# pass #discordSRV responds already.
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_staff()
|
@is_staff()
|
||||||
|
@ -247,7 +255,8 @@ class ServerCommands(commands.Cog):
|
||||||
"""Archive all in-game reports older than 24 hours"""
|
"""Archive all in-game reports older than 24 hours"""
|
||||||
count = 0
|
count = 0
|
||||||
reports_channel = self.bot.get_channel(reports_channel_id)
|
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()
|
await ctx.channel.trigger_typing()
|
||||||
async for report in reports_channel.history(limit=100):
|
async for report in reports_channel.history(limit=100):
|
||||||
try:
|
try:
|
||||||
|
@ -275,5 +284,6 @@ class ServerCommands(commands.Cog):
|
||||||
fixed += 1
|
fixed += 1
|
||||||
await ctx.send(f'Fixed **{fixed}** reports')
|
await ctx.send(f'Fixed **{fixed}** reports')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(ServerCommands(bot))
|
bot.add_cog(ServerCommands(bot))
|
||||||
|
|
26
events.py
26
events.py
|
@ -18,6 +18,7 @@ telnet_username = "root"
|
||||||
telnet_password = "root"
|
telnet_password = "root"
|
||||||
print = logscript.logging.getLogger().critical
|
print = logscript.logging.getLogger().critical
|
||||||
|
|
||||||
|
|
||||||
class Events(commands.Cog):
|
class Events(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -31,7 +32,8 @@ class Events(commands.Cog):
|
||||||
telnet_password = config['TELNET_PASSWORD']
|
telnet_password = config['TELNET_PASSWORD']
|
||||||
|
|
||||||
self.bot.reaction_roles = []
|
self.bot.reaction_roles = []
|
||||||
self.bot.telnet_object = telnet(telnet_ip, telnet_port, telnet_username, telnet_password)
|
self.bot.telnet_object = telnet(
|
||||||
|
telnet_ip, telnet_port, telnet_username, telnet_password)
|
||||||
self.bot.telnet_object.connect()
|
self.bot.telnet_object.connect()
|
||||||
|
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [TELNET] Bot logged into Telnet as: {self.bot.telnet_object.username}')
|
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [TELNET] Bot logged into Telnet as: {self.bot.telnet_object.username}')
|
||||||
|
@ -89,21 +91,24 @@ class Events(commands.Cog):
|
||||||
if before.guild.id != guild_id:
|
if before.guild.id != guild_id:
|
||||||
return
|
return
|
||||||
users = removed_user_mentions(before.mentions, after.mentions)
|
users = removed_user_mentions(before.mentions, after.mentions)
|
||||||
roles = removed_role_mentions(before.role_mentions, after.role_mentions)
|
roles = removed_role_mentions(
|
||||||
|
before.role_mentions, after.role_mentions)
|
||||||
if users:
|
if users:
|
||||||
users = ", ".join([str(member) for member in users])
|
users = ", ".join([str(member) for member in users])
|
||||||
if roles:
|
if roles:
|
||||||
roles = ", ".join([role.name for role in roles])
|
roles = ", ".join([role.name for role in roles])
|
||||||
if not users and not roles:
|
if not users and not roles:
|
||||||
return
|
return
|
||||||
embed = discord.Embed(description="In {}".format(before.channel.mention))
|
embed = discord.Embed(
|
||||||
|
description="In {}".format(before.channel.mention))
|
||||||
if users:
|
if users:
|
||||||
embed.add_field(name="Users", value=users, inline=True)
|
embed.add_field(name="Users", value=users, inline=True)
|
||||||
if roles:
|
if roles:
|
||||||
embed.add_field(name="Roles", value=roles, inline=True)
|
embed.add_field(name="Roles", value=roles, inline=True)
|
||||||
embed.color = 0xFF0000
|
embed.color = 0xFF0000
|
||||||
embed.title = "Message Edit"
|
embed.title = "Message Edit"
|
||||||
embed.set_footer(text=str(before.author), icon_url=get_avatar(before.author))
|
embed.set_footer(text=str(before.author),
|
||||||
|
icon_url=get_avatar(before.author))
|
||||||
channel = before.guild.get_channel(mentions_channel_id)
|
channel = before.guild.get_channel(mentions_channel_id)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
|
@ -121,14 +126,16 @@ class Events(commands.Cog):
|
||||||
roles = ", ".join([role.name for role in message.role_mentions])
|
roles = ", ".join([role.name for role in message.role_mentions])
|
||||||
if not users and not roles:
|
if not users and not roles:
|
||||||
return
|
return
|
||||||
embed = discord.Embed(description="In {}".format(message.channel.mention))
|
embed = discord.Embed(
|
||||||
|
description="In {}".format(message.channel.mention))
|
||||||
if users is not None:
|
if users is not None:
|
||||||
embed.add_field(name="Users", value=users, inline=True)
|
embed.add_field(name="Users", value=users, inline=True)
|
||||||
if roles is not None:
|
if roles is not None:
|
||||||
embed.add_field(name="Roles", value=roles, inline=True)
|
embed.add_field(name="Roles", value=roles, inline=True)
|
||||||
embed.color = 0xFF0000
|
embed.color = 0xFF0000
|
||||||
embed.title = "Message Deletion"
|
embed.title = "Message Deletion"
|
||||||
embed.set_footer(text=str(message.author), icon_url=get_avatar(message.author))
|
embed.set_footer(text=str(message.author),
|
||||||
|
icon_url=get_avatar(message.author))
|
||||||
channel = message.guild.get_channel(mentions_channel_id)
|
channel = message.guild.get_channel(mentions_channel_id)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
|
@ -145,7 +152,8 @@ class Events(commands.Cog):
|
||||||
async def on_command_completion(self, ctx):
|
async def on_command_completion(self, ctx):
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Commands] {ctx.author} (ID: {ctx.author.id}) ran: {ctx.message.content} in guild: {ctx.guild.name}')
|
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Commands] {ctx.author} (ID: {ctx.author.id}) ran: {ctx.message.content} in guild: {ctx.guild.name}')
|
||||||
bot_logs_channel = self.bot.get_channel(bot_logs_channel_id)
|
bot_logs_channel = self.bot.get_channel(bot_logs_channel_id)
|
||||||
log = discord.Embed(title='Logging', description=f'{ctx.author} (ID: {ctx.author.id}) ran: {ctx.message.content}', colour=0xA84300)
|
log = discord.Embed(
|
||||||
|
title='Logging', description=f'{ctx.author} (ID: {ctx.author.id}) ran: {ctx.message.content}', colour=0xA84300)
|
||||||
await bot_logs_channel.send(embed=log)
|
await bot_logs_channel.send(embed=log)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
|
@ -169,7 +177,8 @@ class Events(commands.Cog):
|
||||||
await report.add_reaction(clipboard)
|
await report.add_reaction(clipboard)
|
||||||
elif payload.emoji.name == confirm:
|
elif payload.emoji.name == confirm:
|
||||||
embed = report.embeds[0]
|
embed = report.embeds[0]
|
||||||
archived_reports_channel = self.bot.get_channel(archived_reports_channel_id)
|
archived_reports_channel = self.bot.get_channel(
|
||||||
|
archived_reports_channel_id)
|
||||||
await report.delete()
|
await report.delete()
|
||||||
await archived_reports_channel.send("Handled by " + guild.get_member(payload.user_id).mention, embed=embed)
|
await archived_reports_channel.send("Handled by " + guild.get_member(payload.user_id).mention, embed=embed)
|
||||||
|
|
||||||
|
@ -182,5 +191,6 @@ class Events(commands.Cog):
|
||||||
if msg_id == payload.message_id and emoji == str(payload.emoji.name):
|
if msg_id == payload.message_id and emoji == str(payload.emoji.name):
|
||||||
await self.bot.get_guild(payload.guild_id).get_member(payload.user_id).remove_roles(self.bot.get_guild(payload.guild_id).get_role(role_id), reason='reaction')
|
await self.bot.get_guild(payload.guild_id).get_member(payload.user_id).remove_roles(self.bot.get_guild(payload.guild_id).get_role(role_id), reason='reaction')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Events(bot))
|
bot.add_cog(Events(bot))
|
||||||
|
|
16
functions.py
16
functions.py
|
@ -5,16 +5,20 @@ import requests
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from checks import *
|
from checks import *
|
||||||
|
|
||||||
|
|
||||||
def format_list_entry(embed, list, name):
|
def format_list_entry(embed, list, name):
|
||||||
embed.add_field(name="{} ({})".format(name, len(list)), value=", ".join(list), inline=False)
|
embed.add_field(name="{} ({})".format(name, len(list)),
|
||||||
|
value=", ".join(list), inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
def did_mention_other_user(users, author):
|
def did_mention_other_user(users, author):
|
||||||
for user in users:
|
for user in users:
|
||||||
if user is not author:
|
if user is not author:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def removed_user_mentions(old, new):
|
def removed_user_mentions(old, new):
|
||||||
users = []
|
users = []
|
||||||
for user in old:
|
for user in old:
|
||||||
|
@ -22,6 +26,7 @@ def removed_user_mentions(old, new):
|
||||||
users.append(user)
|
users.append(user)
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
def removed_role_mentions(old, new):
|
def removed_role_mentions(old, new):
|
||||||
roles = []
|
roles = []
|
||||||
for role in old:
|
for role in old:
|
||||||
|
@ -29,6 +34,7 @@ def removed_role_mentions(old, new):
|
||||||
roles.append(role)
|
roles.append(role)
|
||||||
return roles
|
return roles
|
||||||
|
|
||||||
|
|
||||||
def get_avatar(user, animate=True):
|
def get_avatar(user, animate=True):
|
||||||
if user.avatar_url:
|
if user.avatar_url:
|
||||||
avatar = str(user.avatar_url).replace(".webp", ".png")
|
avatar = str(user.avatar_url).replace(".webp", ".png")
|
||||||
|
@ -38,20 +44,24 @@ def get_avatar(user, animate=True):
|
||||||
avatar = avatar.replace(".gif", ".png")
|
avatar = avatar.replace(".gif", ".png")
|
||||||
return avatar
|
return avatar
|
||||||
|
|
||||||
|
|
||||||
def read_json(file_name):
|
def read_json(file_name):
|
||||||
with open(f'/root/totalfreedom/{file_name}.json', 'r') as file:
|
with open(f'/root/totalfreedom/{file_name}.json', 'r') as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def write_json(file_name, data):
|
def write_json(file_name, data):
|
||||||
with open(f'/root/totalfreedom/{file_name}.json', 'w') as file:
|
with open(f'/root/totalfreedom/{file_name}.json', 'w') as file:
|
||||||
json.dump(data,file,indent=4)
|
json.dump(data, file, indent=4)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def hit_endpoint(command):
|
def hit_endpoint(command):
|
||||||
url = [CENSORED_URL]
|
url = [CENSORED_URL]
|
||||||
payload = {}
|
payload = {}
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
||||||
response = json.loads(requests.request("GET", url, headers=headers, data = payload, timeout=100).text)
|
response = json.loads(requests.request(
|
||||||
|
"GET", url, headers=headers, data=payload, timeout=100).text)
|
||||||
return response['response']
|
return response['response']
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logging.basicConfig(level=logging.CRITICAL, format='%(message)s',handlers=[logging.FileHandler('log.log', 'a')])
|
logging.basicConfig(level=logging.CRITICAL, format='%(message)s', handlers=[
|
||||||
|
logging.FileHandler('log.log', 'a')])
|
||||||
|
|
12
main.py
12
main.py
|
@ -18,7 +18,8 @@ load_dotenv()
|
||||||
botToken = os.getenv('botToken')
|
botToken = os.getenv('botToken')
|
||||||
|
|
||||||
intents = discord.Intents.all()
|
intents = discord.Intents.all()
|
||||||
bot = commands.Bot(command_prefix=os.getenv('prefix'), description='TotalFreedom bot help command', intents=intents)
|
bot = commands.Bot(command_prefix=os.getenv('prefix'),
|
||||||
|
description='TotalFreedom bot help command', intents=intents)
|
||||||
|
|
||||||
|
|
||||||
extensions = [
|
extensions = [
|
||||||
|
@ -34,9 +35,11 @@ if __name__ == '__main__':
|
||||||
for extension in extensions:
|
for extension in extensions:
|
||||||
try:
|
try:
|
||||||
bot.load_extension(extension)
|
bot.load_extension(extension)
|
||||||
print(f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} loaded successfully")
|
print(
|
||||||
|
f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} loaded successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} didn't load {e}")
|
print(
|
||||||
|
f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} didn't load {e}")
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
|
@ -63,7 +66,8 @@ async def on_message(message):
|
||||||
try:
|
try:
|
||||||
bot.telnet_object.connect()
|
bot.telnet_object.connect()
|
||||||
except Exception as fuckup:
|
except Exception as fuckup:
|
||||||
print(f'Second attempt failed to reconnect telnet: {fuckup}')
|
print(
|
||||||
|
f'Second attempt failed to reconnect telnet: {fuckup}')
|
||||||
if not bypass:
|
if not bypass:
|
||||||
if re.search('discord\.gg\/[a-zA-z0-9\-]{1,16}', message.content) or re.search('discordapp\.com\/invite\/[a-z0-9]+/ig', message.content):
|
if re.search('discord\.gg\/[a-zA-z0-9\-]{1,16}', message.content) or re.search('discordapp\.com\/invite\/[a-z0-9]+/ig', message.content):
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import time
|
||||||
|
|
||||||
from telnetlib import Telnet
|
from telnetlib import Telnet
|
||||||
|
|
||||||
|
|
||||||
class telnet:
|
class telnet:
|
||||||
def __init__(self, ip, port, username, password):
|
def __init__(self, ip, port, username, password):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
|
@ -14,10 +15,10 @@ class telnet:
|
||||||
for x in username:
|
for x in username:
|
||||||
self.username = username[0]
|
self.username = username[0]
|
||||||
|
|
||||||
if b'Username:' in self.session.read_until(b'Username:', timeout = 3):
|
if b'Username:' in self.session.read_until(b'Username:', timeout=3):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.session.write(bytes(self.username, 'ascii') + b"\r\n")
|
self.session.write(bytes(self.username, 'ascii') + b"\r\n")
|
||||||
if b'Password:' in self.session.read_until(b'Password:', timeout = 3):
|
if b'Password:' in self.session.read_until(b'Password:', timeout=3):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.session.write(bytes(self.password, 'ascii') + b"\r\n")
|
self.session.write(bytes(self.password, 'ascii') + b"\r\n")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#straight from the old bot
|
# straight from the old bot
|
||||||
confirm = "✅"
|
confirm = "✅"
|
||||||
|
|
||||||
clipboard = "📋"
|
clipboard = "📋"
|
||||||
|
|
Loading…
Reference in a new issue