From 88499c7e0912b7fb3aab9a4037ab1870c557c5d3 Mon Sep 17 00:00:00 2001 From: Faiz Ahmed Date: Mon, 26 Jul 2021 12:34:18 -0400 Subject: [PATCH] added command to update plex libs --- app/bot/cogs/app.py | 12 +++++++++++- app/bot/helper/confighelper.py | 8 ++++++-- run.py | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/bot/cogs/app.py b/app/bot/cogs/app.py index 50f7de0..8634fc8 100644 --- a/app/bot/cogs/app.py +++ b/app/bot/cogs/app.py @@ -17,7 +17,7 @@ roles = None PLEXUSER = "" PLEXPASS = "" PLEX_SERVER_NAME = "" -Plex_LIBS = ["all"] +Plex_LIBS = None if(path.exists('app/config/config.ini')): try: @@ -33,6 +33,11 @@ if(path.exists('app/config/config.ini')): roles = config.get(BOT_SECTION, 'roles') except: pass +if(path.exists('app/config/config.ini')): + try: + Plex_LIBS = config.get(BOT_SECTION, 'plex_libs') + except: + pass try: account = MyPlexAccount(PLEXUSER, PLEXPASS) @@ -44,6 +49,11 @@ except: if roles is not None: roles = list(roles.split(',')) +if Plex_LIBS is None: + Plex_LIBS = ["all"] +else: + Plex_LIBS = list(Plex_LIBS.split(', ')) +print(Plex_LIBS) class app(commands.Cog): def __init__(self, bot): diff --git a/app/bot/helper/confighelper.py b/app/bot/helper/confighelper.py index e07ed13..c3e04fa 100644 --- a/app/bot/helper/confighelper.py +++ b/app/bot/helper/confighelper.py @@ -16,7 +16,7 @@ roles = None PLEXUSER = "" PLEXPASS = "" PLEX_SERVER_NAME = "" -Plex_LIBS = ["all"] +Plex_LIBS = None switch = 0 @@ -59,7 +59,11 @@ if(path.exists('app/config/config.ini')): roles = config.get(BOT_SECTION, 'roles') except: pass - +if(path.exists('app/config/config.ini')): + try: + Plex_LIBS = config.get(BOT_SECTION, 'plex_libs') + except: + pass def get_config(): """ Function to return current config diff --git a/run.py b/run.py index 5e4a212..0f261ab 100644 --- a/run.py +++ b/run.py @@ -90,6 +90,20 @@ async def setupplex(ctx): reload() await ctx.author.send("Bot has been restarted. Give it a few seconds. 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. ") print("Bot has been restarted. Give it a few seconds.") - + +@bot.command() +@commands.has_permissions(administrator=True) +async def setuplibs(ctx): + libs = "" + libs = await getplex(ctx, "libs") + if libs is None: + return + else: + confighelper.change_config("plex_libs", str(libs)) + print("Plex libraries updated. Restarting bot.") + reload() + await ctx.author.send("Bot has been restarted. Give it a few seconds. 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. ") + print("Bot has been restarted. Give it a few seconds.") + bot.load_extension(f'app.bot.cogs.app') bot.run(Discord_bot_token) \ No newline at end of file