TotalFreedomBot/main.py

120 lines
4.6 KiB
Python
Raw Normal View History

2020-10-28 11:47:39 +00:00
import os
2020-11-21 12:38:59 +00:00
import re
2021-01-07 19:15:10 +00:00
import time
2020-10-28 12:23:49 +00:00
from datetime import datetime
2021-01-07 19:15:10 +00:00
import discord
2020-10-28 11:47:39 +00:00
from discord.ext import commands
from dotenv import load_dotenv
2021-01-07 19:15:10 +00:00
import logscript
from functions import config_entry, get_prefix, hit_endpoint, get_server_status
from unicode import clipboard
2020-11-21 12:38:59 +00:00
print = logscript.logging.getLogger().critical
2020-10-28 11:47:39 +00:00
load_dotenv()
botToken = os.getenv('botToken')
intents = discord.Intents.all()
2021-01-04 23:43:48 +00:00
bot = commands.Bot(command_prefix=get_prefix, case_insensitive=True, description='TotalFreedom bot help command',
intents=intents)
2020-11-21 12:38:59 +00:00
2021-01-07 19:15:10 +00:00
bot.server_liaison = config_entry("server_liaison")
bot.event_host = config_entry("event_host")
bot.server_banned = config_entry("server_banned")
bot.senior_admin = config_entry("senior_admin")
bot.admin = config_entry("admin")
bot.master_builder = config_entry("master_builder")
bot.reports_channel_id = config_entry("reports_channel_id")
bot.archived_reports_channel_id = config_entry("archived_reports_channel_id")
bot.guild_id = config_entry("guild_id")
bot.mentions_channel_id = config_entry("mentions_channel_id")
bot.discord_admin = config_entry("discord_admin")
bot.discord_mod = config_entry("discord_mod")
bot.devs = config_entry("devs")
bot.bot_logs_channel_id = config_entry("bot_logs_channel_id")
bot.executive = config_entry("executive")
bot.asst_exec = config_entry("asst_exec")
bot.developer = config_entry("developer")
bot.creative_designer = config_entry("creative_designer")
bot.server_chat = config_entry("server_chat")
bot.verification_role = config_entry("verification_role")
bot.server_chat_2 = config_entry("server_chat_2")
2020-10-28 11:47:39 +00:00
extensions = [
2020-10-28 12:23:49 +00:00
"commands.moderation",
"commands.server_commands",
2020-10-28 11:47:39 +00:00
"commands.help",
2020-10-28 12:23:49 +00:00
"commands.miscellaneous",
"events"
2020-10-28 11:47:39 +00:00
]
if __name__ == '__main__':
for extension in extensions:
try:
bot.load_extension(extension)
print(
f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} loaded successfully")
2020-10-28 11:47:39 +00:00
except Exception as e:
print(
f"[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: [Extensions] {extension} didn't load {e}")
2020-10-28 11:47:39 +00:00
2020-11-21 12:38:59 +00:00
@bot.event
async def on_message(message):
2020-12-19 15:54:24 +00:00
if isinstance(message.channel, discord.channel.DMChannel):
print(f'{message.author} DM: {message.content}')
return
2021-01-07 19:15:10 +00:00
elif message.guild and message.author is message.guild.me and message.channel.id == bot.reports_channel_id:
2020-11-21 12:38:59 +00:00
await message.add_reaction(clipboard)
2021-01-04 23:43:48 +00:00
elif message.type == discord.MessageType.new_member:
if re.search('discord\.gg\/[a-zA-z0-9\-]{1,16}', message.author.name.lower()) or re.search(
'discordapp\.com\/invite\/[a-z0-9]+/ig', message.author.name.lower()):
2020-11-21 12:38:59 +00:00
await message.author.ban(reason="Name is an invite link.")
await message.delete()
2021-01-07 19:15:10 +00:00
bypass_roles = [bot.discord_admin, bot.discord_mod]
2020-11-21 12:38:59 +00:00
bypass = False
if message.author != bot.user:
for role in message.author.roles:
if role.id in bypass_roles:
bypass = True
else:
2021-01-07 19:15:10 +00:00
server_chats = {1: bot.server_chat, 2: bot.server_chat_2}
2021-01-04 23:43:48 +00:00
for server in range(1, len(server_chats)):
if message.channel.id == server_chats[server]:
if not get_server_status(server):
hit_endpoint('start', server)
if 'Server has started' in message.content: # Telnet reconnect script
2020-11-21 12:38:59 +00:00
try:
bot.telnet_object.connect()
2021-01-07 19:15:10 +00:00
except Exception as err:
print(f'Failed to reconnect telnet: {err}')
2020-11-21 12:38:59 +00:00
time.sleep(5)
try:
bot.telnet_object.connect()
except Exception as fuckup:
print(
f'Second attempt failed to reconnect telnet: {fuckup}')
2021-01-04 23:43:48 +00:00
try:
bot.telnet_object_2.connect()
2021-01-07 19:15:10 +00:00
except Exception as err:
print(f'Failed to reconnect telnet 2: {err}')
2021-01-04 23:43:48 +00:00
time.sleep(5)
try:
bot.telnet_object_2.connect()
except Exception as fuckup:
print(
f'Second attempt failed to reconnect telnet 2: {fuckup}')
2020-11-21 12:38:59 +00:00
if not bypass:
2021-01-04 23:43:48 +00:00
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):
2020-11-21 12:38:59 +00:00
await message.delete()
await message.channel.send(f"{message.author.mention} do not post invite links to other discord servers.")
2020-12-19 15:54:24 +00:00
await bot.process_commands(message)
2020-11-21 12:38:59 +00:00
2021-01-04 23:43:48 +00:00
2020-10-28 12:23:49 +00:00
bot.run(botToken)