mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 15:44:57 +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:
|
||||||
|
|
58
.github/workflows/codeql-analysis.yml
vendored
58
.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,40 +28,40 @@ 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
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v1
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
# By default, queries listed here will override any specified in a config file.
|
# By default, queries listed here will override any specified in a config file.
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
# and modify them (or add more) to build your code if your project
|
# and modify them (or add more) to build your code if your project
|
||||||
# uses a compiled language
|
# uses a compiled language
|
||||||
|
|
||||||
#- run: |
|
#- run: |
|
||||||
# make bootstrap
|
# make bootstrap
|
||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v1
|
||||||
|
|
20
checks.py
20
checks.py
|
@ -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
|
||||||
|
@ -63,7 +68,7 @@ def is_executive():
|
||||||
raise no_permission(['IS_EXECUTIVE'])
|
raise no_permission(['IS_EXECUTIVE'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_tf_developer():
|
def is_tf_developer():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
@ -74,32 +79,35 @@ 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
|
||||||
for role in user.roles:
|
for role in user.roles:
|
||||||
if role.id == server_liaison:
|
if role.id == server_liaison:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
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
|
||||||
for role in user.roles:
|
for role in user.roles:
|
||||||
if role.id == creative_designer:
|
if role.id == creative_designer:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
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
|
||||||
for role in user.roles:
|
for role in user.roles:
|
||||||
if role.id == senior_admin:
|
if role.id == senior_admin:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -17,12 +18,12 @@ class Help(commands.Cog):
|
||||||
command_list = ''
|
command_list = ''
|
||||||
cog_list = [c for c in self.bot.cogs.keys()]
|
cog_list = [c for c in self.bot.cogs.keys()]
|
||||||
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
|
||||||
|
|
||||||
cogs_needed = []
|
cogs_needed = []
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
x = i + (int(page) - 1) * 4
|
x = i + (int(page) - 1) * 4
|
||||||
|
@ -30,7 +31,7 @@ class Help(commands.Cog):
|
||||||
cogs_needed.append(cog_list[x])
|
cogs_needed.append(cog_list[x])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for cog in cogs_needed:
|
for cog in cogs_needed:
|
||||||
command_list = ''
|
command_list = ''
|
||||||
for command in self.bot.get_cog(cog).get_commands():
|
for command in self.bot.get_cog(cog).get_commands():
|
||||||
|
@ -38,18 +39,20 @@ class Help(commands.Cog):
|
||||||
if command.hidden:
|
if command.hidden:
|
||||||
showcommand = False
|
showcommand = False
|
||||||
if command.parent:
|
if command.parent:
|
||||||
showcommand = False
|
showcommand = False
|
||||||
for check in command.checks:
|
for check in command.checks:
|
||||||
try:
|
try:
|
||||||
check(ctx)
|
check(ctx)
|
||||||
except:
|
except:
|
||||||
showcommand = False
|
showcommand = False
|
||||||
if showcommand:
|
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:
|
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
|
||||||
|
@ -22,7 +23,7 @@ class Miscellaneous(commands.Cog):
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
return
|
return
|
||||||
|
|
||||||
@is_tf_developer()
|
@is_tf_developer()
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def telnetconfig(self, ctx, *args):
|
async def telnetconfig(self, ctx, *args):
|
||||||
|
@ -51,25 +52,29 @@ class Miscellaneous(commands.Cog):
|
||||||
else:
|
else:
|
||||||
em.description = 'Configuration successful'
|
em.description = 'Configuration successful'
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
|
|
||||||
elif args[0] == 'test':
|
elif args[0] == 'test':
|
||||||
command = ''
|
command = ''
|
||||||
for x in range(1, len(args)):
|
for x in range(1, len(args)):
|
||||||
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.'
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
|
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@is_dev()
|
@is_dev()
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def debug(self, ctx, *, cmd):
|
async def debug(self, ctx, *, cmd):
|
||||||
|
@ -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,11 +7,12 @@ 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
|
||||||
self.moderator_role_id = 769659653129896023
|
self.moderator_role_id = 769659653129896023
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.has_permissions(kick_members=True)
|
@commands.has_permissions(kick_members=True)
|
||||||
async def kick(self, ctx, user: discord.Member, *, reason="No reason specified"):
|
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}'))
|
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,10 +7,11 @@ 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
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_liaison()
|
@is_liaison()
|
||||||
async def eventhost(self, ctx, user: discord.Member):
|
async def eventhost(self, ctx, user: discord.Member):
|
||||||
|
@ -22,7 +23,7 @@ class ServerCommands(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await user.add_roles(eventhostrole)
|
await user.add_roles(eventhostrole)
|
||||||
await ctx.send(f'```Succesfully added {eventhostrole.name} to {user.name}```')
|
await ctx.send(f'```Succesfully added {eventhostrole.name} to {user.name}```')
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_creative_designer()
|
@is_creative_designer()
|
||||||
async def masterbuilder(self, ctx, user: discord.Member):
|
async def masterbuilder(self, ctx, user: discord.Member):
|
||||||
|
@ -34,7 +35,7 @@ class ServerCommands(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await user.add_roles(master_builder_role)
|
await user.add_roles(master_builder_role)
|
||||||
await ctx.send(f'```Succesfully added {master_builder_role.name} to {user.name}```')
|
await ctx.send(f'```Succesfully added {master_builder_role.name} to {user.name}```')
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_staff()
|
@is_staff()
|
||||||
async def serverban(self, ctx, user: discord.Member):
|
async def serverban(self, ctx, user: discord.Member):
|
||||||
|
@ -46,7 +47,7 @@ class ServerCommands(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await user.add_roles(serverbannedrole)
|
await user.add_roles(serverbannedrole)
|
||||||
await ctx.send(f'Added Server Banned role to {user.name}')
|
await ctx.send(f'Added Server Banned role to {user.name}')
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_staff()
|
@is_staff()
|
||||||
async def start(self, ctx):
|
async def start(self, ctx):
|
||||||
|
@ -55,23 +56,23 @@ 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'
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
em.description = f'{attempt}'
|
em.description = f'{attempt}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def uptime(self, ctx):
|
async def uptime(self, ctx):
|
||||||
"Returns the uptime of the VPS"
|
"Returns the uptime of the VPS"
|
||||||
|
@ -79,7 +80,7 @@ class ServerCommands(commands.Cog):
|
||||||
em.title = 'VPS Uptime Information'
|
em.title = 'VPS Uptime Information'
|
||||||
em.description = hit_endpoint('uptime')
|
em.description = hit_endpoint('uptime')
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_staff()
|
@is_staff()
|
||||||
async def stop(self, ctx):
|
async def stop(self, ctx):
|
||||||
|
@ -88,23 +89,23 @@ 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'
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
em.description = f'{attempt}'
|
em.description = f'{attempt}'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command(aliases=['adminconsole', 'ac'])
|
@commands.command(aliases=['adminconsole', 'ac'])
|
||||||
@is_staff()
|
@is_staff()
|
||||||
async def telnet(self, ctx, *args):
|
async def telnet(self, ctx, *args):
|
||||||
|
@ -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)
|
||||||
|
@ -133,7 +136,7 @@ class ServerCommands(commands.Cog):
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
em.description = 'Command sent.'
|
em.description = 'Command sent.'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_senior()
|
@is_senior()
|
||||||
async def kill(self, ctx):
|
async def kill(self, ctx):
|
||||||
|
@ -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:
|
||||||
|
@ -159,19 +162,19 @@ class ServerCommands(commands.Cog):
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
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:
|
||||||
|
@ -179,17 +182,18 @@ class ServerCommands(commands.Cog):
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
em.description = 'Server restarting.'
|
em.description = 'Server restarting.'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@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)
|
||||||
|
@ -198,13 +202,14 @@ class ServerCommands(commands.Cog):
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
em.description = 'Command sent.'
|
em.description = 'Command sent.'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command(aliases=['status'])
|
@commands.command(aliases=['status'])
|
||||||
async def state(self, ctx):
|
async def state(self, ctx):
|
||||||
'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
|
||||||
|
@ -212,14 +217,15 @@ class ServerCommands(commands.Cog):
|
||||||
em.description = 'Server is online'
|
em.description = 'Server is online'
|
||||||
em.colour = 0x00FF00
|
em.colour = 0x00FF00
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
@commands.command(name='list')
|
@commands.command(name='list')
|
||||||
async def online(self, ctx):
|
async def online(self, ctx):
|
||||||
'Gives a list of online players.'
|
'Gives a list of online players.'
|
||||||
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,24 +236,27 @@ 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()
|
||||||
async def archivereports(self, ctx):
|
async def archivereports(self, ctx):
|
||||||
"""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:
|
||||||
|
@ -261,7 +270,7 @@ class ServerCommands(commands.Cog):
|
||||||
await archived_reports_channel.send("Message archived because it is older than 24 hours", embed=embed)
|
await archived_reports_channel.send("Message archived because it is older than 24 hours", embed=embed)
|
||||||
count += 1
|
count += 1
|
||||||
await ctx.send("Archived **{}** reports that are older than 24 hours".format(count))
|
await ctx.send("Archived **{}** reports that are older than 24 hours".format(count))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@is_mod_or_has_perms()
|
@is_mod_or_has_perms()
|
||||||
async def fixreports(self, ctx):
|
async def fixreports(self, ctx):
|
||||||
|
@ -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))
|
||||||
|
|
|
@ -25,4 +25,4 @@
|
||||||
"\u2705"
|
"\u2705"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
50
events.py
50
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,25 +32,26 @@ 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}')
|
||||||
|
|
||||||
reaction_data = read_json('config')
|
reaction_data = read_json('config')
|
||||||
self.bot.reaction_roles = reaction_data['reaction_roles']
|
self.bot.reaction_roles = reaction_data['reaction_roles']
|
||||||
|
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Client] {self.bot.user.name} is online.')
|
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Client] {self.bot.user.name} is online.')
|
||||||
game = discord.Game('play.totalfreedom.me')
|
game = discord.Game('play.totalfreedom.me')
|
||||||
await self.bot.change_presence(status=discord.Status.online, activity=game)
|
await self.bot.change_presence(status=discord.Status.online, activity=game)
|
||||||
|
|
||||||
guildCount = len(self.bot.guilds)
|
guildCount = len(self.bot.guilds)
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Guilds] bot currently in {guildCount} guilds.')
|
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Guilds] bot currently in {guildCount} guilds.')
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Guilds] Connected to guild: {guild.name}, Owner: {guild.owner}')
|
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Guilds] Connected to guild: {guild.name}, Owner: {guild.owner}')
|
||||||
starttime = datetime.utcnow()
|
starttime = datetime.utcnow()
|
||||||
global starttime
|
global starttime
|
||||||
|
|
||||||
'''@commands.Cog.listener()
|
'''@commands.Cog.listener()
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
if message.guild and message.author is message.guild.me and message.channel.id == reports_channel_id:
|
if message.guild and message.author is message.guild.me and message.channel.id == reports_channel_id:
|
||||||
|
@ -81,7 +83,7 @@ class Events(commands.Cog):
|
||||||
await message.delete()
|
await message.delete()
|
||||||
await message.channel.send(f"{message.author.mention} do not post invite links to other discord servers.")
|
await message.channel.send(f"{message.author.mention} do not post invite links to other discord servers.")
|
||||||
return'''
|
return'''
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message_edit(self, before, after):
|
async def on_message_edit(self, before, after):
|
||||||
if not isinstance(before.author, discord.Member):
|
if not isinstance(before.author, discord.Member):
|
||||||
|
@ -89,24 +91,27 @@ 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)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message_delete(self, message):
|
async def on_message_delete(self, message):
|
||||||
if not isinstance(message.author, discord.Member):
|
if not isinstance(message.author, discord.Member):
|
||||||
|
@ -121,17 +126,19 @@ 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)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_command_error(self, ctx, error):
|
async def on_command_error(self, ctx, error):
|
||||||
em = discord.Embed()
|
em = discord.Embed()
|
||||||
|
@ -140,14 +147,15 @@ class Events(commands.Cog):
|
||||||
em.colour = 0xFF0000
|
em.colour = 0xFF0000
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
print(f'[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Commands] {ctx.author} (ID: {ctx.author.id}) failed running: {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}) failed running: {ctx.message.content} in guild: {ctx.guild.name}')
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
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()
|
||||||
async def on_raw_reaction_add(self, payload):
|
async def on_raw_reaction_add(self, payload):
|
||||||
if payload.member == self.bot.user:
|
if payload.member == self.bot.user:
|
||||||
|
@ -169,10 +177,11 @@ 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)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_raw_reaction_remove(self, payload):
|
async def on_raw_reaction_remove(self, payload):
|
||||||
if payload.member == self.bot.user:
|
if payload.member == self.bot.user:
|
||||||
|
@ -181,6 +190,7 @@ class Events(commands.Cog):
|
||||||
for role_id, msg_id, emoji in self.bot.reaction_roles:
|
for role_id, msg_id, emoji in self.bot.reaction_roles:
|
||||||
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))
|
||||||
|
|
18
functions.py
18
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')])
|
||||||
|
|
16
main.py
16
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
|
||||||
|
@ -54,7 +57,7 @@ async def on_message(message):
|
||||||
if role.id in bypass_roles:
|
if role.id in bypass_roles:
|
||||||
bypass = True
|
bypass = True
|
||||||
else:
|
else:
|
||||||
if 'Server has started' in message.content: # Telnet reconnect script
|
if 'Server has started' in message.content: # Telnet reconnect script
|
||||||
try:
|
try:
|
||||||
bot.telnet_object.connect()
|
bot.telnet_object.connect()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -63,12 +66,13 @@ 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()
|
||||||
await message.channel.send(f"{message.author.mention} do not post invite links to other discord servers.")
|
await message.channel.send(f"{message.author.mention} do not post invite links to other discord servers.")
|
||||||
|
|
||||||
if message.content.lower().startswith(os.getenv('prefix')):
|
if message.content.lower().startswith(os.getenv('prefix')):
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
|
|
@ -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