feat: Adds some QoL changes

- Logs exception messages when Plex login fails
 - Renames "username" variable in getPlex() to generic naming
 - Changes "roles" config to "plex_roles" in preparation for jellyfin
 integration
 - Changes generic config names to plex specific config name

task: none (because I'm too lazy to set up proper issues)
This commit is contained in:
Yoruio
2022-07-09 00:19:33 -06:00
parent e51311011a
commit a64c43904b
6 changed files with 34 additions and 31 deletions

View File

@@ -1 +1,2 @@
bot.env bot.env
mount

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
mount

View File

@@ -71,9 +71,9 @@ docker run -d --restart unless-stopped --name invitarr -v /path to config:/app/a
``` ```
.setupplex .setupplex
This command is used to setup plex login. This command is used to setup plex login.
.roleadd <@role> .plexroleadd <@role>
These role(s) will be used as the role(s) to automatically invite user to plex These role(s) will be used as the role(s) to automatically invite user to plex
.setuplibs (optional) .setupplexlibs (optional)
This command is used to setup plex libraries. Default is set to all. This command is used to setup plex libraries. Default is set to all.
``` ```

View File

@@ -13,7 +13,7 @@ CONFIG_PATH = 'app/config/config.ini'
BOT_SECTION = 'bot_envs' BOT_SECTION = 'bot_envs'
# settings # settings
roles = None plex_roles = None
PLEXUSER = "" PLEXUSER = ""
PLEXPASS = "" PLEXPASS = ""
PLEX_SERVER_NAME = "" PLEX_SERVER_NAME = ""
@@ -30,7 +30,7 @@ if(path.exists('app/config/config.ini')):
pass pass
if(path.exists('app/config/config.ini')): if(path.exists('app/config/config.ini')):
try: try:
roles = config.get(BOT_SECTION, 'roles') plex_roles = config.get(BOT_SECTION, 'plex_roles')
except: except:
pass pass
if(path.exists('app/config/config.ini')): if(path.exists('app/config/config.ini')):
@@ -43,11 +43,12 @@ try:
account = MyPlexAccount(PLEXUSER, PLEXPASS) account = MyPlexAccount(PLEXUSER, PLEXPASS)
plex = account.resource(PLEX_SERVER_NAME).connect() # returns a PlexServer instance plex = account.resource(PLEX_SERVER_NAME).connect() # returns a PlexServer instance
print('Logged into plex!') print('Logged into plex!')
except: except Exception as e:
print('Error with plex login. Please check username and password and Plex server name or setup plex in the bot.') print('Error with plex login. Please check username and password and Plex server name or setup plex in the bot.')
print(f'Error: {e}')
if roles is not None: if plex_roles is not None:
roles = list(roles.split(',')) plex_roles = list(plex_roles.split(','))
if Plex_LIBS is None: if Plex_LIBS is None:
Plex_LIBS = ["all"] Plex_LIBS = ["all"]
@@ -64,8 +65,8 @@ class app(commands.Cog):
print('Made by Sleepingpirate https://github.com/Sleepingpirates/') print('Made by Sleepingpirate https://github.com/Sleepingpirates/')
print(f'Logged in as {self.bot.user} (ID: {self.bot.user.id})') print(f'Logged in as {self.bot.user} (ID: {self.bot.user.id})')
print('------') print('------')
if roles is None: if plex_roles is None:
print('Configure roles to enable auto invite after a role is assigned.') print('Configure Plex roles to enable auto invite to Plex after a role is assigned.')
async def embederror(self, author, message): async def embederror(self, author, message):
embed1 = discord.Embed(title="ERROR",description=message, color=0xf50000) embed1 = discord.Embed(title="ERROR",description=message, color=0xf50000)
@@ -123,11 +124,11 @@ class app(commands.Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_update(self, before, after): async def on_member_update(self, before, after):
if roles is None: if plex_roles is None:
return return
roles_in_guild = after.guild.roles roles_in_guild = after.guild.roles
role = None role = None
for role_for_app in roles: for role_for_app in plex_roles:
for role_in_guild in roles_in_guild: for role_in_guild in roles_in_guild:
if role_in_guild.name == role_for_app: if role_in_guild.name == role_for_app:
role = role_in_guild role = role_in_guild

View File

@@ -7,12 +7,12 @@ BOT_SECTION = 'bot_envs'
config = configparser.ConfigParser() config = configparser.ConfigParser()
CONFIG_KEYS = ['username', 'password', 'discord_bot_token', 'plex_user', 'plex_pass', CONFIG_KEYS = ['username', 'password', 'discord_bot_token', 'plex_user', 'plex_pass',
'roles', 'plex_server_name', 'plex_libs', 'owner_id', 'channel_id', 'plex_roles', 'plex_server_name', 'plex_libs', 'owner_id', 'channel_id',
'auto_remove_user'] 'auto_remove_user']
# settings # settings
Discord_bot_token = "" Discord_bot_token = ""
roles = None plex_roles = None
PLEXUSER = "" PLEXUSER = ""
PLEXPASS = "" PLEXPASS = ""
PLEX_SERVER_NAME = "" PLEX_SERVER_NAME = ""
@@ -48,7 +48,7 @@ if(path.exists('app/config/config.ini')):
if(path.exists('app/config/config.ini')): if(path.exists('app/config/config.ini')):
try: try:
roles = config.get(BOT_SECTION, 'roles') roles = config.get(BOT_SECTION, 'plex_roles')
except: except:
pass pass
if(path.exists('app/config/config.ini')): if(path.exists('app/config/config.ini')):

32
run.py
View File

@@ -4,14 +4,14 @@ from discord.ext import commands, tasks
from discord.utils import get from discord.utils import get
import asyncio import asyncio
import sys import sys
from app.bot.helper.confighelper import switch, Discord_bot_token, roles from app.bot.helper.confighelper import switch, Discord_bot_token, plex_roles
import app.bot.helper.confighelper as confighelper import app.bot.helper.confighelper as confighelper
maxroles = 10 maxroles = 10
if roles is None: if plex_roles is None:
roles = [] plex_roles = []
else: else:
roles = list(roles.split(',')) plex_roles = list(plex_roles.split(','))
if switch == 0: if switch == 0:
print("Missing Config.") print("Missing Config.")
@@ -41,27 +41,27 @@ def reload():
bot.reload_extension(f'app.bot.cogs.app') bot.reload_extension(f'app.bot.cogs.app')
async def getplex(ctx, type): async def getplex(ctx, type):
username = None value = None
await ctx.author.send("Please reply with your Plex {}:".format(type)) await ctx.author.send("Please reply with your Plex {}:".format(type))
while(username == None): while(value == None):
def check(m): def check(m):
return m.author == ctx.author and not m.guild return m.author == ctx.author and not m.guild
try: try:
username = await bot.wait_for('message', timeout=200, check=check) value = await bot.wait_for('message', timeout=200, check=check)
return username.content return value.content
except asyncio.TimeoutError: except asyncio.TimeoutError:
message = "Timed Out. Try again." message = "Timed Out. Try again."
return None return None
@bot.command() @bot.command()
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
async def roleadd(ctx, role: discord.Role): async def plexroleadd(ctx, role: discord.Role):
if len(roles) <= maxroles: if len(plex_roles) <= maxroles:
roles.append(role.name) plex_roles.append(role.name)
saveroles = ",".join(roles) saveroles = ",".join(plex_roles)
confighelper.change_config("roles", saveroles) confighelper.change_config("plex_roles", saveroles)
await ctx.author.send("Updated roles. Bot is restarting. Please wait.") await ctx.author.send("Updated Plex roles. Bot is restarting. Please wait.")
print("Roles updated. Restarting bot.") print("Plex roles updated. Restarting bot.")
reload() reload()
await ctx.author.send("Bot has been restarted. Give it a few seconds.") await ctx.author.send("Bot has been restarted. Give it a few seconds.")
print("Bot has been restarted. Give it a few seconds.") print("Bot has been restarted. Give it a few seconds.")
@@ -95,7 +95,7 @@ async def setupplex(ctx):
@bot.command() @bot.command()
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
async def setuplibs(ctx): async def setupplexlibs(ctx):
libs = "" libs = ""
libs = await getplex(ctx, "libs") libs = await getplex(ctx, "libs")
if libs is None: if libs is None: