From 97d05866e2b55d083cd358ebac8bb0c157d46d37 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kuleshov Date: Wed, 18 Jan 2023 11:23:28 +0200 Subject: [PATCH 1/9] Updated default config link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8a29dd..7cab0f4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Installation instructions are listed below. Please, make sure you have installed 14. Bot is ready! Run it using `python yusarin.py` ## Config explanation -Default configuration file is [available here](https://git.end-play.xyz/profitroll/YusarinBot/blob/main/config.json) +Default configuration file is [available here](https://git.profitroll.eu/profitroll/YusarinBot/src/branch/main/config.json) - "debug" - Option that enables more detailed log messages [Boolean] - "owner" - Discord ID of user who will be able to execute admin commands (`$shutdown` for example) [Integer] - "bot_name" - Name of your bot. Is not used anywhere yet [String] From bad83b026655f7cdb69c148c02d85c96382de9f2 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 20:56:01 +0100 Subject: [PATCH 2/9] Added gitignore --- .gitignore | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..394d5db --- /dev/null +++ b/.gitignore @@ -0,0 +1,166 @@ +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# ---> VisualStudioCode +.vscode/* +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix \ No newline at end of file From 97fe10bb96816841881beadd7bf5f393cb691756 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 20:59:50 +0100 Subject: [PATCH 3/9] Formatted with black --- cogs/cogCategory.py | 88 +++++++++++--- cogs/cogChannel.py | 122 +++++++++++++++---- cogs/cogLocale.py | 83 +++++++++++-- cogs/cogUtility.py | 35 ++++-- functions.py | 290 ++++++++++++++++++++++++++++++++------------ yusarin.py | 45 ++++--- 6 files changed, 509 insertions(+), 154 deletions(-) diff --git a/cogs/cogCategory.py b/cogs/cogCategory.py index 700aab5..a680c23 100644 --- a/cogs/cogCategory.py +++ b/cogs/cogCategory.py @@ -1,35 +1,91 @@ -from discord import ApplicationContext, Option, SlashCommandGroup, CategoryChannel +from discord import ApplicationContext, CategoryChannel, Option, SlashCommandGroup from discord.ext import commands -from functions import getMsg, guildConfGet, guildConfReset, guildConfSet, loadJson, makeEmbed, strToColor -#========================================================================================================================= +from functions import ( + getMsg, + guildConfGet, + guildConfReset, + guildConfSet, + loadJson, + makeEmbed, + strToColor, +) + + +# ========================================================================================================================= class CogCategory(commands.Cog): - def __init__(self, client): self.client = client - category = SlashCommandGroup("category", "Commands related to parent channels category") + category = SlashCommandGroup( + "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(self, ctx: ApplicationContext, category: Option(CategoryChannel, "Parent Channel Category")): # type: ignore + @category.command( + name="set", + description="Select the voice channel that will be parent to private ones", + ) + async def category_set(self, ctx: ApplicationContext, category: Option(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"]))) + 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"]))) + 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"]))) + 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(self, ctx: ApplicationContext): # type: ignore + @category.command( + name="reset", description="Reset the currently selected parent channel category" + ) + async def category_reset(self, 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"]))) + 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 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"]))) + 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"]))) -#========================================================================================================================= \ No newline at end of file + await ctx.respond( + embed=makeEmbed( + title=getMsg("dm_title", ctx.guild), + description=getMsg("dm_description", ctx.guild), + color=strToColor(config["color_error"]), + ) + ) + + +# ========================================================================================================================= diff --git a/cogs/cogChannel.py b/cogs/cogChannel.py index 91e74e9..170fffe 100644 --- a/cogs/cogChannel.py +++ b/cogs/cogChannel.py @@ -1,21 +1,46 @@ -from discord import ApplicationContext, SlashCommandGroup, VoiceChannel, Member, VoiceState, Cog, option, utils +from discord import ( + ApplicationContext, + Cog, + Member, + SlashCommandGroup, + VoiceChannel, + VoiceState, + option, + utils, +) from discord.ext import commands -from functions import appendLog, changeNomicPerms, createUserVoice, getMsg, guildConfGet, guildConfReset, guildConfSet, isUserVoice, isVoiceOfUser, loadJson, makeEmbed, removeUserVoice, strToColor -#========================================================================================================================= +from functions import ( + appendLog, + changeNomicPerms, + createUserVoice, + getMsg, + guildConfGet, + guildConfReset, + guildConfSet, + isUserVoice, + isVoiceOfUser, + loadJson, + makeEmbed, + removeUserVoice, + strToColor, +) + + +# ========================================================================================================================= class CogChannel(commands.Cog): - def __init__(self, client): self.client = client @Cog.listener() - async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState): - + async def on_voice_state_update( + self, member: Member, before: VoiceState, after: VoiceState + ): 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): @@ -25,7 +50,7 @@ class CogChannel(commands.Cog): else: if loadJson("config.json")["enable_nomic"]: await changeNomicPerms("deny", vc_from, member) - + # If user joined vc else: if isUserVoice(vc_from): @@ -39,37 +64,92 @@ class CogChannel(commands.Cog): await changeNomicPerms("allow", vc_to, member) if vc_to.id == guildConfGet(vc_to.guild, "channel"): if guildConfGet(vc_to.guild, "category") is not None: - voice_chan = await createUserVoice(vc_to, utils.get(vc_to.guild.categories, id=guildConfGet(vc_to.guild, "category")), member) + voice_chan = await createUserVoice( + vc_to, + utils.get( + vc_to.guild.categories, + id=guildConfGet(vc_to.guild, "category"), + ), + member, + ) try: await member.move_to(voice_chan) except: await removeUserVoice(voice_chan) else: - appendLog(f"Category for guild {vc_to.guild} ({str(vc_to.guild.id)}) is not set", guild=vc_to.guild) - + appendLog( + f"Category for guild {vc_to.guild} ({str(vc_to.guild.id)}) is not set", + guild=vc_to.guild, + ) + channel = SlashCommandGroup("channel", "Commands related to parent voice channel") - @channel.command(name="set", description="Select the voice channel that will be parent to private ones") + @channel.command( + name="set", + description="Select the voice channel that will be parent to private ones", + ) @option("channel", description="Parent Voice Channel") async def channel_set(self, ctx: ApplicationContext, channel: VoiceChannel): 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"]))) + 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"]))) + 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"]))) + 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(self, ctx: ApplicationContext): + @channel.command( + name="reset", description="Reset the currently selected parent voice channel" + ) + async def channel_reset(self, ctx: ApplicationContext): 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"]))) + 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 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"]))) + 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"]))) -#========================================================================================================================= \ No newline at end of file + await ctx.respond( + embed=makeEmbed( + title=getMsg("dm_title", ctx.guild), + description=getMsg("dm_description", ctx.guild), + color=strToColor(config["color_error"]), + ) + ) + + +# ========================================================================================================================= diff --git a/cogs/cogLocale.py b/cogs/cogLocale.py index e556fdd..3e1e3eb 100644 --- a/cogs/cogLocale.py +++ b/cogs/cogLocale.py @@ -1,11 +1,22 @@ from os import listdir + from discord import ApplicationContext, Option, SlashCommandGroup from discord.ext import commands -from functions import appendLog, getMsg, guildConfGet, guildConfReset, guildConfSet, loadJson, makeEmbed, strToColor -#========================================================================================================================= +from functions import ( + appendLog, + getMsg, + guildConfGet, + guildConfReset, + guildConfSet, + loadJson, + makeEmbed, + strToColor, +) + + +# ========================================================================================================================= class CogLocale(commands.Cog): - def __init__(self, client): self.client = client @@ -17,32 +28,78 @@ class CogLocale(commands.Cog): valid_locales.append(".".join(entry.split(".")[:-1])) @locale.command(name="set", description="Set bot's messages language") - async def locale_set(self, ctx: ApplicationContext, language: Option(str, "One of the languages in list", choices=valid_locales)): # type: ignore + async def locale_set(self, 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 listdir(f"locale/"): + if language + ".json" in listdir(f"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"]))) + 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: valid_locales = [] files_locales = listdir(f"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"]))) + 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"]))) + 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(self, ctx: ApplicationContext): # type: ignore + async def locale_reset(self, 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"]))) + 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 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"]))) + 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"]))) -#========================================================================================================================= \ No newline at end of file + await ctx.respond( + embed=makeEmbed( + title=getMsg("dm_title", ctx.guild), + description=getMsg("dm_description", ctx.guild), + color=strToColor(config["color_error"]), + ) + ) + + +# ========================================================================================================================= diff --git a/cogs/cogUtility.py b/cogs/cogUtility.py index a5dff61..d4e67c1 100644 --- a/cogs/cogUtility.py +++ b/cogs/cogUtility.py @@ -1,40 +1,53 @@ from os import getpid, makedirs, system from shutil import rmtree -from discord import ApplicationContext, slash_command, Cog, Guild + +from discord import ApplicationContext, Cog, Guild, slash_command from discord.ext import commands + from functions import appendLog, getMsg, loadJson, makeEmbed, saveJson, strToColor -#========================================================================================================================= -class CogUtility(commands.Cog): +# ========================================================================================================================= +class CogUtility(commands.Cog): def __init__(self, client): self.client = client @Cog.listener() async def on_guild_join(self, guild: Guild): - makedirs(f"guilds/{str(guild.id)}", exist_ok=True) makedirs(f"guilds/{str(guild.id)}/channels", exist_ok=True) saveJson({}, f"guilds/{str(guild.id)}/config.json") - + appendLog(f"Joined guild '{guild}' with id {str(guild.id)}") @Cog.listener() async def on_guild_remove(self, guild: Guild): - try: rmtree(f"guilds/{str(guild.id)}") except: pass - + appendLog(f"Left guild '{guild}' with id {str(guild.id)}") @slash_command(name="shutdown", description="Restart the bot") async def shutdown(self, ctx: ApplicationContext): config = loadJson("config.json") - if ctx.author.id == config["owner"]: - await ctx.respond(embed=makeEmbed(description=getMsg("shutdown", ctx.guild).format(ctx.author), color=strToColor(config["color_default"]))) + if ctx.author.id == config["owner"]: + await ctx.respond( + embed=makeEmbed( + description=getMsg("shutdown", ctx.guild).format(ctx.author), + color=strToColor(config["color_default"]), + ) + ) system(f"kill -9 {str(getpid())}") else: - await ctx.respond(embed=makeEmbed(title=getMsg("admin_title", ctx.guild), description=getMsg("admin_description", ctx.guild), color=strToColor(config["color_error"]))) -#========================================================================================================================= \ No newline at end of file + await ctx.respond( + embed=makeEmbed( + title=getMsg("admin_title", ctx.guild), + description=getMsg("admin_description", ctx.guild), + color=strToColor(config["color_error"]), + ) + ) + + +# ========================================================================================================================= diff --git a/functions.py b/functions.py index 70a6139..7d6b713 100644 --- a/functions.py +++ b/functions.py @@ -1,14 +1,27 @@ -from gzip import open as gzipopen from datetime import datetime -from os import listdir, makedirs, remove, stat, path +from gzip import open as gzipopen +from os import listdir, makedirs, path, remove, stat from shutil import copyfileobj from typing import Any, Literal, Union -from discord import utils, Embed, TextChannel, VoiceChannel, PermissionOverwrite, Guild, CategoryChannel, Member, Client, ApplicationContext, Message + +from discord import ( + ApplicationContext, + CategoryChannel, + Client, + Embed, + Guild, + Member, + Message, + PermissionOverwrite, + TextChannel, + VoiceChannel, + utils, +) try: - from ujson import loads, dumps + from ujson import dumps, loads except ImportError: - from json import loads, dumps + from json import dumps, loads # path = Path(__file__).resolve().parent @@ -20,38 +33,42 @@ log_size = 512 debug = False try: - with open("config.json", 'r', encoding="utf-8") as json_file: + with open("config.json", "r", encoding="utf-8") as json_file: output = loads(json_file.read()) json_file.close() debug = output["debug"] except: debug = debug + # Check latest log size def checkSize(): - try: if not path.isdir("logs"): makedirs("logs", exist_ok=True) - + log = stat("logs/latest.log") global log_size if (log.st_size / 1024) > log_size: with open("logs/latest.log", "rb") as f_in: - with gzipopen(f'logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz', 'wb') as f_out: + with gzipopen( + f'logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz', "wb" + ) as f_out: copyfileobj(f_in, f_out) - print(f'Copied logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz') + print( + f'Copied logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz' + ) open("logs/latest.log", "w").close() except FileNotFoundError: - print('Not found') + print("Not found") pass + # Append string to log def appendLog(message: str, guild: Union[Guild, None] = None, announce=True) -> None: global debug - - + if guild == None: message_formatted = f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] {message}' else: @@ -59,25 +76,27 @@ def appendLog(message: str, guild: Union[Guild, None] = None, announce=True) -> message_formatted = f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] [{guild} | {str(guild.id)}] {message}' else: message_formatted = f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] [{guild}] {message}' - + if announce: print(message_formatted, flush=True) checkSize() - log = open('logs/latest.log', 'a') # type: ignore - log.write(f'{message_formatted}\n') + log = open("logs/latest.log", "a") # type: ignore + log.write(f"{message_formatted}\n") log.close() + def saveJson(value: Any, filename: str) -> None: - with open(filename, 'w', encoding="utf-8") as f: + with open(filename, "w", encoding="utf-8") as f: f.write(dumps(value, indent=4, ensure_ascii=False)) f.close() + def loadJson(filename: str) -> Any: global debug try: - with open(filename, 'r', encoding="utf-8") as json_file: + with open(filename, "r", encoding="utf-8") as json_file: output = loads(json_file.read()) json_file.close() except Exception as exp: @@ -86,19 +105,26 @@ def loadJson(filename: str) -> Any: output = {} return output + def colorToStr(): pass + def strToColor(string: str) -> int: return int(hex(int(string.replace("#", ""), 16)), 0) + def gotCommand(message: Message) -> None: global debug if debug: - appendLog(f"Command '{message.content}' from {message.author} ({str(message.author.id)})", message.guild) + appendLog( + f"Command '{message.content}' from {message.author} ({str(message.author.id)})", + message.guild, + ) else: appendLog(f"Command '{message.content}' from {message.author}", message.guild) + def guildConfGet(guild: Guild, variable: str) -> Any: global debug try: @@ -106,9 +132,12 @@ def guildConfGet(guild: Guild, variable: str) -> Any: return config[variable] except Exception as exp: if debug: - appendLog(f"Could not get guild config key '{variable}' due to {exp}", guild) + appendLog( + f"Could not get guild config key '{variable}' due to {exp}", guild + ) return None + def guildConfSet(guild: Guild, variable: str, value: Any) -> None: config = loadJson(f"guilds/{str(guild.id)}/config.json") config[variable] = value @@ -120,6 +149,7 @@ def guildConfSet(guild: Guild, variable: str, value: Any) -> None: saveJson(config, f"guilds/{str(guild.id)}/config.json") appendLog(f"Guild config key '{variable}' is now set to '{value}'", guild) + def guildConfReset(guild: Guild, variable: str) -> None: try: config = loadJson(f"guilds/{str(guild.id)}/config.json") @@ -134,6 +164,7 @@ def guildConfReset(guild: Guild, variable: str) -> None: except Exception as exp: appendLog(f"Could not reset guild config key '{variable}' due to {exp}", guild) + def guildLocaleGet(guild: Guild) -> str: config = loadJson(f"config.json") try: @@ -145,21 +176,28 @@ def guildLocaleGet(guild: Guild) -> str: else: return locale + def getMsg(string: str, guild: Union[Guild, None] = None) -> str: try: - locale = loadJson(f'locale/{guildLocaleGet(guild)}.json') + locale = loadJson(f"locale/{guildLocaleGet(guild)}.json") return locale["messages"][string] except Exception as exp: - appendLog(f"Could not get locale string named {string} due to exception {exp}", guild) + appendLog( + f"Could not get locale string named {string} due to exception {exp}", guild + ) return string -def makeEmbed(title="", description="", footer="", color=0xffffff) -> Embed: - embed=Embed(title=title, description=description, color=color) + +def makeEmbed(title="", description="", footer="", color=0xFFFFFF) -> Embed: + embed = Embed(title=title, description=description, color=color) if footer is not None: embed.set_footer(text=footer) return embed -def channelExists(number: int, guild: Guild, type: Literal["Any", "Text", "Voice"] = "Any") -> bool: + +def channelExists( + number: int, guild: Guild, type: Literal["Any", "Text", "Voice"] = "Any" +) -> bool: global debug if number == None: return False @@ -180,6 +218,7 @@ def channelExists(number: int, guild: Guild, type: Literal["Any", "Text", "Voice appendLog(f"Channel ID {str(number)} is not a channel due to {exp}") return False + def channelGetName(number: int, guild: Guild): global debug try: @@ -190,6 +229,7 @@ def channelGetName(number: int, guild: Guild): appendLog(f"Channel ID {str(number)} is not a channel due to {exp}") return "Channel doesn't exist" + def isUserVoice(vc: VoiceChannel) -> bool: try: channels_list = listdir(f"guilds/{str(vc.guild.id)}/channels/") @@ -199,68 +239,116 @@ def isUserVoice(vc: VoiceChannel) -> bool: return False except: return False - + + async def removeUserVoice(vc: VoiceChannel) -> None: global debug channels_list = listdir(f"guilds/{str(vc.guild.id)}/channels/") if f"{vc.id}.json" in channels_list: vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json" vc_conf = loadJson(vc_file) - + needed_channel = utils.get(vc.guild.channels, id=vc.id) if loadJson("config.json")["enable_nomic"]: nomic_channel = utils.get(vc.guild.channels, id=vc_conf["nomic"]) - + remove(vc_file) - + await needed_channel.delete() if debug: - appendLog(f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}", guild=vc.guild) + appendLog( + f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}", + guild=vc.guild, + ) else: - appendLog(f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}", guild=vc.guild) - + appendLog( + f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}", + guild=vc.guild, + ) + if loadJson("config.json")["enable_nomic"]: await nomic_channel.delete() if debug: - appendLog(f"Removed nomic channel {nomic_channel} ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}", guild=vc.guild) + appendLog( + f"Removed nomic channel {nomic_channel} ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}", + guild=vc.guild, + ) else: - appendLog(f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}", guild=vc.guild) + appendLog( + f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}", + guild=vc.guild, + ) else: return -async def createUserVoice(vc: VoiceChannel, category: CategoryChannel, member: Member) -> VoiceChannel: + +async def createUserVoice( + vc: VoiceChannel, category: CategoryChannel, member: Member +) -> VoiceChannel: global debug chan = {} overwrites_channel = { vc.guild.default_role: PermissionOverwrite(view_channel=True), - vc.guild.me: PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True), - member: PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True) + vc.guild.me: PermissionOverwrite( + read_messages=True, view_channel=True, manage_channels=True + ), + member: PermissionOverwrite( + read_messages=True, view_channel=True, manage_channels=True + ), } overwrites_nomic = { - vc.guild.default_role: PermissionOverwrite(view_channel=False, read_messages=False), - vc.guild.me: PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True), - member: PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True) + vc.guild.default_role: PermissionOverwrite( + view_channel=False, read_messages=False + ), + vc.guild.me: PermissionOverwrite( + read_messages=True, view_channel=True, manage_channels=True + ), + member: PermissionOverwrite( + read_messages=True, view_channel=True, manage_channels=True + ), } - created_channel = await vc.guild.create_voice_channel(getMsg("name_voice", vc.guild).format(member.name), category=category, overwrites=overwrites_channel) + created_channel = await vc.guild.create_voice_channel( + getMsg("name_voice", vc.guild).format(member.name), + category=category, + overwrites=overwrites_channel, + ) if debug: - appendLog(f"Created voice channel '{created_channel}' ({str(created_channel.id)}) for user {member} ({str(member.id)})", guild=vc.guild) + appendLog( + f"Created voice channel '{created_channel}' ({str(created_channel.id)}) for user {member} ({str(member.id)})", + guild=vc.guild, + ) else: - appendLog(f"Created voice channel '{created_channel}' for user {member}", guild=vc.guild) + appendLog( + f"Created voice channel '{created_channel}' for user {member}", + guild=vc.guild, + ) if not path.isdir(f"guilds/{str(created_channel.guild.id)}/channels"): makedirs(f"guilds/{str(created_channel.guild.id)}/channels", exist_ok=True) vc_file = f"guilds/{str(created_channel.guild.id)}/channels/{str(created_channel.id)}.json" chan["ownerid"] = member.id saveJson(chan, vc_file) if loadJson("config.json")["enable_nomic"]: - nomic_channel = await vc.guild.create_text_channel(getMsg("name_nomic", vc.guild).format(created_channel.id), category=category, overwrites=overwrites_nomic, topic=getMsg("description_nomic", vc.guild).format(str(created_channel.id))) + nomic_channel = await vc.guild.create_text_channel( + getMsg("name_nomic", vc.guild).format(created_channel.id), + category=category, + overwrites=overwrites_nomic, + topic=getMsg("description_nomic", vc.guild).format(str(created_channel.id)), + ) if debug: - appendLog(f"Created nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) for channel '{created_channel}' ({str(created_channel.id)})", guild=vc.guild) + appendLog( + f"Created nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) for channel '{created_channel}' ({str(created_channel.id)})", + guild=vc.guild, + ) else: - appendLog(f"Created nomic channel '{nomic_channel}' for channel '{created_channel}'", guild=vc.guild) + appendLog( + f"Created nomic channel '{nomic_channel}' for channel '{created_channel}'", + guild=vc.guild, + ) chan["nomic"] = nomic_channel.id saveJson(chan, vc_file) return created_channel + def isVoiceOfUser(vc: VoiceChannel, member: Member) -> bool: vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json" vc_conf = loadJson(vc_file) @@ -269,7 +357,10 @@ def isVoiceOfUser(vc: VoiceChannel, member: Member) -> bool: else: return False -async def changeNomicPerms(mode: Literal["deny", "allow"], vc: VoiceChannel, member: Member) -> None: + +async def changeNomicPerms( + mode: Literal["deny", "allow"], vc: VoiceChannel, member: Member +) -> None: vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json" vc_conf = loadJson(vc_file) if loadJson("config.json")["enable_nomic"]: @@ -279,6 +370,7 @@ async def changeNomicPerms(mode: Literal["deny", "allow"], vc: VoiceChannel, mem else: await nomic_channel.set_permissions(member, view_channel=True) + async def clearTrash(client: Client): if not path.isdir(f"guilds/"): makedirs(f"guilds", exist_ok=True) @@ -290,8 +382,12 @@ async def clearTrash(client: Client): for channel in channels_list: channel_id = channel[:-5] try: - selected_channel = utils.get(guild_object.voice_channels, id=int(channel_id)) - channel_owner = loadJson(f"guilds/{guild}/channels/{channel}")["ownerid"] + selected_channel = utils.get( + guild_object.voice_channels, id=int(channel_id) + ) + channel_owner = loadJson(f"guilds/{guild}/channels/{channel}")[ + "ownerid" + ] remove_channel = True for member in selected_channel.members: if member.id == channel_owner: @@ -301,52 +397,82 @@ async def clearTrash(client: Client): except: remove(f"guilds/{guild}/channels/{channel_id}.json") -#async def autoClearTrash(client): - # execute clearTrash every 120 seconds + +# async def autoClearTrash(client): +# execute clearTrash every 120 seconds + def getHelpMessage(ctx: ApplicationContext, version: float) -> Embed: - - #channelExists(number, guild, type="Voice") - + # channelExists(number, guild, type="Voice") + config = loadJson("config.json") - + if ctx.guild is not None: - if channelExists(guildConfGet(ctx.guild, 'channel'), ctx.guild, type="Voice"): - desc_channel = getMsg("help_channel_set", guild=ctx.guild).format(channelGetName(guildConfGet(ctx.guild, 'channel'), ctx.guild)) + if channelExists(guildConfGet(ctx.guild, "channel"), ctx.guild, type="Voice"): + desc_channel = getMsg("help_channel_set", guild=ctx.guild).format( + channelGetName(guildConfGet(ctx.guild, "channel"), ctx.guild) + ) else: desc_channel = getMsg("help_channel_none", guild=ctx.guild) - - if channelExists(guildConfGet(ctx.guild, 'category'), ctx.guild, type="Any"): - desc_category = getMsg("help_category_set", guild=ctx.guild).format(channelGetName(guildConfGet(ctx.guild, 'category'), ctx.guild)) + + if channelExists(guildConfGet(ctx.guild, "category"), ctx.guild, type="Any"): + desc_category = getMsg("help_category_set", guild=ctx.guild).format( + channelGetName(guildConfGet(ctx.guild, "category"), ctx.guild) + ) else: desc_category = getMsg("help_category_none", guild=ctx.guild) - - desc_locale = getMsg("help_locale", guild=ctx.guild).format(getMsg("locale_name", ctx.guild)) + + desc_locale = getMsg("help_locale", guild=ctx.guild).format( + getMsg("locale_name", ctx.guild) + ) description = "\n".join([desc_locale, desc_channel, desc_category]) - embed=Embed(title=getMsg("help_title", ctx.guild), description=description, color=strToColor(config["color_default"])) + embed = Embed( + title=getMsg("help_title", ctx.guild), + description=description, + color=strToColor(config["color_default"]), + ) else: - embed=Embed(title=getMsg("help_title_dm", ctx.guild), color=strToColor(config["color_default"])) - - embed.set_author(name=f'{config["bot_name"]} v{str(version)}', url=config["bot_site"], icon_url=config["bot_icon"]) - + embed = Embed( + title=getMsg("help_title_dm", ctx.guild), + color=strToColor(config["color_default"]), + ) + + embed.set_author( + name=f'{config["bot_name"]} v{str(version)}', + url=config["bot_site"], + icon_url=config["bot_icon"], + ) + if ctx.author.id == config["owner"]: - embed.add_field(name=f"/shutdown", value=getMsg("help_cmd_shutdown", ctx.guild), inline=False) - - embed.add_field(name=f"/channel set", value=getMsg("help_cmd_channel", ctx.guild), inline=False) - embed.add_field(name=f"/category set", value=getMsg("help_cmd_category", ctx.guild), inline=False) - embed.add_field(name=f"/locale set", value=getMsg("help_cmd_locale", ctx.guild), inline=False) - + embed.add_field( + name=f"/shutdown", + value=getMsg("help_cmd_shutdown", ctx.guild), + inline=False, + ) + + embed.add_field( + name=f"/channel set", value=getMsg("help_cmd_channel", ctx.guild), inline=False + ) + embed.add_field( + name=f"/category set", + value=getMsg("help_cmd_category", ctx.guild), + inline=False, + ) + embed.add_field( + name=f"/locale set", value=getMsg("help_cmd_locale", ctx.guild), inline=False + ) + if ctx.guild is None: embed.set_footer(text=getMsg("help_server", ctx.guild)) else: embed.set_footer(text=getMsg("help_notice_id", ctx.guild)) - + return embed -async def guildConfigured(guild: Guild) -> str: +async def guildConfigured(guild: Guild) -> str: output = {} config = loadJson("config.json") @@ -354,10 +480,16 @@ async def guildConfigured(guild: Guild) -> str: if guildConfGet(guild, kind) is not None: try: guild_object = utils.get(guild.categories, id=guildConfGet(guild, kind)) - output[kind] = getMsg("configured_"+kind, guild).format(guild_object.name) + output[kind] = getMsg("configured_" + kind, guild).format( + guild_object.name + ) except Exception as exp: - output[kind] = getMsg("unconfigured_"+kind, guild) + output[kind] = getMsg("unconfigured_" + kind, guild) else: - output[kind] = getMsg("unconfigured_"+kind, guild) + output[kind] = getMsg("unconfigured_" + kind, guild) - return getMsg("server_config", guild).format(getMsg("info_locale", guild).format(getMsg("locale_name", guild)), output["channel"], output["category"]) + return getMsg("server_config", guild).format( + getMsg("info_locale", guild).format(getMsg("locale_name", guild)), + output["channel"], + output["category"], + ) diff --git a/yusarin.py b/yusarin.py index 7aafc2d..3c7d759 100644 --- a/yusarin.py +++ b/yusarin.py @@ -1,29 +1,42 @@ try: + from discord import Activity, ActivityType, ApplicationContext, Bot, Intents from requests import get - from discord import ApplicationContext, Intents, Bot, ActivityType, Activity, VoiceState except Exception as exp: - print(f"Dependencies not installed. Make sure to run 'pip install -r requirements.txt' before first start") + print( + f"Dependencies not installed. Make sure to run 'pip install -r requirements.txt' before first start" + ) exit() from os import getpid -from shutil import rmtree + from functions import * pid = getpid() version = 1.8 -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 'config.json'\nLearn more here: https://git.end-play.xyz/profitroll/YusarinBot") +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 'config.json'\nLearn more here: https://git.end-play.xyz/profitroll/YusarinBot" + ) exit() if loadJson("config.json")["check_for_updates"]: try: - serv_ver = loads(get("https://api.end-play.xyz/version?app=yusarinbot&apikey=publickey").text)["version"] + serv_ver = loads( + get("https://api.end-play.xyz/version?app=yusarinbot&apikey=publickey").text + )["version"] if float(serv_ver) > version: - appendLog(f"YusarinBot version {serv_ver} is available. Download new version here: https://git.end-play.xyz/profitroll/YusarinBot/releases/latest") + appendLog( + f"YusarinBot version {serv_ver} is available. Download new version here: https://git.end-play.xyz/profitroll/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)}") + appendLog( + f"Could not get YusarinBot cloud version due to {exp}. Currently using {str(version)}" + ) intents = Intents().all() client = Bot(intents=intents) @@ -33,25 +46,29 @@ from cogs.cogChannel import CogChannel from cogs.cogLocale import CogLocale from cogs.cogUtility import CogUtility + @client.slash_command(name="help", description="Get information about this server") async def help(ctx: ApplicationContext): await ctx.respond(embed=getHelpMessage(ctx, version)) + @client.event async def on_ready(): - appendLog(f"Logged in as {client.user}") - + config = loadJson("config.json") - - await client.change_presence(activity=Activity(type=ActivityType.listening, name=config["bot_activity"])) - + + await client.change_presence( + activity=Activity(type=ActivityType.listening, name=config["bot_activity"]) + ) + await clearTrash(client) + client.add_cog(CogCategory(client)) client.add_cog(CogChannel(client)) client.add_cog(CogLocale(client)) client.add_cog(CogUtility(client)) appendLog(f"Trying to log in...") -client.run(loadJson("config.json")["bot_token"]) \ No newline at end of file +client.run(loadJson("config.json")["bot_token"]) From af24a055b6ebb1d4ddf144f03603c6240f7166d9 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:05:46 +0100 Subject: [PATCH 4/9] Updated header --- README.md | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7cab0f4..47c6f4c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,19 @@ -# YusarinBot -[![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) [![Crowdin](https://badges.crowdin.net/yusarinbot/localized.svg)](https://crowdin.com/project/yusarinbot) ![Discord](https://img.shields.io/discord/940760922346123284) +

