Compare commits
No commits in common. "main" and "v1.7" have entirely different histories.
173
.gitignore
vendored
173
.gitignore
vendored
@ -1,173 +0,0 @@
|
|||||||
# ---> 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
|
|
||||||
|
|
||||||
# Project
|
|
||||||
venv
|
|
||||||
venv_linux
|
|
||||||
venv_windows
|
|
||||||
|
|
||||||
config.json
|
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": [
|
|
||||||
"config:base"
|
|
||||||
]
|
|
||||||
}
|
|
56
README.md
56
README.md
@ -1,19 +1,5 @@
|
|||||||
<h1 align="center">YusarinBot</h1>
|
# 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)
|
||||||
<p align="center">
|
|
||||||
<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">
|
|
||||||
<img alt="License: GPL v2" src="https://img.shields.io/badge/License-GPL_v2-blue.svg">
|
|
||||||
</a>
|
|
||||||
<a href="https://weblate.end-play.xyz/engage/yusarinbot/">
|
|
||||||
<img src="https://weblate.end-play.xyz/widget/yusarinbot/svg-badge.svg" alt="Translation status" />
|
|
||||||
</a>
|
|
||||||
<a href="https://git.end-play.xyz/profitroll/YusarinBot">
|
|
||||||
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
|
|
||||||
</a>
|
|
||||||
<a href="https://discord.com/invite/2zpzErtnNT">
|
|
||||||
<img alt="Discord" src="https://img.shields.io/discord/940760922346123284">
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
Simple, easy to set up, yet reliable.
|
Simple, easy to set up, yet reliable.
|
||||||
A specially designed bot for creating private voice channels on your Discord servers.
|
A specially designed bot for creating private voice channels on your Discord servers.
|
||||||
@ -22,36 +8,28 @@ 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.
|
> 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)
|
## Installation (Short)
|
||||||
|
|
||||||
1. `git clone https://git.end-play.xyz/profitroll/YusarinBot`
|
1. `git clone https://git.end-play.xyz/profitroll/YusarinBot`
|
||||||
2. `cd YusarinBot`
|
2. `cd YusarinBot`
|
||||||
3. `pip install -r requirements.txt`
|
3. `pip install -r requirements.txt`
|
||||||
4. `cp config_example.json config.json`
|
4. `nano config.json`
|
||||||
5. `nano config.json`
|
5. `python yusarin.py`
|
||||||
6. `python yusarin.py`
|
|
||||||
|
|
||||||
## Installation (Detailed)
|
## Installation (Detailed)
|
||||||
|
1. Download and install Python 3 (3.6+ should be fine)
|
||||||
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: <https://git.end-play.xyz/profitroll/YusarinBot/releases/latest>
|
|
||||||
3. Unpack your archive to folder. Name it YusarinBot for example
|
3. Unpack your archive to folder. Name it YusarinBot for example
|
||||||
4. Change working directory using `cd YusarinBot` or `cd FolderYouHaveCreated`
|
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)
|
5. Run `pip install -r requirements.txt` to install dependencies
|
||||||
6. Run `pip install -r requirements.txt` to install dependencies
|
6. Create new Discord application at https://discord.com/developers/applications
|
||||||
7. [Optionally] run `pip install -r requirements-optional.txt` to install optional dependencies
|
7. You can rename it however you want, set needed descriptions etc
|
||||||
8. Create new Discord application at <https://discord.com/developers/applications>
|
8. Go to "Bot" tab and enable application as bot
|
||||||
9. You can rename it however you want, set needed descriptions etc
|
9. Copy token of your bot
|
||||||
10. Go to "Bot" tab and enable application as bot
|
10. Open file `config.json` with your favorite text editor and paste your token as value of "bot_token" key
|
||||||
11. Copy token of your bot
|
11. Copy your own Discord ID and paste it as value of "owner" key (How to get ID: https://support.playhive.com/discord-user-id/)
|
||||||
12. Copy `config_example.json` to `config.json`
|
12. Bot is ready! Run it using `python yusarin.py`
|
||||||
13. Open file `config.json` with your favorite text editor and paste your token as value of "bot_token" key
|
|
||||||
14. Copy your own Discord ID and paste it as value of "owner" key (How to get ID: <https://support.playhive.com/discord-user-id/>)
|
|
||||||
15. Bot is ready! Run it using `python yusarin.py`
|
|
||||||
|
|
||||||
## Config explanation
|
## 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]
|
- "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]
|
- "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]
|
- "bot_name" - Name of your bot. Is not used anywhere yet [String]
|
||||||
@ -71,7 +49,5 @@ 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]
|
- "auto_clear_timer" - Option that defines how often "auto_clear_trash" will do its job [Integer]
|
||||||
|
|
||||||
## Extra
|
## Extra
|
||||||
|
|
||||||
1. Bot doesn't have any self updaters **yet**
|
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>
|
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)
|
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
from discord import ApplicationContext, CategoryChannel, Option, SlashCommandGroup
|
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
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.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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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(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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await ctx.respond(
|
|
||||||
embed=makeEmbed(
|
|
||||||
title=getMsg("dm_title", ctx.guild),
|
|
||||||
description=getMsg("dm_description", ctx.guild),
|
|
||||||
color=strToColor(config["color_error"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================================================================
|
|
@ -1,155 +0,0 @@
|
|||||||
from discord import (
|
|
||||||
ApplicationContext,
|
|
||||||
Cog,
|
|
||||||
Member,
|
|
||||||
SlashCommandGroup,
|
|
||||||
VoiceChannel,
|
|
||||||
VoiceState,
|
|
||||||
option,
|
|
||||||
utils,
|
|
||||||
)
|
|
||||||
from discord.ext import commands
|
|
||||||
from discord.abc import GuildChannel
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_guild_channel_delete(self, channel: GuildChannel):
|
|
||||||
if isUserVoice(channel):
|
|
||||||
await removeUserVoice(channel)
|
|
||||||
|
|
||||||
@Cog.listener()
|
|
||||||
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 before.channel is not None and len(before.channel.members) == 0:
|
|
||||||
if isUserVoice(vc_from):
|
|
||||||
if not isVoiceOfUser(vc_from, member):
|
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
|
||||||
await changeNomicPerms("deny", vc_from, member)
|
|
||||||
await removeUserVoice(vc_from)
|
|
||||||
|
|
||||||
# If user joined vc
|
|
||||||
if after.channel is not None and after.channel.id == guildConfGet(
|
|
||||||
member.guild, "channel"
|
|
||||||
):
|
|
||||||
if isUserVoice(vc_to):
|
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
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",
|
|
||||||
)
|
|
||||||
@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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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(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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await ctx.respond(
|
|
||||||
embed=makeEmbed(
|
|
||||||
title=getMsg("dm_title", ctx.guild),
|
|
||||||
description=getMsg("dm_description", ctx.guild),
|
|
||||||
color=strToColor(config["color_error"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================================================================
|
|
@ -1,105 +0,0 @@
|
|||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================================================================
|
|
||||||
class CogLocale(commands.Cog):
|
|
||||||
def __init__(self, client):
|
|
||||||
self.client = client
|
|
||||||
|
|
||||||
locale = SlashCommandGroup("locale", "Commands related to bot's locale")
|
|
||||||
|
|
||||||
valid_locales = []
|
|
||||||
files_locales = listdir(f"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(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/"):
|
|
||||||
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:
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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(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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await ctx.respond(
|
|
||||||
embed=makeEmbed(
|
|
||||||
title=getMsg("dm_title", ctx.guild),
|
|
||||||
description=getMsg("dm_description", ctx.guild),
|
|
||||||
color=strToColor(config["color_error"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================================================================
|
|
@ -1,53 +0,0 @@
|
|||||||
from os import getpid, makedirs, system
|
|
||||||
from shutil import rmtree
|
|
||||||
|
|
||||||
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):
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
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"]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================================================================
|
|
410
functions.py
410
functions.py
@ -1,29 +1,14 @@
|
|||||||
|
import gzip
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
import discord # type: ignore
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from gzip import open as gzipopen
|
from pathlib import Path
|
||||||
from os import listdir, makedirs, path, remove, stat
|
|
||||||
from shutil import copyfileobj
|
|
||||||
from typing import Any, Literal, Union
|
|
||||||
|
|
||||||
from discord import (
|
path = Path(__file__).resolve().parent
|
||||||
ApplicationContext,
|
|
||||||
CategoryChannel,
|
|
||||||
Client,
|
|
||||||
Embed,
|
|
||||||
Guild,
|
|
||||||
Member,
|
|
||||||
Message,
|
|
||||||
PermissionOverwrite,
|
|
||||||
TextChannel,
|
|
||||||
VoiceChannel,
|
|
||||||
utils,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from ujson import dumps, loads
|
|
||||||
except ImportError:
|
|
||||||
from json import dumps, loads
|
|
||||||
|
|
||||||
# path = Path(__file__).resolve().parent
|
|
||||||
|
|
||||||
log_size = 512
|
log_size = 512
|
||||||
|
|
||||||
@ -33,41 +18,39 @@ log_size = 512
|
|||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
try:
|
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())
|
output = json.load(json_file)
|
||||||
json_file.close()
|
json_file.close()
|
||||||
debug = output["debug"]
|
debug = output["debug"]
|
||||||
except:
|
except:
|
||||||
debug = debug
|
debug = debug
|
||||||
|
|
||||||
|
|
||||||
# Check latest log size
|
# Check latest log size
|
||||||
def checkSize():
|
def checkSize():
|
||||||
try:
|
global path
|
||||||
if not path.isdir("logs"):
|
path = str(path)
|
||||||
makedirs("logs", exist_ok=True)
|
|
||||||
|
|
||||||
log = stat("logs/latest.log")
|
try:
|
||||||
|
if not os.path.isdir(f"{path}/logs"):
|
||||||
|
os.mkdir(f"{path}/logs")
|
||||||
|
|
||||||
|
log = os.stat(path + '/logs/latest.log')
|
||||||
global log_size
|
global log_size
|
||||||
|
|
||||||
if (log.st_size / 1024) > log_size:
|
if (log.st_size / 1024) > log_size:
|
||||||
with open("logs/latest.log", "rb") as f_in:
|
with open(path + '/logs/latest.log', 'rb') as f_in:
|
||||||
with gzipopen(
|
with gzip.open(f'{path}/logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz', 'wb') as f_out:
|
||||||
f'logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz', "wb"
|
shutil.copyfileobj(f_in, f_out)
|
||||||
) as f_out:
|
print(f'Copied {path}/logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz')
|
||||||
copyfileobj(f_in, f_out)
|
open(path + '/logs/latest.log', 'w').close()
|
||||||
print(
|
|
||||||
f'Copied logs/{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.log.gz'
|
|
||||||
)
|
|
||||||
open("logs/latest.log", "w").close()
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("Not found")
|
print('Not found')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Append string to log
|
# Append string to log
|
||||||
def appendLog(message: str, guild: Union[Guild, None] = None, announce=True) -> None:
|
def appendLog(message, guild=None, announce=True):
|
||||||
global debug
|
global debug
|
||||||
|
global path
|
||||||
|
|
||||||
if guild == None:
|
if guild == None:
|
||||||
message_formatted = f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] {message}'
|
message_formatted = f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] {message}'
|
||||||
@ -82,22 +65,20 @@ def appendLog(message: str, guild: Union[Guild, None] = None, announce=True) ->
|
|||||||
|
|
||||||
checkSize()
|
checkSize()
|
||||||
|
|
||||||
log = open("logs/latest.log", "a") # type: ignore
|
log = open(path + '/logs/latest.log', 'a') # type: ignore
|
||||||
log.write(f"{message_formatted}\n")
|
log.write(f'{message_formatted}\n')
|
||||||
log.close()
|
log.close()
|
||||||
|
|
||||||
|
def saveJson(value, filename):
|
||||||
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:
|
json.dump(value, f, indent=4, ensure_ascii=False)
|
||||||
f.write(dumps(value, indent=4, ensure_ascii=False))
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def loadJson(filename):
|
||||||
def loadJson(filename: str) -> Any:
|
|
||||||
global debug
|
global debug
|
||||||
try:
|
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())
|
output = json.load(json_file)
|
||||||
json_file.close()
|
json_file.close()
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
if debug:
|
if debug:
|
||||||
@ -105,68 +86,60 @@ def loadJson(filename: str) -> Any:
|
|||||||
output = {}
|
output = {}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def colorToStr():
|
def colorToStr():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def strToColor(string):
|
||||||
def strToColor(string: str) -> int:
|
|
||||||
return int(hex(int(string.replace("#", ""), 16)), 0)
|
return int(hex(int(string.replace("#", ""), 16)), 0)
|
||||||
|
|
||||||
|
def gotCommand(message):
|
||||||
def gotCommand(message: Message) -> None:
|
|
||||||
global debug
|
global debug
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Command '{message.content}' from {message.author} ({str(message.author.id)})", message.guild)
|
||||||
f"Command '{message.content}' from {message.author} ({str(message.author.id)})",
|
|
||||||
message.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
appendLog(f"Command '{message.content}' from {message.author}", message.guild)
|
appendLog(f"Command '{message.content}' from {message.author}", message.guild)
|
||||||
|
|
||||||
|
def guildConfGet(guild, variable):
|
||||||
def guildConfGet(guild: Guild, variable: str) -> Any:
|
global path
|
||||||
global debug
|
global debug
|
||||||
try:
|
try:
|
||||||
config = loadJson(f"guilds/{str(guild.id)}/config.json")
|
config = loadJson(f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
return config[variable]
|
return config[variable]
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Could not get guild config key '{variable}' due to {exp}", guild)
|
||||||
f"Could not get guild config key '{variable}' due to {exp}", guild
|
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def guildConfSet(guild, variable, value):
|
||||||
def guildConfSet(guild: Guild, variable: str, value: Any) -> None:
|
global path
|
||||||
config = loadJson(f"guilds/{str(guild.id)}/config.json")
|
config = loadJson(f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
config[variable] = value
|
config[variable] = value
|
||||||
try:
|
try:
|
||||||
saveJson(config, f"guilds/{str(guild.id)}/config.json")
|
saveJson(config, f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
except:
|
except:
|
||||||
makedirs(f"guilds/{str(guild.id)}", exist_ok=True)
|
os.mkdir(f"{path}/guilds/{str(guild.id)}")
|
||||||
makedirs(f"guilds/{str(guild.id)}/channels", exist_ok=True)
|
os.mkdir(f"{path}/guilds/{str(guild.id)}/channels")
|
||||||
saveJson(config, f"guilds/{str(guild.id)}/config.json")
|
saveJson(config, f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
appendLog(f"Guild config key '{variable}' is now set to '{value}'", guild)
|
appendLog(f"Guild config key '{variable}' is now set to '{value}'", guild)
|
||||||
|
|
||||||
|
def guildConfReset(guild, variable):
|
||||||
def guildConfReset(guild: Guild, variable: str) -> None:
|
global path
|
||||||
try:
|
try:
|
||||||
config = loadJson(f"guilds/{str(guild.id)}/config.json")
|
config = loadJson(f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
del config[variable]
|
del config[variable]
|
||||||
try:
|
try:
|
||||||
saveJson(config, f"guilds/{str(guild.id)}/config.json")
|
saveJson(config, f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
except:
|
except:
|
||||||
makedirs(f"guilds/{str(guild.id)}", exist_ok=True)
|
os.mkdir(f"{path}/guilds/{str(guild.id)}")
|
||||||
makedirs(f"guilds/{str(guild.id)}/channels", exist_ok=True)
|
os.mkdir(f"{path}/guilds/{str(guild.id)}/channels")
|
||||||
saveJson(config, f"guilds/{str(guild.id)}/config.json")
|
saveJson(config, f"{path}/guilds/{str(guild.id)}/config.json")
|
||||||
appendLog(f"Guild config key '{variable}' has been reset", guild)
|
appendLog(f"Guild config key '{variable}' has been reset", guild)
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
appendLog(f"Could not reset guild config key '{variable}' due to {exp}", guild)
|
appendLog(f"Could not reset guild config key '{variable}' due to {exp}", guild)
|
||||||
|
|
||||||
|
def guildLocaleGet(guild):
|
||||||
def guildLocaleGet(guild: Guild) -> str:
|
global path
|
||||||
config = loadJson(f"config.json")
|
config = loadJson(f"{path}/config.json")
|
||||||
try:
|
try:
|
||||||
locale = guildConfGet(guild, "locale")
|
locale = guildConfGet(guild, "locale")
|
||||||
except:
|
except:
|
||||||
@ -176,63 +149,57 @@ def guildLocaleGet(guild: Guild) -> str:
|
|||||||
else:
|
else:
|
||||||
return locale
|
return locale
|
||||||
|
|
||||||
|
def getMsg(string, guild=None):
|
||||||
def getMsg(string: str, guild: Union[Guild, None] = None) -> str:
|
global path
|
||||||
|
config = loadJson("config.json")
|
||||||
try:
|
try:
|
||||||
locale = loadJson(f"locale/{guildLocaleGet(guild)}.json")
|
locale = loadJson(f'{path}/locale/{guildLocaleGet(guild)}.json')
|
||||||
return locale["messages"][string]
|
return locale["messages"][string]
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
appendLog(
|
appendLog(f"Could not get locale string named {string} due to exception {exp}", guild)
|
||||||
f"Could not get locale string named {string} due to exception {exp}", guild
|
|
||||||
)
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def makeEmbed(title="", description="", footer="", color=0xffffff):
|
||||||
def makeEmbed(title="", description="", footer="", color=0xFFFFFF) -> Embed:
|
embed=discord.Embed(title=title, description=description, color=color)
|
||||||
embed = Embed(title=title, description=description, color=color)
|
|
||||||
if footer is not None:
|
if footer is not None:
|
||||||
embed.set_footer(text=footer)
|
embed.set_footer(text=footer)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
def channelExists(number, guild, type="Any"):
|
||||||
def channelExists(
|
|
||||||
number: int, guild: Guild, type: Literal["Any", "Text", "Voice"] = "Any"
|
|
||||||
) -> bool:
|
|
||||||
global debug
|
global debug
|
||||||
if number == None:
|
if number == None:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
if type == "Voice":
|
if type == "Voice":
|
||||||
selected_channel = utils.get(guild.channels, id=number)
|
selected_channel = discord.utils.get(guild.channels, id=number)
|
||||||
if isinstance(selected_channel, VoiceChannel):
|
if isinstance(selected_channel, discord.VoiceChannel):
|
||||||
return True
|
return True
|
||||||
elif type == "Text":
|
elif type == "Text":
|
||||||
selected_channel = utils.get(guild.channels, id=number)
|
selected_channel = discord.utils.get(guild.channels, id=number)
|
||||||
if isinstance(selected_channel, TextChannel):
|
if isinstance(selected_channel, discord.TextChannel):
|
||||||
return True
|
return True
|
||||||
elif type == "Any":
|
elif type == "Any":
|
||||||
selected_channel = utils.get(guild.channels, id=number)
|
selected_channel = discord.utils.get(guild.channels, id=number)
|
||||||
return True
|
return True
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(f"Channel ID {str(number)} is not a channel due to {exp}")
|
appendLog(f"Channel ID {str(number)} is not a channel due to {exp}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def channelGetName(number, guild):
|
||||||
def channelGetName(number: int, guild: Guild):
|
|
||||||
global debug
|
global debug
|
||||||
try:
|
try:
|
||||||
selected_channel = utils.get(guild.channels, id=number)
|
selected_channel = discord.utils.get(guild.channels, id=number)
|
||||||
return selected_channel.name
|
return selected_channel.name
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(f"Channel ID {str(number)} is not a channel due to {exp}")
|
appendLog(f"Channel ID {str(number)} is not a channel due to {exp}")
|
||||||
return "Channel doesn't exist"
|
return "Channel doesn't exist"
|
||||||
|
|
||||||
|
def isUserVoice(vc):
|
||||||
def isUserVoice(vc: VoiceChannel) -> bool:
|
global path
|
||||||
try:
|
try:
|
||||||
channels_list = listdir(f"guilds/{str(vc.guild.id)}/channels/")
|
channels_list = os.listdir(f"{path}/guilds/{str(vc.guild.id)}/channels/")
|
||||||
if f"{str(vc.id)}.json" in channels_list:
|
if f"{str(vc.id)}.json" in channels_list:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -240,168 +207,103 @@ def isUserVoice(vc: VoiceChannel) -> bool:
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def removeUserVoice(vc):
|
||||||
async def removeUserVoice(vc: VoiceChannel) -> None:
|
global path
|
||||||
global debug
|
global debug
|
||||||
channels_list = listdir(f"guilds/{str(vc.guild.id)}/channels/")
|
channels_list = os.listdir(f"{path}/guilds/{str(vc.guild.id)}/channels/")
|
||||||
if f"{vc.id}.json" in channels_list:
|
if f"{vc.id}.json" in channels_list:
|
||||||
vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
vc_file = f"{path}/guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
||||||
vc_conf = loadJson(vc_file)
|
vc_conf = loadJson(vc_file)
|
||||||
|
|
||||||
needed_channel = utils.get(vc.guild.channels, id=vc.id)
|
needed_channel = discord.utils.get(vc.guild.channels, id=vc.id)
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
nomic_channel = utils.get(vc.guild.channels, id=vc_conf["nomic"])
|
nomic_channel = discord.utils.get(vc.guild.channels, id=vc_conf["nomic"])
|
||||||
|
|
||||||
remove(vc_file)
|
os.remove(vc_file)
|
||||||
|
|
||||||
if needed_channel is None:
|
|
||||||
appendLog(
|
|
||||||
f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await needed_channel.delete()
|
await needed_channel.delete()
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}", guild=vc.guild)
|
||||||
f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
appendLog(
|
appendLog(f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}", guild=vc.guild)
|
||||||
f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
|
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
if nomic_channel is None:
|
|
||||||
appendLog(
|
|
||||||
f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await nomic_channel.delete()
|
await nomic_channel.delete()
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Removed nomic channel {nomic_channel} ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}", guild=vc.guild)
|
||||||
f"Removed nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
appendLog(
|
appendLog(f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}", guild=vc.guild)
|
||||||
f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
async def createUserVoice(vc, category, member):
|
||||||
async def createUserVoice(
|
global path
|
||||||
vc: VoiceChannel, category: CategoryChannel, member: Member
|
|
||||||
) -> VoiceChannel:
|
|
||||||
global debug
|
global debug
|
||||||
chan = {}
|
chan = {}
|
||||||
overwrites_channel = {
|
overwrites_channel = {
|
||||||
vc.guild.default_role: PermissionOverwrite(view_channel=True),
|
vc.guild.default_role: discord.PermissionOverwrite(view_channel=True),
|
||||||
vc.guild.me: PermissionOverwrite(
|
vc.guild.me: discord.PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True),
|
||||||
read_messages=True, view_channel=True, manage_channels=True
|
member: discord.PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True)
|
||||||
),
|
|
||||||
member: PermissionOverwrite(
|
|
||||||
read_messages=True, view_channel=True, manage_channels=True
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
overwrites_nomic = {
|
overwrites_nomic = {
|
||||||
vc.guild.default_role: PermissionOverwrite(
|
vc.guild.default_role: discord.PermissionOverwrite(view_channel=False, read_messages=False),
|
||||||
view_channel=False, read_messages=False
|
vc.guild.me: discord.PermissionOverwrite(read_messages=True, view_channel=True, manage_channels=True),
|
||||||
),
|
member: discord.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
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
created_channel = await vc.guild.create_voice_channel(
|
created_channel = await vc.guild.create_voice_channel(getMsg("name_voice", vc.guild).format(member.name), category=category, overwrites=overwrites_channel)
|
||||||
getMsg("name_voice", vc.guild).format(member.name),
|
|
||||||
category=category,
|
|
||||||
overwrites=overwrites_channel,
|
|
||||||
)
|
|
||||||
if debug:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Created voice channel '{created_channel}' ({str(created_channel.id)}) for user {member} ({str(member.id)})", guild=vc.guild)
|
||||||
f"Created voice channel '{created_channel}' ({str(created_channel.id)}) for user {member} ({str(member.id)})",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
appendLog(
|
appendLog(f"Created voice channel '{created_channel}' for user {member}", guild=vc.guild)
|
||||||
f"Created voice channel '{created_channel}' for user {member}",
|
if not os.path.isdir(f"{path}/guilds/{str(created_channel.guild.id)}/channels"):
|
||||||
guild=vc.guild,
|
os.mkdir(f"{path}/guilds/{str(created_channel.guild.id)}/channels")
|
||||||
)
|
vc_file = f"{path}/guilds/{str(created_channel.guild.id)}/channels/{str(created_channel.id)}.json"
|
||||||
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
|
chan["ownerid"] = member.id
|
||||||
saveJson(chan, vc_file)
|
saveJson(chan, vc_file)
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
nomic_channel = await vc.guild.create_text_channel(
|
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)))
|
||||||
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:
|
if debug:
|
||||||
appendLog(
|
appendLog(f"Created nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) for channel '{created_channel}' ({str(created_channel.id)})", guild=vc.guild)
|
||||||
f"Created nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) for channel '{created_channel}' ({str(created_channel.id)})",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
appendLog(
|
appendLog(f"Created nomic channel '{nomic_channel}' for channel '{created_channel}'", guild=vc.guild)
|
||||||
f"Created nomic channel '{nomic_channel}' for channel '{created_channel}'",
|
|
||||||
guild=vc.guild,
|
|
||||||
)
|
|
||||||
chan["nomic"] = nomic_channel.id
|
chan["nomic"] = nomic_channel.id
|
||||||
saveJson(chan, vc_file)
|
saveJson(chan, vc_file)
|
||||||
return created_channel
|
return created_channel
|
||||||
|
|
||||||
|
def isVoiceOfUser(vc, member):
|
||||||
def isVoiceOfUser(vc: VoiceChannel, member: Member) -> bool:
|
global path
|
||||||
vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
vc_file = f"{path}/guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
||||||
vc_conf = loadJson(vc_file)
|
vc_conf = loadJson(vc_file)
|
||||||
if vc_conf["ownerid"] == member.id:
|
if vc_conf["ownerid"] == member.id:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def changeNomicPerms(mode, vc, member):
|
||||||
async def changeNomicPerms(
|
global path
|
||||||
mode: Literal["deny", "allow"], vc: VoiceChannel, member: Member
|
vc_file = f"{path}/guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
||||||
) -> None:
|
|
||||||
vc_file = f"guilds/{str(vc.guild.id)}/channels/{str(vc.id)}.json"
|
|
||||||
vc_conf = loadJson(vc_file)
|
vc_conf = loadJson(vc_file)
|
||||||
if loadJson("config.json")["enable_nomic"]:
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
nomic_channel = utils.get(vc.guild.channels, id=vc_conf["nomic"])
|
nomic_channel = discord.utils.get(vc.guild.channels, id=vc_conf["nomic"])
|
||||||
if mode == "deny":
|
if mode == "deny":
|
||||||
await nomic_channel.set_permissions(member, view_channel=False)
|
await nomic_channel.set_permissions(member, view_channel=False)
|
||||||
else:
|
else:
|
||||||
await nomic_channel.set_permissions(member, view_channel=True)
|
await nomic_channel.set_permissions(member, view_channel=True)
|
||||||
|
|
||||||
|
async def clearTrash(client):
|
||||||
async def clearTrash(client: Client):
|
global path
|
||||||
if not path.isdir(f"guilds/"):
|
if not os.path.isdir(f"{path}/guilds/"):
|
||||||
makedirs(f"guilds", exist_ok=True)
|
os.mkdir(f"{path}/guilds")
|
||||||
guilds_list = listdir(f"guilds/")
|
guilds_list = os.listdir(f"{path}/guilds/")
|
||||||
for guild in guilds_list:
|
for guild in guilds_list:
|
||||||
guild_object = client.get_guild(int(guild))
|
guild_object = client.get_guild(int(guild))
|
||||||
if path.isdir(f"guilds/{guild}/channels"):
|
if os.path.isdir(f"{path}/guilds/{guild}/channels"):
|
||||||
channels_list = listdir(f"guilds/{guild}/channels/")
|
channels_list = os.listdir(f"{path}/guilds/{guild}/channels/")
|
||||||
for channel in channels_list:
|
for channel in channels_list:
|
||||||
channel_id = channel[:-5]
|
channel_id = channel[:-5]
|
||||||
try:
|
try:
|
||||||
selected_channel = utils.get(
|
selected_channel = discord.utils.get(guild_object.voice_channels, id=int(channel_id))
|
||||||
guild_object.voice_channels, id=int(channel_id)
|
channel_owner = loadJson(f"{path}/guilds/{guild}/channels/{channel}")["ownerid"]
|
||||||
)
|
|
||||||
channel_owner = loadJson(f"guilds/{guild}/channels/{channel}")[
|
|
||||||
"ownerid"
|
|
||||||
]
|
|
||||||
remove_channel = True
|
remove_channel = True
|
||||||
for member in selected_channel.members:
|
for member in selected_channel.members:
|
||||||
if member.id == channel_owner:
|
if member.id == channel_owner:
|
||||||
@ -409,74 +311,44 @@ async def clearTrash(client: Client):
|
|||||||
if remove_channel:
|
if remove_channel:
|
||||||
await removeUserVoice(selected_channel)
|
await removeUserVoice(selected_channel)
|
||||||
except:
|
except:
|
||||||
remove(f"guilds/{guild}/channels/{channel_id}.json")
|
os.remove(f"{path}/guilds/{guild}/channels/{channel_id}.json")
|
||||||
|
|
||||||
|
|
||||||
#async def autoClearTrash(client):
|
#async def autoClearTrash(client):
|
||||||
# execute clearTrash every 120 seconds
|
# execute clearTrash every 120 seconds
|
||||||
|
|
||||||
|
def getHelpMessage(ctx, version):
|
||||||
|
|
||||||
def getHelpMessage(ctx: ApplicationContext, version: float) -> Embed:
|
|
||||||
#channelExists(number, guild, type="Voice")
|
#channelExists(number, guild, type="Voice")
|
||||||
|
|
||||||
config = loadJson("config.json")
|
config = loadJson("config.json")
|
||||||
|
|
||||||
if ctx.guild is not None:
|
if ctx.guild is not None:
|
||||||
if channelExists(guildConfGet(ctx.guild, "channel"), ctx.guild, type="Voice"):
|
if channelExists(guildConfGet(ctx.guild, 'channel'), ctx.guild, type="Voice"):
|
||||||
desc_channel = getMsg("help_channel_set", guild=ctx.guild).format(
|
desc_channel = getMsg("help_channel_set", guild=ctx.guild).format(channelGetName(guildConfGet(ctx.guild, 'channel'), ctx.guild))
|
||||||
channelGetName(guildConfGet(ctx.guild, "channel"), ctx.guild)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
desc_channel = getMsg("help_channel_none", guild=ctx.guild)
|
desc_channel = getMsg("help_channel_none", guild=ctx.guild)
|
||||||
|
|
||||||
if channelExists(guildConfGet(ctx.guild, "category"), ctx.guild, type="Any"):
|
if channelExists(guildConfGet(ctx.guild, 'category'), ctx.guild, type="Any"):
|
||||||
desc_category = getMsg("help_category_set", guild=ctx.guild).format(
|
desc_category = getMsg("help_category_set", guild=ctx.guild).format(channelGetName(guildConfGet(ctx.guild, 'category'), ctx.guild))
|
||||||
channelGetName(guildConfGet(ctx.guild, "category"), ctx.guild)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
desc_category = getMsg("help_category_none", guild=ctx.guild)
|
desc_category = getMsg("help_category_none", guild=ctx.guild)
|
||||||
|
|
||||||
desc_locale = getMsg("help_locale", guild=ctx.guild).format(
|
desc_locale = getMsg("help_locale", guild=ctx.guild).format(getMsg("locale_name", ctx.guild))
|
||||||
getMsg("locale_name", ctx.guild)
|
|
||||||
)
|
|
||||||
|
|
||||||
description = "\n".join([desc_locale, desc_channel, desc_category])
|
description = "\n".join([desc_locale, desc_channel, desc_category])
|
||||||
|
|
||||||
embed = Embed(
|
embed=discord.Embed(title=getMsg("help_title", ctx.guild), description=description, color=strToColor(config["color_default"]))
|
||||||
title=getMsg("help_title", ctx.guild),
|
|
||||||
description=description,
|
|
||||||
color=strToColor(config["color_default"]),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
embed = Embed(
|
embed=discord.Embed(title=getMsg("help_title_dm", ctx.guild), color=strToColor(config["color_default"]))
|
||||||
title=getMsg("help_title_dm", ctx.guild),
|
|
||||||
color=strToColor(config["color_default"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
embed.set_author(
|
embed.set_author(name=f'{config["bot_name"]} v{str(version)}', url=config["bot_site"], icon_url=config["bot_icon"])
|
||||||
name=f'{config["bot_name"]} v{str(version)}',
|
|
||||||
url=config["bot_site"],
|
|
||||||
icon_url=config["bot_icon"],
|
|
||||||
)
|
|
||||||
|
|
||||||
if ctx.author.id == config["owner"]:
|
if ctx.author.id == config["owner"]:
|
||||||
embed.add_field(
|
embed.add_field(name=f"/shutdown", value=getMsg("help_cmd_shutdown", ctx.guild), inline=False)
|
||||||
name=f"/shutdown",
|
|
||||||
value=getMsg("help_cmd_shutdown", ctx.guild),
|
|
||||||
inline=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(name=f"/channel set", value=getMsg("help_cmd_channel", ctx.guild), inline=False)
|
||||||
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"/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:
|
if ctx.guild is None:
|
||||||
embed.set_footer(text=getMsg("help_server", ctx.guild))
|
embed.set_footer(text=getMsg("help_server", ctx.guild))
|
||||||
@ -485,25 +357,19 @@ def getHelpMessage(ctx: ApplicationContext, version: float) -> Embed:
|
|||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
async def guildConfigured(guild):
|
||||||
|
|
||||||
async def guildConfigured(guild: Guild) -> str:
|
|
||||||
output = {}
|
output = {}
|
||||||
config = loadJson("config.json")
|
config = loadJson("config.json")
|
||||||
|
|
||||||
for kind in ["channel", "category"]:
|
for kind in ["channel", "category"]:
|
||||||
if guildConfGet(guild, kind) is not None:
|
if guildConfGet(guild, kind) is not None:
|
||||||
try:
|
try:
|
||||||
guild_object = utils.get(guild.categories, id=guildConfGet(guild, kind))
|
guild_object = discord.utils.get(guild.categories, id=guildConfGet(guild, kind))
|
||||||
output[kind] = getMsg("configured_" + kind, guild).format(
|
output[kind] = getMsg("configured_"+kind, guild).format(guild_object.name)
|
||||||
guild_object.name
|
|
||||||
)
|
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
output[kind] = getMsg("unconfigured_"+kind, guild)
|
output[kind] = getMsg("unconfigured_"+kind, guild)
|
||||||
else:
|
else:
|
||||||
output[kind] = getMsg("unconfigured_"+kind, guild)
|
output[kind] = getMsg("unconfigured_"+kind, guild)
|
||||||
|
|
||||||
return getMsg("server_config", guild).format(
|
return getMsg("server_config", guild).format(getMsg("info_locale", guild).format(getMsg("locale_name", guild)), output["channel"], output["category"])
|
||||||
getMsg("info_locale", guild).format(getMsg("locale_name", guild)),
|
|
||||||
output["channel"],
|
|
||||||
output["category"],
|
|
||||||
)
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
ujson==5.10.0
|
|
||||||
py-cord[speed]==2.6.1
|
|
@ -1,2 +1 @@
|
|||||||
py-cord==2.6.1
|
py-cord>=2.0.0b7
|
||||||
requests==2.32.3
|
|
||||||
|
251
yusarin.py
251
yusarin.py
@ -1,75 +1,224 @@
|
|||||||
try:
|
import os
|
||||||
from discord import Activity, ActivityType, ApplicationContext, Bot, Intents
|
import sys
|
||||||
from requests import get
|
import json
|
||||||
except Exception as exp:
|
import shutil
|
||||||
print(
|
import requests # type: ignore
|
||||||
f"Dependencies not installed. Make sure to run 'pip install -r requirements.txt' before first start"
|
import threading
|
||||||
)
|
|
||||||
exit()
|
|
||||||
|
|
||||||
from os import getpid, path
|
try:
|
||||||
|
import discord # type: ignore
|
||||||
|
from discord import ApplicationContext, Option, Intents # type: ignore
|
||||||
|
except Exception as exp:
|
||||||
|
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 *
|
from functions import *
|
||||||
|
pid = os.getpid()
|
||||||
|
version = 1.6
|
||||||
|
|
||||||
pid = getpid()
|
if loadJson("config.json")["owner"] == "SET-OWNER-ID" or loadJson("config.json")["bot_token"] == "SET-BOT-TOKEN":
|
||||||
version = 2.3
|
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://git.end-play.xyz/profitroll/YusarinBot")
|
||||||
|
sys.exit()
|
||||||
if (
|
|
||||||
not path.exists("config.json")
|
|
||||||
or 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"]:
|
if loadJson("config.json")["check_for_updates"]:
|
||||||
appendLog(f"Currently using YusarinBot v{str(version)}")
|
|
||||||
try:
|
try:
|
||||||
releases = get(
|
serv_ver = json.loads(requests.get("https://api.end-play.xyz/version?app=yusarinbot&apikey=publickey").text)["version"]
|
||||||
"https://git.end-play.xyz/api/v1/repos/profitroll/YusarinBot/releases?draft=false&pre-release=false&page=1&limit=1"
|
if float(serv_ver) > version:
|
||||||
).json()
|
appendLog(f"YusarinBot version {serv_ver} is available. Download new version here: https://git.end-play.xyz/profitroll/YusarinBot/releases/latest")
|
||||||
if float(releases[0]["tag_name"].replace("v", "")) > version:
|
appendLog(f"Currently using YusarinBot v{str(version)}")
|
||||||
appendLog(
|
|
||||||
f"YusarinBot version {releases[0]['tag_name']} is available. Download new version here: {releases[0]['html_url']}"
|
|
||||||
)
|
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
appendLog(
|
appendLog(f"Could not get YusarinBot cloud version due to {exp}. Currently using {str(version)}")
|
||||||
f"Could not get YusarinBot cloud version due to {exp}. Currently using {str(version)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
intents = Intents().all()
|
intents = Intents().all()
|
||||||
client = Bot(intents=intents)
|
client = discord.Bot(intents=intents)
|
||||||
|
|
||||||
from cogs.cogCategory import CogCategory
|
|
||||||
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
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
|
|
||||||
appendLog(f"Logged in as {client.user}")
|
appendLog(f"Logged in as {client.user}")
|
||||||
|
|
||||||
config = loadJson("config.json")
|
config = loadJson("config.json")
|
||||||
|
|
||||||
await client.change_presence(
|
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=config["bot_activity"]))
|
||||||
activity=Activity(type=ActivityType.listening, name=config["bot_activity"])
|
|
||||||
)
|
|
||||||
|
|
||||||
await clearTrash(client)
|
await clearTrash(client)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_join(guild):
|
||||||
|
|
||||||
client.add_cog(CogCategory(client))
|
global path
|
||||||
client.add_cog(CogChannel(client))
|
|
||||||
client.add_cog(CogLocale(client))
|
os.mkdir(f"{path}/guilds/{str(guild.id)}")
|
||||||
client.add_cog(CogUtility(client))
|
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)}")
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_voice_state_update(member, before, after):
|
||||||
|
|
||||||
|
global debug
|
||||||
|
|
||||||
|
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:
|
||||||
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
|
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:
|
||||||
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
|
await changeNomicPerms("deny", vc_from, member)
|
||||||
|
if isUserVoice(vc_to):
|
||||||
|
if loadJson("config.json")["enable_nomic"]:
|
||||||
|
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, discord.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:
|
||||||
|
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)
|
||||||
|
|
||||||
|
#=========================================================================================================================
|
||||||
|
@client.slash_command(name="shutdown", description="Restart the bot")
|
||||||
|
async def shutdown(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"])))
|
||||||
|
os.system(f"kill -9 {str(pid)}")
|
||||||
|
else:
|
||||||
|
await ctx.respond(embed=makeEmbed(title=getMsg("admin_title", ctx.guild), description=getMsg("admin_description", ctx.guild), color=strToColor(config["color_error"])))
|
||||||
|
#=========================================================================================================================
|
||||||
|
|
||||||
|
#=========================================================================================================================
|
||||||
|
@client.slash_command(name="help", description="Get information about this server")
|
||||||
|
async def help(ctx: ApplicationContext):
|
||||||
|
await ctx.respond(embed=getHelpMessage(ctx, version))
|
||||||
|
#=========================================================================================================================
|
||||||
|
|
||||||
|
#=========================================================================================================================
|
||||||
|
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:
|
||||||
|
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 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 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 = 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 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...")
|
appendLog(f"Trying to log in...")
|
||||||
client.run(loadJson("config.json")["bot_token"])
|
client.run(loadJson("config.json")["bot_token"])
|
Loading…
Reference in New Issue
Block a user