BUG FIXES

This commit is contained in:
Yoruio
2022-07-11 22:31:10 -06:00
parent 1efc4e0686
commit dec952e198
3 changed files with 202 additions and 116 deletions

View File

@@ -18,6 +18,83 @@ BOT_SECTION = 'bot_envs'
plex_configured = True plex_configured = True
jellyfin_configured = True jellyfin_configured = True
config = configparser.ConfigParser()
config.read(CONFIG_PATH)
# Get Plex config
try:
PLEXUSER = config.get(BOT_SECTION, 'plex_user')
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
except:
print("Could not load plex config")
plex_configured = False
# Get Plex roles config
try:
plex_roles = config.get(BOT_SECTION, 'plex_roles')
except:
plex_roles = None
if plex_roles:
plex_roles = list(plex_roles.split(','))
else:
plex_roles = []
# Get Plex libs config
try:
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
except:
Plex_LIBS = None
if Plex_LIBS is None:
Plex_LIBS = ["all"]
else:
Plex_LIBS = list(Plex_LIBS.split(','))
# Get Jellyfin config
try:
JELLYFIN_SERVER_URL = config.get(BOT_SECTION, 'jellyfin_server_url')
JELLYFIN_API_KEY = config.get(BOT_SECTION, "jellyfin_api_key")
except:
jellyfin_configured = False
# Get Jellyfin roles config
try:
jellyfin_roles = config.get(BOT_SECTION, 'jellyfin_roles')
except:
jellyfin_roles = None
if jellyfin_roles:
jellyfin_roles = list(jellyfin_roles.split(','))
else:
jellyfin_roles = []
# Get Jellyfin libs config
try:
jellyfin_libs = config.get(BOT_SECTION, 'jellyfin_libs')
except:
jellyfin_libs = None
if jellyfin_libs is None:
jellyfin_libs = ["all"]
else:
jellyfin_libs = list(jellyfin_libs.split(','))
# Get Enable config
try:
USE_JELLYFIN = config.get(BOT_SECTION, 'jellyfin_enabled')
USE_JELLYFIN = USE_JELLYFIN.lower() == "true"
except:
USE_JELLYFIN = False
try:
USE_PLEX = config.get(BOT_SECTION, "plex_enabled")
USE_PLEX = USE_PLEX.lower() == "true"
except:
USE_PLEX = False
try:
synced = not (float(config.get(BOT_SECTION, "sync_version")) < MEMBARR_VERSION)
except:
synced = False
if USE_PLEX and plex_configured: if USE_PLEX and plex_configured:
try: try:
print("Connecting to Plex......") print("Connecting to Plex......")
@@ -252,37 +329,41 @@ class app(commands.Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_remove(self, member): async def on_member_remove(self, member):
email = db.get_useremail(member.id) if USE_PLEX and plex_configured:
plexhelper.plexremove(plex,email) email = db.get_useremail(member.id)
jellyfin_username = db.get_jellyfin_username(member.id) plexhelper.plexremove(plex,email)
jelly.remove_user(jellyfin_username)
if USE_JELLYFIN and jellyfin_configured:
jellyfin_username = db.get_jellyfin_username(member.id)
jelly.remove_user(jellyfin_username)
deleted = db.delete_user(member.id) deleted = db.delete_user(member.id)
if deleted: if deleted:
print("Removed {} from db because user left discord server.".format(email)) print("Removed {} from db because user left discord server.".format(email))
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@plex_commands.command(name="invite", description="Invite a user to Plex") @plex_commands.command(name="invite", description="Invite a user to 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)
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@plex_commands.command(name="remove", description="Remove a user from Plex") @plex_commands.command(name="remove", description="Remove a user from 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)
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@jellyfin_commands.command(name="invite", description="Invite a user to Jellyfin") @jellyfin_commands.command(name="invite", description="Invite a user to 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 user created!", {'Username': username, 'Password': f"||{password}||"}) await embedcustom(interaction.response, "Jellyfin user created!", {'Username': username, 'Password': f"||{password}||"})
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@jellyfin_commands.command(name="remove", description="Remove a user from Jellyfin") @jellyfin_commands.command(name="remove", description="Remove a user from 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)
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@membarr_commands.command(name="dbadd", description="Add a user to the Membarr database") @membarr_commands.command(name="dbadd", description="Add a user to the Membarr database")
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()
@@ -300,7 +381,7 @@ class app(commands.Cog):
await embedinfo(interaction.response, 'There was an error adding this user to database. Check Membarr logs for more info') await embedinfo(interaction.response, 'There was an error adding this user to database. Check Membarr logs for more info')
print(e) print(e)
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@membarr_commands.command(name="dbls", description="View Membarr database") @membarr_commands.command(name="dbls", description="View Membarr database")
async def dbls(self, interaction: discord.Interaction): async def dbls(self, interaction: discord.Interaction):
@@ -334,7 +415,7 @@ class app(commands.Cog):
await interaction.response.send_message(embed = embed, ephemeral=True) await interaction.response.send_message(embed = embed, ephemeral=True)
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
@membarr_commands.command(name="dbrm", description="Remove user from Membarr database") @membarr_commands.command(name="dbrm", description="Remove user from Membarr database")
async def dbrm(self, interaction: discord.Interaction, position: int): async def dbrm(self, interaction: discord.Interaction, position: int):
embed = discord.Embed(title='Membarr Database.') embed = discord.Embed(title='Membarr Database.')

View File

@@ -41,98 +41,103 @@ if(path.exists('bot.env')):
except Exception as e: except Exception as e:
pass pass
try: try:
Discord_bot_token = str(os.environ['token']) Discord_bot_token = str(os.environ['token'])
switch = 1 switch = 1
except Exception as e: except Exception as e:
pass pass
if(path.exists(CONFIG_PATH)): if not (path.exists(CONFIG_PATH)):
config = configparser.ConfigParser() with open (CONFIG_PATH, 'w') as fp:
config.read(CONFIG_PATH) pass
# Get Plex config
try:
PLEXUSER = config.get(BOT_SECTION, 'plex_user')
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
except:
print("Could not load plex config")
plex_configured = False
# Get Plex roles config
try:
plex_roles = config.get(BOT_SECTION, 'plex_roles')
except:
print("Could not get Plex roles config")
plex_roles = None
if plex_roles:
plex_roles = list(plex_roles.split(','))
else:
plex_roles = []
# Get Plex libs config config = configparser.ConfigParser()
try: config.read(CONFIG_PATH)
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
except:
print("Could not get Plex libs config. Defaulting to all libraries.")
Plex_LIBS = None
if Plex_LIBS is None:
Plex_LIBS = ["all"]
else:
Plex_LIBS = list(Plex_LIBS.split(','))
# Get Jellyfin config
try:
JELLYFIN_SERVER_URL = config.get(BOT_SECTION, 'jellyfin_server_url')
JELLYFIN_API_KEY = config.get(BOT_SECTION, "jellyfin_api_key")
except:
print("Could not load Jellyfin config")
jellyfin_configured = False
# Get Jellyfin roles config # Get Plex config
try: try:
jellyfin_roles = config.get(BOT_SECTION, 'jellyfin_roles') PLEXUSER = config.get(BOT_SECTION, 'plex_user')
except: PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
print("Could not get Jellyfin roles config") PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
jellyfin_roles = None except:
if jellyfin_roles: print("Could not load plex config")
jellyfin_roles = list(jellyfin_roles.split(',')) plex_configured = False
else:
jellyfin_roles = []
# Get Jellyfin libs config # Get Plex roles config
try: try:
jellyfin_libs = config.get(BOT_SECTION, 'jellyfin_libs') plex_roles = config.get(BOT_SECTION, 'plex_roles')
except: except:
print("Could not get Jellyfin libs config. Defaulting to all libraries.") print("Could not get Plex roles config")
jellyfin_libs = None plex_roles = None
if jellyfin_libs is None: if plex_roles:
jellyfin_libs = ["all"] plex_roles = list(plex_roles.split(','))
else: else:
jellyfin_libs = list(jellyfin_libs.split(',')) plex_roles = []
# Get Plex libs config
try:
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
except:
print("Could not get Plex libs config. Defaulting to all libraries.")
Plex_LIBS = None
if Plex_LIBS is None:
Plex_LIBS = ["all"]
else:
Plex_LIBS = list(Plex_LIBS.split(','))
# Get Enable config # Get Jellyfin config
try: try:
USE_JELLYFIN = config.get(BOT_SECTION, 'jellyfin_enabled') JELLYFIN_SERVER_URL = config.get(BOT_SECTION, 'jellyfin_server_url')
USE_JELLYFIN = USE_JELLYFIN.lower() == "true" JELLYFIN_API_KEY = config.get(BOT_SECTION, "jellyfin_api_key")
except: except:
print("Could not get Jellyfin enable config. Defaulting to False") print("Could not load Jellyfin config")
USE_JELLYFIN = False jellyfin_configured = False
try: # Get Jellyfin roles config
USE_PLEX = config.get(BOT_SECTION, "plex_enabled") try:
USE_PLEX = USE_PLEX.lower() == "true" jellyfin_roles = config.get(BOT_SECTION, 'jellyfin_roles')
except: except:
print("Could not get Plex enable config. Defaulting to False") print("Could not get Jellyfin roles config")
USE_PLEX = False jellyfin_roles = None
if jellyfin_roles:
try: jellyfin_roles = list(jellyfin_roles.split(','))
synced = not (float(config.get(BOT_SECTION, "sync_version")) < MEMBARR_VERSION) else:
except: jellyfin_roles = []
print("Could not find previously synced version. Setting synced to false.")
synced = False # Get Jellyfin libs config
try:
jellyfin_libs = config.get(BOT_SECTION, 'jellyfin_libs')
except:
print("Could not get Jellyfin libs config. Defaulting to all libraries.")
jellyfin_libs = None
if jellyfin_libs is None:
jellyfin_libs = ["all"]
else:
jellyfin_libs = list(jellyfin_libs.split(','))
# Get Enable config
try:
USE_JELLYFIN = config.get(BOT_SECTION, 'jellyfin_enabled')
USE_JELLYFIN = USE_JELLYFIN.lower() == "true"
except:
print("Could not get Jellyfin enable config. Defaulting to False")
USE_JELLYFIN = False
try:
USE_PLEX = config.get(BOT_SECTION, "plex_enabled")
USE_PLEX = USE_PLEX.lower() == "true"
except:
print("Could not get Plex enable config. Defaulting to False")
USE_PLEX = False
try:
synced = not (float(config.get(BOT_SECTION, "sync_version")) < MEMBARR_VERSION)
except:
print("Could not find previously synced version. Setting synced to false.")
synced = False
def get_config(): def get_config():
""" """

50
run.py
View File

@@ -65,7 +65,7 @@ plex_commands = app_commands.Group(name="plexsettings", description="Membarr Ple
jellyfin_commands = app_commands.Group(name="jellyfinsettings", description="Membarr Jellyfin commands") jellyfin_commands = app_commands.Group(name="jellyfinsettings", description="Membarr Jellyfin commands")
@plex_commands.command(name="addrole", description="Add a role to automatically add users to Plex") @plex_commands.command(name="addrole", description="Add a role to automatically add users to Plex")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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.
@@ -81,11 +81,11 @@ async def plexroleadd(interaction: discord.Interaction, role: discord.Role):
confighelper.change_config("plex_roles", saveroles) confighelper.change_config("plex_roles", saveroles)
await interaction.response.send_message("Updated Plex roles. Bot is restarting. Please wait.", ephemeral=True) await interaction.response.send_message("Updated Plex roles. Bot is restarting. Please wait.", ephemeral=True)
print("Plex roles updated. Restarting bot, Give it a few seconds.") print("Plex roles updated. Restarting bot, Give it a few seconds.")
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@plex_commands.command(name="removerole", description="Stop adding users with a role to Plex") @plex_commands.command(name="removerole", description="Stop adding users with a role to Plex")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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}\" is currently not a Plex role.") await embederror(interaction.response, f"\"{role.name}\" is currently not a Plex role.")
@@ -95,7 +95,7 @@ async def plexroleremove(interaction: discord.Interaction, role: discord.Role):
await interaction.response.send_message(f"Membarr will stop auto-adding \"{role.name}\" to Plex", ephemeral=True) await interaction.response.send_message(f"Membarr will stop auto-adding \"{role.name}\" to Plex", ephemeral=True)
@plex_commands.command(name="listroles", description="List all roles whose members will be automatically added to Plex") @plex_commands.command(name="listroles", description="List all roles whose members will be automatically added to Plex")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
async def plexrolels(interaction: discord.Interaction): async def plexrolels(interaction: discord.Interaction):
await interaction.response.send_message( await interaction.response.send_message(
"The following roles are being automatically added to Plex:\n" + "The following roles are being automatically added to Plex:\n" +
@@ -103,7 +103,7 @@ async def plexrolels(interaction: discord.Interaction):
) )
@plex_commands.command(name="setup", description="Setup Plex integration") @plex_commands.command(name="setup", description="Setup Plex integration")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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):
confighelper.change_config("plex_user", str(username)) confighelper.change_config("plex_user", str(username))
confighelper.change_config("plex_pass", str(password)) confighelper.change_config("plex_pass", str(password))
@@ -114,11 +114,11 @@ async def setupplex(interaction: discord.Interaction, username: str, password: s
"Please check logs and make sure you see the line: `Logged into plex`. If not run this command again and make sure you enter the right values.", "Please check logs and make sure you see the line: `Logged into plex`. If not run this command again and make sure you enter the right values.",
ephemeral=True ephemeral=True
) )
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@jellyfin_commands.command(name="addrole", description="Add a role to automatically add users to Jellyfin") @jellyfin_commands.command(name="addrole", description="Add a role to automatically add users to Jellyfin")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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.
@@ -131,11 +131,11 @@ async def jellyroleadd(interaction: discord.Interaction, role: discord.Role):
confighelper.change_config("jellyfin_roles", saveroles) confighelper.change_config("jellyfin_roles", saveroles)
await interaction.response.send_message("Updated Jellyfin roles. Bot is restarting. Please wait a few seconds.", ephemeral=True) await interaction.response.send_message("Updated Jellyfin roles. Bot is restarting. Please wait a few seconds.", ephemeral=True)
print("Jellyfin roles updated. Restarting bot.") print("Jellyfin roles updated. Restarting bot.")
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@jellyfin_commands.command(name="removerole", description="Stop adding users with a role to Jellyfin") @jellyfin_commands.command(name="removerole", description="Stop adding users with a role to Jellyfin")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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}\" is currently not a Jellyfin role.") await embederror(interaction.response, f"\"{role.name}\" is currently not a Jellyfin role.")
@@ -145,7 +145,7 @@ async def jellyroleremove(interaction: discord.Interaction, role: discord.Role):
await interaction.response.send_message(f"Membarr will stop auto-adding \"{role.name}\" to Jellyfin", ephemeral=True) await interaction.response.send_message(f"Membarr will stop auto-adding \"{role.name}\" to Jellyfin", ephemeral=True)
@jellyfin_commands.command(name="listroles", description="List all roles whose members will be automatically added to Jellyfin") @jellyfin_commands.command(name="listroles", description="List all roles whose members will be automatically added to Jellyfin")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
async def jellyrolels(interaction: discord.Interaction): async def jellyrolels(interaction: discord.Interaction):
await interaction.response.send_message( await interaction.response.send_message(
"The following roles are being automatically added to Jellyfin:\n" + "The following roles are being automatically added to Jellyfin:\n" +
@@ -153,7 +153,7 @@ async def jellyrolels(interaction: discord.Interaction):
) )
@jellyfin_commands.command(name="setup", description="Setup Jellyfin integration") @jellyfin_commands.command(name="setup", description="Setup Jellyfin integration")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
async def setupjelly(interaction: discord.Interaction, server_url: str, api_key: str): async def setupjelly(interaction: discord.Interaction, server_url: str, api_key: str):
# get rid of training slashes # get rid of training slashes
server_url = server_url.rstrip('/') server_url = server_url.rstrip('/')
@@ -185,13 +185,13 @@ async def setupjelly(interaction: discord.Interaction, server_url: str, api_key:
confighelper.change_config("jellyfin_server_url", str(server_url)) confighelper.change_config("jellyfin_server_url", str(server_url))
confighelper.change_config("jellyfin_api_key", str(api_key)) confighelper.change_config("jellyfin_api_key", str(api_key))
print("Jellyfin server URL and API key updated. Restarting bot.") print("Jellyfin server URL and API key updated. Restarting bot.")
await interaction.interaction.send_message("Jellyfin server URL and API key updated. Restarting bot.", ephemeral=True) await interaction.response.send_message("Jellyfin server URL and API key updated. Restarting bot.", ephemeral=True)
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@plex_commands.command(name="setuplibs", description="Setup libraries that new users can access") @plex_commands.command(name="setuplibs", description="Setup libraries that new users can access")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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, "libraries string is empty.") await embederror(interaction.response, "libraries string is empty.")
@@ -202,11 +202,11 @@ async def setupplexlibs(interaction: discord.Interaction, libraries:str):
confighelper.change_config("plex_libs", str(libraries)) confighelper.change_config("plex_libs", str(libraries))
print("Plex libraries updated. Restarting bot. Please wait.") print("Plex libraries updated. Restarting bot. Please wait.")
await interaction.response.send_message("Jellyfin libraries updated. Please wait a few seconds for bot to restart.", ephemeral=True) await interaction.response.send_message("Jellyfin libraries updated. Please wait a few seconds for bot to restart.", ephemeral=True)
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@jellyfin_commands.command(name="setuplibs", description="Setup libraries that new users can access") @jellyfin_commands.command(name="setuplibs", description="Setup libraries that new users can access")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
async def setupjellylibs(interaction: discord.Interaction, libraries:str): async def setupjellylibs(interaction: discord.Interaction, libraries:str):
if not libraries is None: if not libraries is None:
await embederror(interaction.response, "libraries string is empty.") await embederror(interaction.response, "libraries string is empty.")
@@ -217,39 +217,39 @@ async def setupjellylibs(interaction: discord.Interaction, libraries:str):
confighelper.change_config("jellyfin_libs", str(libraries)) confighelper.change_config("jellyfin_libs", str(libraries))
print("Jellyfin libraries updated. Restarting bot. Please wait.") print("Jellyfin libraries updated. Restarting bot. Please wait.")
await interaction.response.send_message("Jellyfin libraries updated. Please wait a few seconds for bot to restart.", ephemeral=True) await interaction.response.send_message("Jellyfin libraries updated. Please wait a few seconds for bot to restart.", ephemeral=True)
reload() await reload()
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
# Enable / Disable Plex integration # Enable / Disable Plex integration
@plex_commands.command(name="enable", description="Enable auto-adding users to Plex") @plex_commands.command(name="enable", description="Enable auto-adding users to Plex")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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 already enabled.", ephemeral=True) await interaction.response.send_message("Plex already enabled.", ephemeral=True)
return return
confighelper.change_config("plex_enabled", True) confighelper.change_config("plex_enabled", True)
print("Plex enabled, reloading server") print("Plex enabled, reloading server")
reload() await reload()
confighelper.USE_PLEX = True confighelper.USE_PLEX = True
await interaction.response.send_message("Plex enabled. Restarting server. Give it a few seconds.", ephemeral=True) await interaction.response.send_message("Plex enabled. Restarting server. Give it a few seconds.", ephemeral=True)
print("Bot has restarted. Give it a few seconds.") print("Bot has restarted. Give it a few seconds.")
@plex_commands.command(name="disable", description="Disable adding users to Plex") @plex_commands.command(name="disable", description="Disable adding users to Plex")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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 already disabled.", ephemeral=True) await interaction.response.send_message("Plex already disabled.", ephemeral=True)
return return
confighelper.change_config("plex_enabled", False) confighelper.change_config("plex_enabled", False)
print("Plex disabled, reloading server") print("Plex disabled, reloading server")
reload() await reload()
confighelper.USE_PLEX = False confighelper.USE_PLEX = False
await interaction.response.send_message("Plex disabled. Restarting server. Give it a few seconds.", ephemeral=True) await interaction.response.send_message("Plex disabled. Restarting server. Give it a few seconds.", ephemeral=True)
print("Bot has restarted. Give it a few seconds.") print("Bot has restarted. Give it a few seconds.")
# Enable / Disable Jellyfin integration # Enable / Disable Jellyfin integration
@jellyfin_commands.command(name="enable", description="Enable adding users to Jellyfin") @jellyfin_commands.command(name="enable", description="Enable adding users to Jellyfin")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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 already enabled.", ephemeral=True) await interaction.response.send_message("Jellyfin already enabled.", ephemeral=True)
@@ -257,19 +257,19 @@ async def enablejellyfin(interaction: discord.Interaction):
confighelper.change_config("jellyfin_enabled", True) confighelper.change_config("jellyfin_enabled", True)
print("Jellyfin enabled, reloading server") print("Jellyfin enabled, reloading server")
confighelper.USE_JELLYFIN = True confighelper.USE_JELLYFIN = True
reload() await reload()
await interaction.response.send_message("Jellyfin enabled. Restarting server. Give it a few seconds.", ephemeral=True) await interaction.response.send_message("Jellyfin enabled. Restarting server. Give it a few seconds.", ephemeral=True)
print("Bot has restarted. Give it a few seconds.") print("Bot has restarted. Give it a few seconds.")
@jellyfin_commands.command(name="disable", description = "Disable adding users to Jellyfin") @jellyfin_commands.command(name="disable", description = "Disable adding users to Jellyfin")
@commands.has_permissions(administrator=True) @app_commands.checks.has_permissions(administrator=True)
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 already disabled.", ephemeral=True) await interaction.response.send_message("Jellyfin already disabled.", ephemeral=True)
return return
confighelper.change_config("jellyfin_enabled", False) confighelper.change_config("jellyfin_enabled", False)
print("Jellyfin disabled, reloading server") print("Jellyfin disabled, reloading server")
reload() await reload()
confighelper.USE_JELLYFIN = False confighelper.USE_JELLYFIN = False
await interaction.response.send_message("Jellyfin disabled. Restarting server. Give it a few seconds.", ephemeral=True) await interaction.response.send_message("Jellyfin disabled. Restarting server. Give it a few seconds.", ephemeral=True)
print("Bot has restarted. Give it a few seconds.") print("Bot has restarted. Give it a few seconds.")