Update 1.5
This commit is contained in:
349
yusarin.py
349
yusarin.py
@@ -6,14 +6,15 @@ import requests
|
||||
import threading
|
||||
|
||||
try:
|
||||
import discord
|
||||
import discord # type: ignore
|
||||
from discord import ApplicationContext, Option, Intents # type: ignore
|
||||
except Exception as exp:
|
||||
print(f"Module discord.py is not installed. Make sure to run 'pip install -r requirements.txt' before first start")
|
||||
print(f"Module py-cord is not installed. Make sure to run 'pip install -r requirements.txt' before first start")
|
||||
sys.exit()
|
||||
|
||||
from functions import *
|
||||
pid = os.getpid()
|
||||
version = 1.4
|
||||
version = 1.5
|
||||
|
||||
if loadJson("config.json")["owner"] == "SET-OWNER-ID" or loadJson("config.json")["bot_token"] == "SET-BOT-TOKEN":
|
||||
print(f"Bot is not correctly configured.\nMake sure you've set up owner id and bot token in {path}/config.json\nLearn more here: https://github.com/profitrollgame/YusarinBot")
|
||||
@@ -21,15 +22,15 @@ if loadJson("config.json")["owner"] == "SET-OWNER-ID" or loadJson("config.json")
|
||||
|
||||
if loadJson("config.json")["check_for_updates"]:
|
||||
try:
|
||||
serv_ver = requests.get("https://www.end-play.xyz/yusarin/version.txt").text.replace('\n', '')
|
||||
serv_ver = json.loads(requests.get("https://api.end-play.xyz/version&apikey=publickey&app=yusarinbot").text)["version"]
|
||||
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)}")
|
||||
|
||||
intents = discord.Intents().all()
|
||||
client = discord.Client(intents=intents)
|
||||
intents = Intents().all()
|
||||
client = discord.Bot(intents=intents)
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
@@ -106,251 +107,115 @@ async def on_voice_state_update(member, before, after):
|
||||
else:
|
||||
appendLog(f"Category for guild {vc_to.guild} is not set", guild=vc_to.guild)
|
||||
|
||||
# ==========================================================================================
|
||||
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
|
||||
#=========================================================================================================================
|
||||
@client.slash_command(name="shutdown", description="Restart the bot")
|
||||
async def shutdown(ctx: ApplicationContext):
|
||||
config = loadJson("config.json")
|
||||
|
||||
if message.guild is not None:
|
||||
try:
|
||||
prefix = guildConfGet(message.guild, "prefix")
|
||||
if prefix is None:
|
||||
prefix = config["bot_prefix"]
|
||||
except Exception as exp:
|
||||
print(exp)
|
||||
prefix = config["bot_prefix"]
|
||||
if ctx.author.id == config["owner"]:
|
||||
await ctx.respond(embed=makeEmbed(description=getMsg("shutdown", ctx.guild).format(ctx.author), color=strToColor(config["color_default"])))
|
||||
os.system(f"kill -9 {str(pid)}")
|
||||
else:
|
||||
prefix = config["bot_prefix"]
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("admin_title", ctx.guild), description=getMsg("admin_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
#=========================================================================================================================
|
||||
|
||||
if message.author == client.user:
|
||||
|
||||
return
|
||||
#=========================================================================================================================
|
||||
@client.slash_command(name="help", description="Get information about this server")
|
||||
async def help(ctx: ApplicationContext):
|
||||
await ctx.respond(embed=getHelpMessage(ctx, version))
|
||||
#=========================================================================================================================
|
||||
|
||||
if message.content in [f"{prefix}reboot", f"{prefix}restart", f"{prefix}shutdown", f"{prefix}die"]:
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
if message.author.id == config["owner"]:
|
||||
|
||||
await message.reply(embed=makeEmbed(description=getMsg("shutdown", message.guild).format(message.author), color=strToColor(config["color_default"])), mention_author=False)
|
||||
os.system(f"kill -9 {str(pid)}")
|
||||
|
||||
#=========================================================================================================================
|
||||
locale = client.create_group("locale", "Commands related to bot's locale")
|
||||
|
||||
valid_locales = []
|
||||
files_locales = os.listdir(f"{path}/locale/")
|
||||
for entry in files_locales:
|
||||
valid_locales.append(".".join(entry.split(".")[:-1]))
|
||||
|
||||
@locale.command(name="set", description="Set bot's messages language")
|
||||
async def locale_set(ctx: ApplicationContext, language: Option(str, "One of the languages in list", choices=valid_locales)): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
if language+".json" in os.listdir(f"{path}/locale/"):
|
||||
guildConfSet(ctx.guild, "locale", language)
|
||||
appendLog(f"Server's locale is now set to {language}", ctx.guild)
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("set_locale_title", ctx.guild), description=getMsg("set_locale_description", ctx.guild).format(getMsg("locale_name", ctx.guild)), color=strToColor(config["color_ok"])))
|
||||
else:
|
||||
|
||||
return
|
||||
|
||||
elif message.content.startswith(f"{prefix}channel"):
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
fullcmd = message.content.split()
|
||||
|
||||
if message.guild is not None:
|
||||
|
||||
if message.author.guild_permissions.administrator:
|
||||
|
||||
try:
|
||||
|
||||
if fullcmd[1] == "reset":
|
||||
|
||||
if guildConfGet(message.guild, "channel") is not None:
|
||||
|
||||
guildConfReset(message.guild, "channel")
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("reset_channel_title", message.guild), description=getMsg("reset_channel_description", message.guild).format(prefix), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("hint_none_channel_title", message.guild), description=getMsg("hint_none_channel_description", message.guild).format(prefix), color=strToColor(config["color_warn"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
selected_channel = discord.utils.get(message.guild.channels, id=int(fullcmd[1]))
|
||||
|
||||
if isinstance(selected_channel, discord.VoiceChannel):
|
||||
|
||||
guildConfSet(message.guild, "channel", int(fullcmd[1]))
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("set_channel_title", message.guild), description=getMsg("set_channel_description", message.guild).format(selected_channel.name), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
if guildConfGet(message.guild, "category") is None:
|
||||
|
||||
await message.channel.send(embed=makeEmbed(title=getMsg("hint_none_category_title", message.guild), description=getMsg("hint_none_category_description", message.guild).format(prefix), color=strToColor(config["color_warn"])))
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_text_channel_title", message.guild), description=getMsg("error_text_channel_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
except Exception as exp:
|
||||
|
||||
if debug:
|
||||
print(exp)
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_channel_title", message.guild), description=getMsg("error_channel_description", message.guild).format(prefix), footer=getMsg("help_notice_id", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("forbidden_title", message.guild), description=getMsg("forbidden_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
valid_locales = []
|
||||
files_locales = os.listdir(f"{path}/locale/")
|
||||
for entry in files_locales:
|
||||
valid_locales.append(entry.split(".")[:-1])
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("error_locale_title", ctx.guild), description=getMsg("error_locale_description", ctx.guild).format(", ".join(valid_locales)), color=strToColor(config["color_error"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
|
||||
@locale.command(name="reset", description="Reset the bot's language in this guild")
|
||||
async def locale_reset(ctx: ApplicationContext): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
if guildConfGet(ctx.guild, "locale") is not None:
|
||||
guildConfReset(ctx.guild, "locale")
|
||||
appendLog(f"Server's locale has been reset", ctx.guild)
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("reset_locale_title", ctx.guild), description=getMsg("reset_locale_description", ctx.guild).format(getMsg("locale_name", ctx.guild)), color=strToColor(config["color_ok"])))
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("dm_title", message.guild), description=getMsg("dm_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
elif message.content.startswith(f"{prefix}category"):
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
fullcmd = message.content.split()
|
||||
|
||||
if message.guild is not None:
|
||||
|
||||
if message.author.guild_permissions.administrator:
|
||||
|
||||
try:
|
||||
|
||||
if fullcmd[1] == "reset":
|
||||
|
||||
if guildConfGet(message.guild, "category") is not None:
|
||||
|
||||
guildConfReset(message.guild, "category")
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("reset_category_title", message.guild), description=getMsg("reset_category_description", message.guild).format(prefix), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("hint_none_category_title", message.guild), description=getMsg("hint_none_category_description", message.guild).format(prefix), color=strToColor(config["color_warn"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
selected_category = discord.utils.get(message.guild.channels, id=int(fullcmd[1]))
|
||||
|
||||
guildConfSet(message.guild, "category", int(fullcmd[1]))
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("set_category_title", message.guild), description=getMsg("set_category_description", message.guild).format(selected_category.name), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
if guildConfGet(message.guild, "channel") is None:
|
||||
|
||||
await message.channel.send(embed=makeEmbed(title=getMsg("hint_none_channel_title", message.guild), description=getMsg("hint_none_channel_description", message.guild).format(prefix), color=strToColor(config["color_warn"])))
|
||||
|
||||
except Exception as exp:
|
||||
|
||||
if debug:
|
||||
print(exp)
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_category_title", message.guild), description=getMsg("error_category_description", message.guild).format(prefix), footer=getMsg("help_notice_id_category", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("forbidden_title", message.guild), description=getMsg("forbidden_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("hint_none_locale_title", ctx.guild), description=getMsg("hint_none_locale_description", ctx.guild).format(getMsg("locale_name", ctx.guild)), color=strToColor(config["color_warn"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
#=========================================================================================================================
|
||||
|
||||
#=========================================================================================================================
|
||||
channel = client.create_group("channel", "Commands related to parent voice channel")
|
||||
|
||||
@channel.command(name="set", description="Select the voice channel that will be parent to private ones")
|
||||
async def channel_set(ctx: ApplicationContext, channel: Option(discord.VoiceChannel, "Parent Voice Channel")): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
guildConfSet(ctx.guild, "channel", channel.id)
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("set_channel_title", ctx.guild), description=getMsg("set_channel_description", ctx.guild).format(channel.name), color=strToColor(config["color_ok"])))
|
||||
if guildConfGet(ctx.guild, "category") is None:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("hint_none_category_title", ctx.guild), description=getMsg("hint_none_category_description", ctx.guild), color=strToColor(config["color_warn"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
|
||||
@channel.command(name="reset", description="Reset the currently selected parent voice channel")
|
||||
async def channel_reset(ctx: ApplicationContext): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
if guildConfGet(ctx.guild, "channel") is not None:
|
||||
guildConfReset(ctx.guild, "channel")
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("reset_channel_title", ctx.guild), description=getMsg("reset_channel_description", ctx.guild), color=strToColor(config["color_ok"])))
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("dm_title", message.guild), description=getMsg("dm_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("hint_none_channel_title", ctx.guild), description=getMsg("hint_none_channel_description", ctx.guild), color=strToColor(config["color_warn"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
#=========================================================================================================================
|
||||
|
||||
elif message.content.startswith(f"{prefix}prefix"):
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
fullcmd = message.content.split()
|
||||
|
||||
if message.guild is not None:
|
||||
|
||||
if message.author.guild_permissions.administrator:
|
||||
|
||||
try:
|
||||
|
||||
if fullcmd[1] == "reset":
|
||||
|
||||
if guildConfGet(message.guild, "prefix") is not None:
|
||||
|
||||
guildConfReset(message.guild, "prefix")
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("reset_prefix_title", message.guild), description=getMsg("reset_prefix_description", message.guild).format(config["bot_prefix"], config["bot_prefix"]), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("hint_none_prefix_title", message.guild), description=getMsg("hint_none_prefix_description", message.guild).format(prefix, prefix), color=strToColor(config["color_warn"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
guildConfSet(message.guild, "prefix", fullcmd[1])
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("set_prefix_title", message.guild), description=getMsg("set_prefix_description", message.guild).format(fullcmd[1]), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
except:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_prefix_title", message.guild), description=getMsg("error_prefix_description", message.guild).format(prefix), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("forbidden_title", message.guild), description=getMsg("forbidden_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
#=========================================================================================================================
|
||||
category = client.create_group("category", "Commands related to parent channels category")
|
||||
|
||||
@category.command(name="set", description="Select the voice channel that will be parent to private ones")
|
||||
async def category_set(ctx: ApplicationContext, category: Option(discord.CategoryChannel, "Parent Channel Category")): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
guildConfSet(ctx.guild, "category", category.id)
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("set_category_title", ctx.guild), description=getMsg("set_category_description", ctx.guild).format(category.name), color=strToColor(config["color_ok"])))
|
||||
if guildConfGet(ctx.guild, "channel") is None:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("hint_none_channel_title", ctx.guild), description=getMsg("hint_none_channel_description", ctx.guild), color=strToColor(config["color_warn"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
|
||||
@category.command(name="reset", description="Reset the currently selected parent channel category")
|
||||
async def category_reset(ctx: ApplicationContext): # type: ignore
|
||||
config = loadJson("config.json")
|
||||
if ctx.guild is not None:
|
||||
if guildConfGet(ctx.guild, "category") is not None:
|
||||
guildConfReset(ctx.guild, "category")
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("reset_category_title", ctx.guild), description=getMsg("reset_category_description", ctx.guild), color=strToColor(config["color_ok"])))
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("dm_title", message.guild), description=getMsg("dm_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
elif message.content.startswith(f"{prefix}locale"):
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
fullcmd = message.content.split()
|
||||
|
||||
if message.guild is not None:
|
||||
|
||||
if message.author.guild_permissions.administrator:
|
||||
|
||||
try:
|
||||
|
||||
if fullcmd[1] == "reset":
|
||||
|
||||
if guildConfGet(message.guild, "locale") is not None:
|
||||
|
||||
guildConfReset(message.guild, "locale")
|
||||
appendLog(f"Server's locale has been reset", message.guild)
|
||||
await message.reply(embed=makeEmbed(title=getMsg("reset_locale_title", message.guild), description=getMsg("reset_locale_description", message.guild).format(getMsg("locale_name", message.guild), prefix), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("hint_none_locale_title", message.guild), description=getMsg("hint_none_locale_description", message.guild).format(getMsg("locale_name", message.guild), prefix), color=strToColor(config["color_warn"])), mention_author=False)
|
||||
|
||||
else:
|
||||
|
||||
for locale_file in os.listdir(f"{path}/locale/"):
|
||||
if locale_file[:-5] == fullcmd[1]:
|
||||
guildConfSet(message.guild, "locale", fullcmd[1])
|
||||
appendLog(f"Server's locale is now set to {fullcmd[1]}", message.guild)
|
||||
await message.reply(embed=makeEmbed(title=getMsg("set_locale_title", message.guild), description=getMsg("set_locale_description", message.guild).format(getMsg("locale_name", message.guild)), color=strToColor(config["color_ok"])), mention_author=False)
|
||||
return
|
||||
|
||||
locales = []
|
||||
|
||||
for locale_file in os.listdir(f"{path}/locale/"):
|
||||
locales.append(f"`{locale_file[:-5]}`")
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_locale_title", message.guild), description=getMsg("error_locale_description", message.guild).format(prefix, ", ".join(locales)), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
except:
|
||||
|
||||
locales = []
|
||||
|
||||
for locale_file in os.listdir(f"{path}/locale/"):
|
||||
locales.append(f"`{locale_file[:-5]}`")
|
||||
|
||||
await message.reply(embed=makeEmbed(title=getMsg("error_locale_title", message.guild), description=getMsg("error_locale_description", message.guild).format(prefix, ", ".join(locales)), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("forbidden_title", message.guild), description=getMsg("forbidden_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
else:
|
||||
await message.reply(embed=makeEmbed(title=getMsg("dm_title", message.guild), description=getMsg("dm_description", message.guild), color=strToColor(config["color_error"])), mention_author=False)
|
||||
|
||||
elif message.content.startswith(f"{prefix}help"):
|
||||
|
||||
gotCommand(message)
|
||||
|
||||
await message.reply(embed=getHelpMessage(message, version, prefix=prefix), mention_author=False)
|
||||
|
||||
#if loadJson("config.json")["auto_clear_trash"]:
|
||||
# run func
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("hint_none_category_title", ctx.guild), description=getMsg("hint_none_category_description", ctx.guild), color=strToColor(config["color_warn"])))
|
||||
else:
|
||||
await ctx.respond(embed=makeEmbed(title=getMsg("dm_title", ctx.guild), description=getMsg("dm_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||
#=========================================================================================================================
|
||||
|
||||
appendLog(f"Trying to log in...")
|
||||
|
||||
client.run(loadJson("config.json")["bot_token"])
|
||||
client.run(loadJson("config.json")["bot_token"])
|
Reference in New Issue
Block a user