From 75aae28cbb9c7104f5aed05da627f28c18d79722 Mon Sep 17 00:00:00 2001 From: mightypanders Date: Sun, 16 Apr 2023 02:02:40 +0200 Subject: [PATCH] scaffold adduser function --- server/handler/addUserAccount.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/handler/addUserAccount.ts b/server/handler/addUserAccount.ts index 4facd3f..81b443e 100644 --- a/server/handler/addUserAccount.ts +++ b/server/handler/addUserAccount.ts @@ -1,13 +1,15 @@ import { User as DiscordUser } from "discord.js"; -import { AuthenticateUserByNameRequest, JellyfinAPI } from "../../jellyfin/api"; -import { UserApi } from "../../jellyfin/api/userApi"; -import { config } from "../configuration"; - -export async function add(discordUser: DiscordUser): Promise { - const jfUserAPI: UserApi = new UserApi(config.jellyfin_url) - - +import { JellyfinHandler } from "../../jellyfin/handler"; +import { logger } from "../logger"; +export async function addUser(discordUser: DiscordUser, jf: JellyfinHandler, guildId: string, requestId: string): Promise { + if (!jf.isUserAlreadyPresent(discordUser, guildId, requestId)) { + logger.info(`User ${discordUser.username} is already registered on ${jf.ServerName}`) + return + } + const jfUserAccount = await jf.createUserAccountForDiscordUser(discordUser, guildId, requestId) + if (jfUserAccount) { + await jf.addPermissionsToUserAccount(jfUserAccount,guildId,requestId) + } return - }