- 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)
111 lines
3.8 KiB
Python
111 lines
3.8 KiB
Python
import discord
|
|
import os
|
|
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, plex_roles
|
|
import app.bot.helper.confighelper as confighelper
|
|
maxroles = 10
|
|
|
|
if plex_roles is None:
|
|
plex_roles = []
|
|
else:
|
|
plex_roles = list(plex_roles.split(','))
|
|
|
|
if switch == 0:
|
|
print("Missing Config.")
|
|
sys.exit()
|
|
|
|
print("V 1.0")
|
|
|
|
intents = discord.Intents.default()
|
|
intents.members = True
|
|
bot = commands.Bot(command_prefix=".", intents = intents)
|
|
bot.remove_command('help')
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
print("bot is online.")
|
|
|
|
|
|
@bot.event
|
|
async def on_message(message):
|
|
if message.author.id == bot.user.id:
|
|
return
|
|
if not message.guild:
|
|
return
|
|
await bot.process_commands(message)
|
|
|
|
def reload():
|
|
bot.reload_extension(f'app.bot.cogs.app')
|
|
|
|
async def getplex(ctx, type):
|
|
value = None
|
|
await ctx.author.send("Please reply with your Plex {}:".format(type))
|
|
while(value == None):
|
|
def check(m):
|
|
return m.author == ctx.author and not m.guild
|
|
try:
|
|
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 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.")
|
|
|
|
@bot.command()
|
|
@commands.has_permissions(administrator=True)
|
|
async def setupplex(ctx):
|
|
username = ""
|
|
pasword = ""
|
|
servername = ""
|
|
username = await getplex(ctx, "username")
|
|
if username is None:
|
|
return
|
|
else:
|
|
password = await getplex(ctx, "password")
|
|
if password is None:
|
|
return
|
|
else:
|
|
servername = await getplex(ctx, "servername")
|
|
if servername is None:
|
|
return
|
|
else:
|
|
confighelper.change_config("plex_user", str(username))
|
|
confighelper.change_config("plex_pass", str(password))
|
|
confighelper.change_config("plex_server_name", str(servername))
|
|
print("Plex username, password, and plex server name updated. Restarting bot.")
|
|
await ctx.author.send("Plex username, password, and plex server name updated. Restarting bot. Please wait.")
|
|
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 setupplexlibs(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. Please wait.")
|
|
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) |