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

View File

@@ -7,12 +7,12 @@ BOT_SECTION = 'bot_envs'
config = configparser.ConfigParser()
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']
# settings
Discord_bot_token = ""
roles = None
plex_roles = None
PLEXUSER = ""
PLEXPASS = ""
PLEX_SERVER_NAME = ""
@@ -48,7 +48,7 @@ if(path.exists('app/config/config.ini')):
if(path.exists('app/config/config.ini')):
try:
roles = config.get(BOT_SECTION, 'roles')
roles = config.get(BOT_SECTION, 'plex_roles')
except:
pass
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
import asyncio
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
maxroles = 10
if roles is None:
roles = []
if plex_roles is None:
plex_roles = []
else:
roles = list(roles.split(','))
plex_roles = list(plex_roles.split(','))
if switch == 0:
print("Missing Config.")
@@ -41,27 +41,27 @@ def reload():
bot.reload_extension(f'app.bot.cogs.app')
async def getplex(ctx, type):
username = None
value = None
await ctx.author.send("Please reply with your Plex {}:".format(type))
while(username == None):
while(value == None):
def check(m):
return m.author == ctx.author and not m.guild
try:
username = await bot.wait_for('message', timeout=200, check=check)
return username.content
value = await bot.wait_for('message', timeout=200, check=check)
return value.content
except asyncio.TimeoutError:
message = "Timed Out. Try again."
return None
@bot.command()
@commands.has_permissions(administrator=True)
async def roleadd(ctx, role: discord.Role):
if len(roles) <= maxroles:
roles.append(role.name)
saveroles = ",".join(roles)
confighelper.change_config("roles", saveroles)
await ctx.author.send("Updated roles. Bot is restarting. Please wait.")
print("Roles updated. Restarting bot.")
async def plexroleadd(ctx, role: discord.Role):
if len(plex_roles) <= maxroles:
plex_roles.append(role.name)
saveroles = ",".join(plex_roles)
confighelper.change_config("plex_roles", saveroles)
await ctx.author.send("Updated Plex roles. Bot is restarting. Please wait.")
print("Plex roles updated. Restarting bot.")
reload()
await ctx.author.send("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()
@commands.has_permissions(administrator=True)
async def setuplibs(ctx):
async def setupplexlibs(ctx):
libs = ""
libs = await getplex(ctx, "libs")
if libs is None: