diff --git a/README.md b/README.md index 7cea06f..f05a161 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ Fill out values in the .env and you're good to go! - `!searchaccount` - Find linked Discord user - `!searchdiscord` @user - Find linked Jellyfin account - `!scanlibraries` - Scan all Jellyfin libraries -- `!assignaccount` @user - Manually link accounts +- `!link` @user - Manually link accounts +- `!unlink` @user - Manually unlink accounts ***Admin Bot Commands*** - `!setprefix` - Change the bots command prefix \ No newline at end of file diff --git a/app.py b/app.py index 9d1e2cb..6b21d2c 100644 --- a/app.py +++ b/app.py @@ -381,7 +381,7 @@ async def scanlibraries(ctx): await ctx.send(f"❌ Failed to start library scan. Status code: {response.status_code}") @bot.command() -async def assignaccount(ctx, jellyfin_username: str, user: discord.User): +async def link(ctx, jellyfin_username: str, user: discord.User): member = ctx.guild.get_member(ctx.author.id) if not has_admin_role(member): await ctx.send("❌ You don’t have permission to use this command.") @@ -390,6 +390,26 @@ async def assignaccount(ctx, jellyfin_username: str, user: discord.User): add_account(user.id, jellyfin_username) await ctx.send(f"✅ Linked Jellyfin account **{jellyfin_username}** to {user.mention}.") +@bot.command() +async def unlink(ctx, discord_user: discord.User): + """Admin-only: unlink a Jellyfin account from a Discord user (without deleting the account)""" + guild = ctx.guild + member = guild.get_member(ctx.author.id) if guild else None + + if not member or not has_admin_role(member): + await ctx.send(f"❌ {ctx.author.mention}, you don’t have permission to use this command.") + return + + # Check if the Discord user has a linked Jellyfin account + account = get_account_by_discord(discord_user.id) + if not account: + await ctx.send(f"❌ Discord user {discord_user.mention} does not have a linked Jellyfin account.") + return + + # Remove the database entry + delete_account(discord_user.id) + await ctx.send(f"✅ Unlinked Jellyfin account **{account[0]}** from Discord user {discord_user.mention}.") + @bot.command() async def setprefix(ctx, new_prefix: str): """Admin-only: change the bot command prefix""" @@ -440,7 +460,8 @@ async def help_command(ctx): f"`{PREFIX}searchaccount ` - Find linked Discord user\n" f"`{PREFIX}searchdiscord @user` - Find linked Jellyfin account\n" f"`{PREFIX}scanlibraries` - Scan all Jellyfin libraries\n" - f"`{PREFIX}assignaccount @user` - Manually link accounts\n" + f"`{PREFIX}link @user` - Manually link accounts\n" + f"`{PREFIX}unlink @user` - Manually unlink accounts\n" ), inline=False) embed.add_field(name="Admin Bot Commands", value=( f"`{PREFIX}setprefix` - Change the bots command prefix\n"