WIP: use guildmember in jf handler, start user creation
This commit is contained in:
parent
4ff8c83cdf
commit
b01700df6c
@ -1,4 +1,4 @@
|
||||
import { User } from "discord.js";
|
||||
import { GuildMember, User } from "discord.js";
|
||||
import { UserDto } from "./model/userDto";
|
||||
import { Config } from "../server/configuration";
|
||||
import { UserApi } from "./api/userApi";
|
||||
@ -12,7 +12,7 @@ export class JellyfinHandler {
|
||||
private token: string
|
||||
private authHeader: { headers: { 'X-MediaBrowser-Token': string } }
|
||||
private config: Config
|
||||
private serverName: string = "";
|
||||
private serverName = "";
|
||||
|
||||
public async ServerName(): Promise<string> {
|
||||
if (this.serverName === "") {
|
||||
@ -33,26 +33,28 @@ export class JellyfinHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private generateJFUserName(discordUser: User): string {
|
||||
return discordUser.username + discordUser.discriminator
|
||||
private generateJFUserName(discordUser: GuildMember): string {
|
||||
return discordUser.displayName
|
||||
}
|
||||
|
||||
public async addPermissionsToUserAccount(jfUserAccount: UserDto, guildId: string, requestId: string): Promise<UserDto> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
public async createUserAccountForDiscordUser(discordUser: User, guildId: string, requestId: string): Promise<UserDto> {
|
||||
public async createUserAccountForDiscordUser(discordUser: GuildMember, guildId: string, requestId: string): Promise<UserDto> {
|
||||
const newUserName = this.generateJFUserName(discordUser)
|
||||
logger.info(`New Username for ${discordUser.username}: ${newUserName}`, { guildId, requestId })
|
||||
logger.info(`New Username for ${discordUser.displayName}: ${newUserName}`, { guildId, requestId })
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
public async isUserAlreadyPresent(discordUser: User, guildId: string, requestId: string): Promise<boolean> {
|
||||
public async isUserAlreadyPresent(discordUser: GuildMember, guildId: string, requestId?: string): Promise<boolean> {
|
||||
const jfUsernameFromDiscordUsername = this.generateJFUserName(discordUser)
|
||||
const jfUsers = await this.getCurrentUsers(guildId, requestId)
|
||||
const currentJfUserNames = jfUsers.map(x => x.name)
|
||||
logger.debug(`Current JF Usernames: ${JSON.stringify(currentJfUserNames)}`)
|
||||
const presence = currentJfUserNames.find(x => x === jfUsernameFromDiscordUsername)
|
||||
logger.debug(`Presence for DiscordUser ${discordUser.id}:${presence}`)
|
||||
return presence !== undefined
|
||||
}
|
||||
public async getCurrentUsers(guildId: string, requestId: string): Promise<UserDto[]> {
|
||||
public async getCurrentUsers(guildId: string, requestId?: string): Promise<UserDto[]> {
|
||||
try {
|
||||
const result = await this.userApi.getUsers(undefined, undefined, this.authHeader)
|
||||
return result.body
|
||||
@ -61,4 +63,16 @@ export class JellyfinHandler {
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
public async removeUser(newMember: GuildMember) {
|
||||
logger.error(`Trying to remove user ${newMember.displayName}, but method is not implemented`)
|
||||
}
|
||||
public async upsertUser(newMember: GuildMember, level: string, requestId?: string) {
|
||||
logger.error(`Trying to upsert user ${newMember.displayName}, with permissionLevel ${level} but method is not implemented`)
|
||||
const presence = await this.isUserAlreadyPresent(newMember, newMember.guild.id, requestId)
|
||||
if (presence) {
|
||||
logger.info(`User with name ${newMember.displayName} is already present`)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user