2022-02-07 03:06:01 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
2022-02-08 23:37:24 +02:00
|
|
|
import shutil
|
2022-02-07 03:06:01 +02:00
|
|
|
import requests
|
|
|
|
import threading
|
2022-02-06 02:58:55 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
import discord
|
|
|
|
except Exception as exp:
|
|
|
|
print(f"Module discord.py is not installed. Make sure to run 'pip install -r requirements.txt' before first start")
|
|
|
|
sys.exit()
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
from functions import *
|
|
|
|
pid = os.getpid()
|
2022-02-08 23:37:24 +02:00
|
|
|
version = 1.2
|
2022-02-07 03:06:01 +02:00
|
|
|
|
|
|
|
if loadJson("config.json")["check_for_updates"]:
|
|
|
|
try:
|
|
|
|
serv_ver = requests.get("https://www.end-play.xyz/yusarin/version.txt").text.replace('\n', '')
|
|
|
|
if float(serv_ver) > version:
|
|
|
|
appendLog(f"YusarinBot version {serv_ver} is available. Download new version here: https://github.com/profitrollgame/YusarinBot/releases/latest")
|
|
|
|
appendLog(f"Currently using YusarinBot v{str(version)}")
|
|
|
|
except Exception as exp:
|
|
|
|
appendLog(f"Could not get YusarinBot cloud version due to {exp}. Currently using {str(version)}")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
intents = discord.Intents().all()
|
|
|
|
client = discord.Client(intents=intents)
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_ready():
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
appendLog(f"Logged in as {client.user}")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
config = loadJson("config.json")
|
|
|
|
|
|
|
|
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=config["bot_activity"]))
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await clearTrash(client)
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
@client.event
|
|
|
|
async def on_guild_join(guild):
|
|
|
|
|
|
|
|
global path
|
|
|
|
|
|
|
|
os.mkdir(f"{path}/guilds/{str(guild.id)}")
|
|
|
|
os.mkdir(f"{path}/guilds/{str(guild.id)}/channels")
|
|
|
|
saveJson({}, f"{path}/guilds/{str(guild.id)}/config.json")
|
|
|
|
|
|
|
|
appendLog(f"Joined guild '{guild}' with id {str(guild.id)}")
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_guild_remove(guild):
|
|
|
|
|
|
|
|
global path
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.rmtree(f"{path}/guilds/{str(guild.id)}")
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
appendLog(f"Left guild '{guild}' with id {str(guild.id)}")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_voice_state_update(member, before, after):
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
global debug
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
config = loadJson("config.json")
|
|
|
|
|
|
|
|
vc_from = before.channel
|
|
|
|
vc_to = after.channel
|
|
|
|
|
|
|
|
# If user left vc
|
|
|
|
if vc_to is None:
|
|
|
|
if isUserVoice(vc_from):
|
|
|
|
if isVoiceOfUser(vc_from, member):
|
|
|
|
await removeUserVoice(vc_from)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
await changeNomicPerms("deny", vc_from, member)
|
|
|
|
|
|
|
|
# If user joined vc
|
|
|
|
else:
|
|
|
|
if isUserVoice(vc_from):
|
|
|
|
if isVoiceOfUser(vc_from, member):
|
|
|
|
await removeUserVoice(vc_from)
|
|
|
|
else:
|
|
|
|
await changeNomicPerms("deny", vc_from, member)
|
|
|
|
if isUserVoice(vc_to):
|
|
|
|
await changeNomicPerms("allow", vc_to, member)
|
2022-02-08 23:37:24 +02:00
|
|
|
if vc_to.id == guildConfGet(vc_to.guild, "channel"):
|
|
|
|
if guildConfGet(vc_to.guild, "category") is not None:
|
|
|
|
voice_chan = await createUserVoice(vc_to, discord.utils.get(vc_to.guild.categories, id=guildConfGet(vc_to.guild, "category")), member)
|
2022-02-05 02:31:32 +02:00
|
|
|
try:
|
|
|
|
await member.move_to(voice_chan)
|
|
|
|
except:
|
|
|
|
await removeUserVoice(voice_chan)
|
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
if debug:
|
|
|
|
appendLog(f"Category for guild {vc_to.guild} ({str(vc_to.guild.id)}) is not set", guild=vc_to.guild)
|
|
|
|
else:
|
|
|
|
appendLog(f"Category for guild {vc_to.guild} is not set", guild=vc_to.guild)
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
# ==========================================================================================
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_message(message):
|
|
|
|
|
|
|
|
config = loadJson("config.json")
|
|
|
|
|
|
|
|
if message.guild is not None:
|
|
|
|
try:
|
2022-02-08 23:37:24 +02:00
|
|
|
prefix = guildConfGet(message.guild, "prefix")
|
2022-02-05 02:31:32 +02:00
|
|
|
if prefix is None:
|
|
|
|
prefix = config["bot_prefix"]
|
|
|
|
except Exception as exp:
|
|
|
|
print(exp)
|
|
|
|
prefix = config["bot_prefix"]
|
|
|
|
else:
|
|
|
|
prefix = config["bot_prefix"]
|
|
|
|
|
|
|
|
if message.author == client.user:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if message.content in [f"{prefix}reboot", f"{prefix}restart", f"{prefix}shutdown", f"{prefix}die"]:
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
if message.author.id == config["owner"]:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("shutdown", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
os.system(f"kill -9 {str(pid)}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
elif message.content.startswith(f"{prefix}channel"):
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
fullcmd = message.content.split()
|
|
|
|
|
|
|
|
if message.guild is not None:
|
|
|
|
|
|
|
|
if message.author.guild_permissions.administrator:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if fullcmd[1] == "reset":
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "channel") is not None:
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfReset(message.guild, "channel")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("reset_channel", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("none_channel", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
selected_channel = discord.utils.get(message.guild.channels, id=int(fullcmd[1]))
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfSet(message.guild, "channel", int(fullcmd[1]))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("result_channel", message.guild).format(selected_channel.name))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "category") is None:
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("warn_category", message.guild).format(prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
except Exception as exp:
|
|
|
|
|
|
|
|
#print(exp)
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("usage_channel", message.guild).format(prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("command_forbidden", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("command_in_dm"))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
elif message.content.startswith(f"{prefix}category"):
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
fullcmd = message.content.split()
|
|
|
|
|
|
|
|
if message.guild is not None:
|
|
|
|
|
|
|
|
if message.author.guild_permissions.administrator:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if fullcmd[1] == "reset":
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "category") is not None:
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfReset(message.guild, "category")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("reset_category", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("none_category", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
selected_category = discord.utils.get(message.guild.channels, id=int(fullcmd[1]))
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfSet(message.guild, "category", int(fullcmd[1]))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("result_category", message.guild).format(selected_category.name))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "channel") is None:
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("warn_channel", message.guild).format(prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
except Exception as exp:
|
|
|
|
|
|
|
|
#print(exp)
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("usage_category", message.guild).format(prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("command_forbidden", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("command_in_dm"))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
elif message.content.startswith(f"{prefix}prefix"):
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
fullcmd = message.content.split()
|
|
|
|
|
|
|
|
if message.guild is not None:
|
|
|
|
|
|
|
|
if message.author.guild_permissions.administrator:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if fullcmd[1] == "reset":
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "prefix") is not None:
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfReset(message.guild, "prefix")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("reset_prefix", message.guild).format(config["bot_prefix"]))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("none_prefix", message.guild).format(prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfSet(message.guild, "prefix", fullcmd[1])
|
2022-02-05 02:31:32 +02:00
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("result_prefix", message.guild).format(fullcmd[1]))
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
await message.channel.send(getMsg("usage_prefix", message.guild).format(prefix))
|
|
|
|
|
|
|
|
else:
|
|
|
|
await message.channel.send(getMsg("command_forbidden", message.guild))
|
|
|
|
|
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("command_in_dm"))
|
2022-02-07 03:06:01 +02:00
|
|
|
|
|
|
|
elif message.content.startswith(f"{prefix}locale"):
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
fullcmd = message.content.split()
|
|
|
|
|
|
|
|
if message.guild is not None:
|
|
|
|
|
|
|
|
if message.author.guild_permissions.administrator:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if fullcmd[1] == "reset":
|
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
if guildConfGet(message.guild, "locale") is not None:
|
2022-02-07 03:06:01 +02:00
|
|
|
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfReset(message.guild, "locale")
|
|
|
|
appendLog(f"Server's locale has been reset", message.guild)
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("reset_locale", message.guild).format(getMsg("locale_name", message.guild)))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await message.channel.send(getMsg("none_locale", message.guild).format(getMsg("locale_name", message.guild)))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
for locale_file in os.listdir(f"{path}/locale/"):
|
|
|
|
if locale_file[:-5] == fullcmd[1]:
|
2022-02-08 23:37:24 +02:00
|
|
|
guildConfSet(message.guild, "locale", fullcmd[1])
|
|
|
|
appendLog(f"Server's locale is now set to {fullcmd[1]}", message.guild)
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("locale_set", message.guild))
|
|
|
|
return
|
|
|
|
|
|
|
|
locales = []
|
|
|
|
|
|
|
|
for locale_file in os.listdir(f"{path}/locale/"):
|
|
|
|
locales.append(f"`{locale_file[:-5]}`")
|
|
|
|
|
|
|
|
await message.channel.send(getMsg("usage_locale", message.guild).format(prefix, ", ".join(locales)))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
except:
|
|
|
|
|
2022-02-07 03:06:01 +02:00
|
|
|
locales = []
|
|
|
|
|
|
|
|
for locale_file in os.listdir(f"{path}/locale/"):
|
|
|
|
locales.append(f"`{locale_file[:-5]}`")
|
|
|
|
|
|
|
|
await message.channel.send(getMsg("usage_locale", message.guild).format(prefix, ", ".join(locales)))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
2022-02-07 03:06:01 +02:00
|
|
|
await message.channel.send(getMsg("command_forbidden", message.guild))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("command_in_dm"))
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
elif message.content.startswith(f"{prefix}help"):
|
2022-02-08 23:37:24 +02:00
|
|
|
|
|
|
|
gotCommand(message)
|
|
|
|
|
2022-02-05 02:31:32 +02:00
|
|
|
if message.author.id == config["owner"]:
|
|
|
|
if message.guild is not None:
|
2022-02-07 03:11:51 +02:00
|
|
|
await message.channel.send(await guildConfigured(message.guild) + getMsg("help", message.guild).format(getMsg("help_owner", message.guild).format(prefix), prefix, prefix, prefix, prefix, prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("help").format(getMsg("help_owner").format(prefix), prefix, prefix, prefix, prefix, prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
else:
|
|
|
|
if message.guild is not None:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(await guildConfigured(message.guild) + getMsg("help", message.guild).format("", prefix, prefix, prefix, prefix))
|
2022-02-05 02:31:32 +02:00
|
|
|
else:
|
2022-02-08 23:37:24 +02:00
|
|
|
await message.channel.send(getMsg("help").format("", prefix, prefix, prefix, prefix))
|
2022-02-07 03:06:01 +02:00
|
|
|
|
|
|
|
#if loadJson("config.json")["auto_clear_trash"]:
|
|
|
|
# run func
|
|
|
|
|
|
|
|
appendLog(f"Trying to log in...")
|
2022-02-05 02:31:32 +02:00
|
|
|
|
|
|
|
client.run(loadJson("config.json")["bot_token"])
|