добавил discord_perm как переменную конфига - роль, имеющая право на отдачу команд серверу.
This commit is contained in:
@@ -110,6 +110,13 @@ except:
|
|||||||
JELLYFIN_EXTERNAL_URL = JELLYFIN_SERVER_URL
|
JELLYFIN_EXTERNAL_URL = JELLYFIN_SERVER_URL
|
||||||
print("Не удалось получить внешний URL-адрес Jellyfin. По умолчанию используется URL-адрес сервера.")
|
print("Не удалось получить внешний URL-адрес Jellyfin. По умолчанию используется URL-адрес сервера.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
DISCORD_SERVER_PERM = config.get(BOT_SECTION, "discord_perm")
|
||||||
|
except:
|
||||||
|
DISCORD_SERVER_PERM = None
|
||||||
|
print("Не удалось получить id роли для управления ботом. Возможна любая дичь.")
|
||||||
|
|
||||||
|
|
||||||
if USE_PLEX and plex_configured:
|
if USE_PLEX and plex_configured:
|
||||||
try:
|
try:
|
||||||
print("Подключение к Plex......")
|
print("Подключение к Plex......")
|
||||||
@@ -363,29 +370,29 @@ class app(commands.Cog):
|
|||||||
if deleted:
|
if deleted:
|
||||||
print("Удален {} из базы данных, поскольку пользователь покинул сервер Discord.".format(email))
|
print("Удален {} из базы данных, поскольку пользователь покинул сервер Discord.".format(email))
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@plex_commands.command(name="invite", description="Пригласить пользователя в Plex")
|
@plex_commands.command(name="invite", description="Пригласить пользователя в Plex")
|
||||||
async def plexinvite(self, interaction: discord.Interaction, email: str):
|
async def plexinvite(self, interaction: discord.Interaction, email: str):
|
||||||
await self.addtoplex(email, interaction.response)
|
await self.addtoplex(email, interaction.response)
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@plex_commands.command(name="remove", description="Удаление пользователя из Plex")
|
@plex_commands.command(name="remove", description="Удаление пользователя из Plex")
|
||||||
async def plexremove(self, interaction: discord.Interaction, email: str):
|
async def plexremove(self, interaction: discord.Interaction, email: str):
|
||||||
await self.removefromplex(email, interaction.response)
|
await self.removefromplex(email, interaction.response)
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@jellyfin_commands.command(name="invite", description="Пригласить пользователя в Jellyfin")
|
@jellyfin_commands.command(name="invite", description="Пригласить пользователя в Jellyfin")
|
||||||
async def jellyfininvite(self, interaction: discord.Interaction, username: str):
|
async def jellyfininvite(self, interaction: discord.Interaction, username: str):
|
||||||
password = jelly.generate_password(16)
|
password = jelly.generate_password(16)
|
||||||
if await self.addtojellyfin(username, password, interaction.response):
|
if await self.addtojellyfin(username, password, interaction.response):
|
||||||
await embedcustom(interaction.response, "Пользователь Jellyfin создан!", {'Username': username, 'Password': f"||{password}||"})
|
await embedcustom(interaction.response, "Пользователь Jellyfin создан!", {'Username': username, 'Password': f"||{password}||"})
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@jellyfin_commands.command(name="remove", description="Удаление пользователя из Jellyfin")
|
@jellyfin_commands.command(name="remove", description="Удаление пользователя из Jellyfin")
|
||||||
async def jellyfinremove(self, interaction: discord.Interaction, username: str):
|
async def jellyfinremove(self, interaction: discord.Interaction, username: str):
|
||||||
await self.removefromjellyfin(username, interaction.response)
|
await self.removefromjellyfin(username, interaction.response)
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@membarr_commands.command(name="dbadd", description="Добавьте пользователя в базу данных Membarr")
|
@membarr_commands.command(name="dbadd", description="Добавьте пользователя в базу данных Membarr")
|
||||||
async def dbadd(self, interaction: discord.Interaction, member: discord.Member, email: str = "", jellyfin_username: str = ""):
|
async def dbadd(self, interaction: discord.Interaction, member: discord.Member, email: str = "", jellyfin_username: str = ""):
|
||||||
email = email.strip()
|
email = email.strip()
|
||||||
@@ -403,7 +410,7 @@ class app(commands.Cog):
|
|||||||
await embedinfo(interaction.response, 'Произошла ошибка при добавлении этого пользователя в базу данных. Проверьте журналы Membarr для получения дополнительной информации.')
|
await embedinfo(interaction.response, 'Произошла ошибка при добавлении этого пользователя в базу данных. Проверьте журналы Membarr для получения дополнительной информации.')
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@membarr_commands.command(name="dbls", description="Посмотреть базу данных Memarr")
|
@membarr_commands.command(name="dbls", description="Посмотреть базу данных Memarr")
|
||||||
async def dbls(self, interaction: discord.Interaction):
|
async def dbls(self, interaction: discord.Interaction):
|
||||||
|
|
||||||
@@ -437,7 +444,7 @@ class app(commands.Cog):
|
|||||||
await interaction.response.send_message(embed = embed, ephemeral=True)
|
await interaction.response.send_message(embed = embed, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
@membarr_commands.command(name="dbrm", description="Удалить пользователя из базы данных Membarr")
|
@membarr_commands.command(name="dbrm", description="Удалить пользователя из базы данных Membarr")
|
||||||
async def dbrm(self, interaction: discord.Interaction, position: int):
|
async def dbrm(self, interaction: discord.Interaction, position: int):
|
||||||
embed = discord.Embed(title='База данных Memarr.')
|
embed = discord.Embed(title='База данных Memarr.')
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ config = configparser.ConfigParser()
|
|||||||
CONFIG_KEYS = ['username', 'password', 'discord_bot_token', 'plex_user', 'plex_pass', 'plex_token',
|
CONFIG_KEYS = ['username', 'password', 'discord_bot_token', 'plex_user', 'plex_pass', 'plex_token',
|
||||||
'plex_base_url', 'plex_roles', 'plex_server_name', 'plex_libs', 'owner_id', 'channel_id',
|
'plex_base_url', 'plex_roles', 'plex_server_name', 'plex_libs', 'owner_id', 'channel_id',
|
||||||
'auto_remove_user', 'jellyfin_api_key', 'jellyfin_server_url', 'jellyfin_roles',
|
'auto_remove_user', 'jellyfin_api_key', 'jellyfin_server_url', 'jellyfin_roles',
|
||||||
'jellyfin_libs', 'plex_enabled', 'jellyfin_enabled', 'jellyfin_external_url']
|
'jellyfin_libs', 'plex_enabled', 'jellyfin_enabled', 'jellyfin_external_url', 'discord_perm']
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
Discord_bot_token = ""
|
Discord_bot_token = ""
|
||||||
@@ -29,6 +29,7 @@ jellyfin_libs = ""
|
|||||||
jellyfin_roles = None
|
jellyfin_roles = None
|
||||||
plex_configured = True
|
plex_configured = True
|
||||||
jellyfin_configured = True
|
jellyfin_configured = True
|
||||||
|
DISCORD_SERVER_PERM = ""
|
||||||
|
|
||||||
switch = 0
|
switch = 0
|
||||||
|
|
||||||
@@ -153,6 +154,12 @@ except:
|
|||||||
print("Не удалось получить конфигурацию включения Plex. По умолчанию установлено значение False")
|
print("Не удалось получить конфигурацию включения Plex. По умолчанию установлено значение False")
|
||||||
USE_PLEX = False
|
USE_PLEX = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
DISCORD_SERVER_PERM = config.get(BOT_SECTION, "discord_perm")
|
||||||
|
except:
|
||||||
|
DISCORD_SERVER_PERM = None
|
||||||
|
print("Не удалось получить id роли для управления ботом. Возможна любая дичь.")
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
"""
|
"""
|
||||||
Function to return current config
|
Function to return current config
|
||||||
|
|||||||
28
run.py
28
run.py
@@ -74,7 +74,7 @@ jellyfin_commands = app_commands.Group(name="jellyfinsettings", description="Mem
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="addrole", description="Роль для автоматического создания пользователя в Plex")
|
@plex_commands.command(name="addrole", description="Роль для автоматического создания пользователя в Plex")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def plexroleadd(interaction: discord.Interaction, role: discord.Role):
|
async def plexroleadd(interaction: discord.Interaction, role: discord.Role):
|
||||||
if len(plex_roles) <= maxroles:
|
if len(plex_roles) <= maxroles:
|
||||||
# Do not add roles multiple times.
|
# Do not add roles multiple times.
|
||||||
@@ -92,7 +92,7 @@ async def plexroleadd(interaction: discord.Interaction, role: discord.Role):
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="removerole", description="Прекратить создавать пользователй Plex с помощью ролей.")
|
@plex_commands.command(name="removerole", description="Прекратить создавать пользователй Plex с помощью ролей.")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def plexroleremove(interaction: discord.Interaction, role: discord.Role):
|
async def plexroleremove(interaction: discord.Interaction, role: discord.Role):
|
||||||
if role.name not in plex_roles:
|
if role.name not in plex_roles:
|
||||||
await embederror(interaction.response, f"\"{role.name}\" больше не связана с Plex.")
|
await embederror(interaction.response, f"\"{role.name}\" больше не связана с Plex.")
|
||||||
@@ -103,7 +103,7 @@ async def plexroleremove(interaction: discord.Interaction, role: discord.Role):
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="listroles", description="Список всех ролей, участники которых будут автоматически добавлены в Plex.")
|
@plex_commands.command(name="listroles", description="Список всех ролей, участники которых будут автоматически добавлены в Plex.")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def plexrolels(interaction: discord.Interaction):
|
async def plexrolels(interaction: discord.Interaction):
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
"Следующие роли автоматически добавляются в Plex:\n" +
|
"Следующие роли автоматически добавляются в Plex:\n" +
|
||||||
@@ -112,7 +112,7 @@ async def plexrolels(interaction: discord.Interaction):
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="setup", description="Настройка интеграции с Plex")
|
@plex_commands.command(name="setup", description="Настройка интеграции с Plex")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def setupplex(interaction: discord.Interaction, username: str, password: str, server_name: str,
|
async def setupplex(interaction: discord.Interaction, username: str, password: str, server_name: str,
|
||||||
base_url: str = "", save_token: bool = True):
|
base_url: str = "", save_token: bool = True):
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
@@ -157,7 +157,7 @@ async def setupplex(interaction: discord.Interaction, username: str, password: s
|
|||||||
|
|
||||||
|
|
||||||
@jellyfin_commands.command(name="addrole", description="Добавление роли для автоматического добавления пользователей в Jellyfin")
|
@jellyfin_commands.command(name="addrole", description="Добавление роли для автоматического добавления пользователей в Jellyfin")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def jellyroleadd(interaction: discord.Interaction, role: discord.Role):
|
async def jellyroleadd(interaction: discord.Interaction, role: discord.Role):
|
||||||
if len(jellyfin_roles) <= maxroles:
|
if len(jellyfin_roles) <= maxroles:
|
||||||
# Do not add roles multiple times.
|
# Do not add roles multiple times.
|
||||||
@@ -176,7 +176,7 @@ async def jellyroleadd(interaction: discord.Interaction, role: discord.Role):
|
|||||||
|
|
||||||
|
|
||||||
@jellyfin_commands.command(name="removerole", description="Прекращение добавления пользователей с ролью в Jellyfin")
|
@jellyfin_commands.command(name="removerole", description="Прекращение добавления пользователей с ролью в Jellyfin")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def jellyroleremove(interaction: discord.Interaction, role: discord.Role):
|
async def jellyroleremove(interaction: discord.Interaction, role: discord.Role):
|
||||||
if role.name not in jellyfin_roles:
|
if role.name not in jellyfin_roles:
|
||||||
await embederror(interaction.response, f"\"{role.name}\" больше не связана с Jellyfin.")
|
await embederror(interaction.response, f"\"{role.name}\" больше не связана с Jellyfin.")
|
||||||
@@ -189,7 +189,7 @@ async def jellyroleremove(interaction: discord.Interaction, role: discord.Role):
|
|||||||
|
|
||||||
@jellyfin_commands.command(name="listroles",
|
@jellyfin_commands.command(name="listroles",
|
||||||
description="Список всех ролей, участники которых будут автоматически добавлены в Jellyfin.")
|
description="Список всех ролей, участники которых будут автоматически добавлены в Jellyfin.")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def jellyrolels(interaction: discord.Interaction):
|
async def jellyrolels(interaction: discord.Interaction):
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
"Следующие роли автоматически добавляются в Jellyfin:\n" +
|
"Следующие роли автоматически добавляются в Jellyfin:\n" +
|
||||||
@@ -198,7 +198,7 @@ async def jellyrolels(interaction: discord.Interaction):
|
|||||||
|
|
||||||
|
|
||||||
@jellyfin_commands.command(name="setup", description="Настройка интеграции Jellyfin")
|
@jellyfin_commands.command(name="setup", description="Настройка интеграции Jellyfin")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def setupjelly(interaction: discord.Interaction, server_url: str, api_key: str, external_url: str = None):
|
async def setupjelly(interaction: discord.Interaction, server_url: str, api_key: str, external_url: str = None):
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
# get rid of training slashes
|
# get rid of training slashes
|
||||||
@@ -247,7 +247,7 @@ async def setupjelly(interaction: discord.Interaction, server_url: str, api_key:
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="setuplibs", description="Библиотеки настройки, к которым могут получить доступ новые пользователи")
|
@plex_commands.command(name="setuplibs", description="Библиотеки настройки, к которым могут получить доступ новые пользователи")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def setupplexlibs(interaction: discord.Interaction, libraries: str):
|
async def setupplexlibs(interaction: discord.Interaction, libraries: str):
|
||||||
if not libraries:
|
if not libraries:
|
||||||
await embederror(interaction.response, "строка библиотек пуста.")
|
await embederror(interaction.response, "строка библиотек пуста.")
|
||||||
@@ -264,7 +264,7 @@ async def setupplexlibs(interaction: discord.Interaction, libraries: str):
|
|||||||
|
|
||||||
|
|
||||||
@jellyfin_commands.command(name="setuplibs", description="Настройка библиотек, к которым могут получить доступ новые пользователи")
|
@jellyfin_commands.command(name="setuplibs", description="Настройка библиотек, к которым могут получить доступ новые пользователи")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def setupjellylibs(interaction: discord.Interaction, libraries: str):
|
async def setupjellylibs(interaction: discord.Interaction, libraries: str):
|
||||||
if not libraries:
|
if not libraries:
|
||||||
await embederror(interaction.response, "строка библиотек пуста.")
|
await embederror(interaction.response, "строка библиотек пуста.")
|
||||||
@@ -282,7 +282,7 @@ async def setupjellylibs(interaction: discord.Interaction, libraries: str):
|
|||||||
|
|
||||||
# Enable / Disable Plex integration
|
# Enable / Disable Plex integration
|
||||||
@plex_commands.command(name="enable", description="Включение автоматического добавления пользователей в Plex")
|
@plex_commands.command(name="enable", description="Включение автоматического добавления пользователей в Plex")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def enableplex(interaction: discord.Interaction):
|
async def enableplex(interaction: discord.Interaction):
|
||||||
if confighelper.USE_PLEX:
|
if confighelper.USE_PLEX:
|
||||||
await interaction.response.send_message("Plex уже включен.", ephemeral=True)
|
await interaction.response.send_message("Plex уже включен.", ephemeral=True)
|
||||||
@@ -296,7 +296,7 @@ async def enableplex(interaction: discord.Interaction):
|
|||||||
|
|
||||||
|
|
||||||
@plex_commands.command(name="disable", description="Отключение добавления пользователей в Plex")
|
@plex_commands.command(name="disable", description="Отключение добавления пользователей в Plex")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def disableplex(interaction: discord.Interaction):
|
async def disableplex(interaction: discord.Interaction):
|
||||||
if not confighelper.USE_PLEX:
|
if not confighelper.USE_PLEX:
|
||||||
await interaction.response.send_message("Plex уже отключен.", ephemeral=True)
|
await interaction.response.send_message("Plex уже отключен.", ephemeral=True)
|
||||||
@@ -311,7 +311,7 @@ async def disableplex(interaction: discord.Interaction):
|
|||||||
|
|
||||||
# Enable / Disable Jellyfin integration
|
# Enable / Disable Jellyfin integration
|
||||||
@jellyfin_commands.command(name="enable", description="Включение добавления пользователей в Jellyfin")
|
@jellyfin_commands.command(name="enable", description="Включение добавления пользователей в Jellyfin")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def enablejellyfin(interaction: discord.Interaction):
|
async def enablejellyfin(interaction: discord.Interaction):
|
||||||
if confighelper.USE_JELLYFIN:
|
if confighelper.USE_JELLYFIN:
|
||||||
await interaction.response.send_message("Jellyfin уже включен.", ephemeral=True)
|
await interaction.response.send_message("Jellyfin уже включен.", ephemeral=True)
|
||||||
@@ -326,7 +326,7 @@ async def enablejellyfin(interaction: discord.Interaction):
|
|||||||
|
|
||||||
|
|
||||||
@jellyfin_commands.command(name="disable", description="Отключение добавления пользователей в Jellyfin")
|
@jellyfin_commands.command(name="disable", description="Отключение добавления пользователей в Jellyfin")
|
||||||
@app_commands.checks.has_permissions(administrator=True)
|
@app_commands.checks.has_role(DISCORD_SERVER_PERM)
|
||||||
async def disablejellyfin(interaction: discord.Interaction):
|
async def disablejellyfin(interaction: discord.Interaction):
|
||||||
if not confighelper.USE_JELLYFIN:
|
if not confighelper.USE_JELLYFIN:
|
||||||
await interaction.response.send_message("Jellyfin уже отключен.", ephemeral=True)
|
await interaction.response.send_message("Jellyfin уже отключен.", ephemeral=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user