YusarinBot

+ +

+ + License: GPL v2 + + + Crowdin + + + Code style: black + + + Discord + +

Simple, easy to set up, yet reliable. A specially designed bot for creating private voice channels on your Discord servers. @@ -8,6 +22,7 @@ Installation instructions are listed below. Please, make sure you have installed > Since version 1.5 only slash commands are supported. If you'd like to use old-fashioned commands and commands prefix feature – consider installing [1.4 version](https://git.end-play.xyz/profitroll/YusarinBot/releases/tag/v1.4) which is the last one compatible with those. ## Installation (Short) + 1. `git clone https://git.end-play.xyz/profitroll/YusarinBot` 2. `cd YusarinBot` 3. `pip install -r requirements.txt` @@ -15,23 +30,26 @@ Installation instructions are listed below. Please, make sure you have installed 5. `python yusarin.py` ## Installation (Detailed) + 1. Download and install Python 3.8+ -2. Download bot's release: https://git.end-play.xyz/profitroll/YusarinBot/releases/latest +2. Download bot's release: 3. Unpack your archive to folder. Name it YusarinBot for example 4. Change working directory using `cd YusarinBot` or `cd FolderYouHaveCreated` 5. If you're using Linux system - install [dependencies for Pycord](https://docs.pycord.dev/en/stable/installing.html#installing) 6. Run `pip install -r requirements.txt` to install dependencies 7. [Optionally] run `pip install -r requirements-optional.txt` to install optional dependencies -8. Create new Discord application at https://discord.com/developers/applications +8. Create new Discord application at 9. You can rename it however you want, set needed descriptions etc 10. Go to "Bot" tab and enable application as bot 11. Copy token of your bot 12. Open file `config.json` with your favorite text editor and paste your token as value of "bot_token" key -13. Copy your own Discord ID and paste it as value of "owner" key (How to get ID: https://support.playhive.com/discord-user-id/) +13. Copy your own Discord ID and paste it as value of "owner" key (How to get ID: ) 14. Bot is ready! Run it using `python yusarin.py` ## Config explanation + Default configuration file is [available here](https://git.profitroll.eu/profitroll/YusarinBot/src/branch/main/config.json) + - "debug" - Option that enables more detailed log messages [Boolean] - "owner" - Discord ID of user who will be able to execute admin commands (`$shutdown` for example) [Integer] - "bot_name" - Name of your bot. Is not used anywhere yet [String] @@ -51,6 +69,7 @@ Default configuration file is [available here](https://git.profitroll.eu/profitr - "auto_clear_timer" - Option that defines how often "auto_clear_trash" will do its job [Integer] ## Extra + 1. Bot doesn't have any self updaters **yet** -2. You can add public version of the bot to your Discord server using this link: https://www.end-play.xyz/yusarin/invite -3. If you have questions/suggestions - just join our [Discord Support Server](https://discord.com/invite/2zpzErtnNT) \ No newline at end of file +2. You can add public version of the bot to your Discord server using this link: +3. If you have questions/suggestions - just join our [Discord Support Server](https://discord.com/invite/2zpzErtnNT) From 98ac531a36bf6288575720532637146c71ccb331 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:09:09 +0100 Subject: [PATCH 5/9] Changed version API requests --- yusarin.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/yusarin.py b/yusarin.py index 3c7d759..d0fd833 100644 --- a/yusarin.py +++ b/yusarin.py @@ -25,12 +25,14 @@ if ( if loadJson("config.json")["check_for_updates"]: try: - serv_ver = loads( - get("https://api.end-play.xyz/version?app=yusarinbot&apikey=publickey").text - )["version"] - if float(serv_ver) > version: + release = loads( + get( + "https://git.end-play.xyz/api/v1/repos/profitroll/YusarinBot/releases?draft=false&pre-release=false&page=1&limit=1" + ).json() + )[0] + if float(release["tag_name"].replace("v", "")) > version: appendLog( - f"YusarinBot version {serv_ver} is available. Download new version here: https://git.end-play.xyz/profitroll/YusarinBot/releases/latest" + f"YusarinBot version {release['tag_name']} is available. Download new version here: {release['html_url']}" ) appendLog(f"Currently using YusarinBot v{str(version)}") except Exception as exp: From a2bd55dcdfc63b02ddfc6ff32263429b914ac8bc Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:09:32 +0100 Subject: [PATCH 6/9] Updated version to 1.9 --- yusarin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yusarin.py b/yusarin.py index d0fd833..a088763 100644 --- a/yusarin.py +++ b/yusarin.py @@ -12,7 +12,7 @@ from os import getpid from functions import * pid = getpid() -version = 1.8 +version = 1.9 if ( loadJson("config.json")["owner"] == "SET-OWNER-ID" From c600747848f0534cf612517842dd0206ffac0911 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:09:58 +0100 Subject: [PATCH 7/9] Bump py-cord to 2.4.1 --- requirements-optional.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-optional.txt b/requirements-optional.txt index 3385df7..df40e6b 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -1,2 +1,2 @@ ujson~=5.7.0 -py-cord[speed]~=2.3.2 \ No newline at end of file +py-cord[speed]~=2.4.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 63cac09..7183d79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -py-cord~=2.3.2 +py-cord~=2.4.1 requests~=2.28.2 \ No newline at end of file From 7f1f86ca03a1a7665c854d87e9300ddd4d1986e8 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:26:05 +0100 Subject: [PATCH 8/9] Fixed update checker behavior --- yusarin.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/yusarin.py b/yusarin.py index a088763..70b9966 100644 --- a/yusarin.py +++ b/yusarin.py @@ -24,17 +24,15 @@ if ( exit() if loadJson("config.json")["check_for_updates"]: + appendLog(f"Currently using YusarinBot v{str(version)}") try: - release = loads( - get( - "https://git.end-play.xyz/api/v1/repos/profitroll/YusarinBot/releases?draft=false&pre-release=false&page=1&limit=1" - ).json() - )[0] - if float(release["tag_name"].replace("v", "")) > version: + releases = get( + "https://git.end-play.xyz/api/v1/repos/profitroll/YusarinBot/releases?draft=false&pre-release=false&page=1&limit=1" + ).json() + if float(releases[0]["tag_name"].replace("v", "")) > version: appendLog( - f"YusarinBot version {release['tag_name']} is available. Download new version here: {release['html_url']}" + f"YusarinBot version {releases[0]['tag_name']} is available. Download new version here: {releases[0]['html_url']}" ) - 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)}" From 0f3a6121d61b24f66814e2752e0aaf6ab5bdc493 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 22 Mar 2023 21:30:45 +0100 Subject: [PATCH 9/9] Fixed black badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47c6f4c..b7e2c83 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Crowdin - + Code style: black