Compare commits

..

No commits in common. "e234e9f68f01db839b07bdb0578d620a1e1d0e28" and "64c58742492e42743795df1898b1adba7edb9f07" have entirely different histories.

2 changed files with 15 additions and 15 deletions

View File

@ -8,7 +8,7 @@ export async function execute(interaction: ExtendedInteraction) {
//console.dir(interaction, { depth: null }) //console.dir(interaction, { depth: null })
if (interaction.isCommand()) { if (interaction.isCommand()) {
logger.info(`Interaction is a command.`, { guildId: interaction.guild?.id }) logger.info(`Interaction is a command.`, { guildId: interaction.guild?.id })
await interaction.deferReply({ ephemeral: true }) await interaction.deferReply()
const command = client.commands.get(interaction.commandName) const command = client.commands.get(interaction.commandName)
if (!command) if (!command)
return interaction.followUp('Invalid command') return interaction.followUp('Invalid command')

View File

@ -67,7 +67,7 @@ export class JellyfinHandler {
password: this.generatePasswordForUser(), password: this.generatePasswordForUser(),
} }
} }
logger.debug(JSON.stringify(req), { requestId, guildId }) logger.debug(JSON.stringify(req))
const createResult = await this.userApi.createUserByName(req) const createResult = await this.userApi.createUserByName(req)
if (createResult) { if (createResult) {
(await discordUser.createDM()).send(`Ich hab dir mal nen Account angelegt :)\nDein Username ist ${createResult.name}, dein Password ist "${req.createUserByNameRequest.password}"!`) (await discordUser.createDM()).send(`Ich hab dir mal nen Account angelegt :)\nDein Username ist ${createResult.name}, dein Password ist "${req.createUserByNameRequest.password}"!`)
@ -78,7 +78,7 @@ export class JellyfinHandler {
public async isUserAlreadyPresent(discordUser: GuildMember, requestId?: string): Promise<boolean> { public async isUserAlreadyPresent(discordUser: GuildMember, requestId?: string): Promise<boolean> {
const jfuser = await this.getUser(discordUser, requestId) const jfuser = await this.getUser(discordUser, requestId)
logger.debug(`Presence for DiscordUser ${discordUser.id}:${jfuser !== undefined}`, { guildId: discordUser.guild.id, requestId }) logger.debug(`Presence for DiscordUser ${discordUser.id}:${jfuser !== undefined}`)
return jfuser !== undefined return jfuser !== undefined
} }
@ -94,14 +94,14 @@ export class JellyfinHandler {
} }
public async getUser(discordUser: GuildMember, requestId?: string): Promise<Maybe<UserDto>> { public async getUser(discordUser: GuildMember, requestId?: string): Promise<Maybe<UserDto>> {
logger.info(`Getting user for discord member ${discordUser.displayName}`, { requestId, guildId: discordUser.guild.id }) logger.info(`Getting user for discord member ${discordUser.displayName}`, { requestId })
const jfUsers = await this.getCurrentUsers(discordUser.guild.id, requestId) const jfUsers = await this.getCurrentUsers(discordUser.guild.id, requestId)
const foundUser = jfUsers.find(x => x.name?.includes(discordUser.displayName)) const foundUser = jfUsers.find(x => x.name?.includes(discordUser.displayName))
return foundUser return foundUser
} }
public async removeUser(newMember: GuildMember, level: PermissionLevel, requestId?: string) { public async removeUser(newMember: GuildMember, level: PermissionLevel, requestId?: string) {
logger.info(`${level == "TEMPORARY" ? "Deleting" : "Disabling"} user ${newMember.displayName}, but method is not implemented`, { requestId, guildId: newMember.guild.id }) logger.info(`${level == "TEMPORARY" ? "Deleting" : "Disabling" } user ${newMember.displayName}, but method is not implemented`, { requestId })
const jfuser = await this.getUser(newMember, requestId) const jfuser = await this.getUser(newMember, requestId)
if (jfuser && jfuser.id) { if (jfuser && jfuser.id) {
if (level === "TEMPORARY") { if (level === "TEMPORARY") {
@ -116,7 +116,7 @@ export class JellyfinHandler {
} }
public async purge(guildId: string, requestId?: string) { public async purge(guildId: string, requestId?: string) {
logger.info("Deleting tmp users", { requestId, guildId }) logger.info("Deleting tmp users")
const users = (await this.userApi.getUsers()).filter(user => user.name?.endsWith("_tmp")) const users = (await this.userApi.getUsers()).filter(user => user.name?.endsWith("_tmp"))
users.forEach(user => { users.forEach(user => {
@ -130,7 +130,7 @@ export class JellyfinHandler {
} }
public async resetUserPasswort(member: GuildMember, requestId?: string) { public async resetUserPasswort(member: GuildMember, requestId?: string) {
logger.info(`Resetting password for user ${member.displayName}`, { requestId, guildId: member.guild.id }) logger.info(`Resetting password for user ${member.displayName}`, { requestId })
const jfUser = await this.getUser(member, requestId) const jfUser = await this.getUser(member, requestId)
if (jfUser && jfUser.id) { if (jfUser && jfUser.id) {
@ -160,7 +160,7 @@ export class JellyfinHandler {
userId: jfUser.id userId: jfUser.id
} }
logger.info("Setting new password", { requestId, guildId: member.guild.id }) logger.info("Setting new password", { requestId })
await this.userApi.updateUserPassword(passwordOperationRequest); await this.userApi.updateUserPassword(passwordOperationRequest);
@ -175,7 +175,7 @@ export class JellyfinHandler {
public async disableUser(user: UserDto, guildId?: string, requestId?: string): Promise<void> { public async disableUser(user: UserDto, guildId?: string, requestId?: string): Promise<void> {
if (user.id) { if (user.id) {
const jfUser = await this.getUser(<GuildMember>{ displayName: user.name, guild: { id: guildId } }, requestId) const jfUser = await this.getUser(<GuildMember>{ displayName: user.name, guild: { id: guildId } }, requestId)
logger.info(`Trying to disable user: ${user.name}|${user.id}|${JSON.stringify(jfUser, null, 2)}`, { guildId, requestId }) logger.info(`Trying to disable user: ${user.name}|${user.id}|${JSON.stringify(jfUser, null, 2)}`)
const r: UpdateUserPolicyOperationRequest = { const r: UpdateUserPolicyOperationRequest = {
userId: user.id ?? "", userId: user.id ?? "",
updateUserPolicyRequest: { updateUserPolicyRequest: {
@ -184,7 +184,7 @@ export class JellyfinHandler {
} }
} }
await this.userApi.updateUserPolicy(r) await this.userApi.updateUserPolicy(r)
logger.info(`Succeeded with disabling user: ${user.name}`, { guildId, requestId }) logger.info(`Succeeded with disabling user: ${user.name}`)
} }
else { else {
logger.error(`Can not disable user ${JSON.stringify(user)}, has no id?!`, { requestId, guildId }) logger.error(`Can not disable user ${JSON.stringify(user)}, has no id?!`, { requestId, guildId })
@ -194,7 +194,7 @@ export class JellyfinHandler {
public async enableUser(user: UserDto, guildId: string, requestId?: string): Promise<void> { public async enableUser(user: UserDto, guildId: string, requestId?: string): Promise<void> {
if (user.id) { if (user.id) {
const jfUser = await this.getUser(<GuildMember>{ displayName: user.name, guild: { id: guildId } }, requestId) const jfUser = await this.getUser(<GuildMember>{ displayName: user.name, guild: { id: guildId } }, requestId)
logger.info(`Trying to enable user: ${user.name}|${user.id}|${JSON.stringify(jfUser, null, 2)}`, { guildId, requestId }) logger.info(`Trying to enable user: ${user.name}|${user.id}|${JSON.stringify(jfUser, null, 2)}`)
const r: UpdateUserPolicyOperationRequest = { const r: UpdateUserPolicyOperationRequest = {
userId: user.id ?? "", userId: user.id ?? "",
updateUserPolicyRequest: { updateUserPolicyRequest: {
@ -203,7 +203,7 @@ export class JellyfinHandler {
} }
} }
await this.userApi.updateUserPolicy(r) await this.userApi.updateUserPolicy(r)
logger.info(`Succeeded with enabling user: ${user.name}`, { guildId, requestId }) logger.info(`Succeeded with enabling user: ${user.name}`)
} }
else { else {
logger.error(`Can not enable user ${JSON.stringify(user)}, has no id?!`, { requestId, guildId }) logger.error(`Can not enable user ${JSON.stringify(user)}, has no id?!`, { requestId, guildId })
@ -211,10 +211,10 @@ export class JellyfinHandler {
} }
public async upsertUser(newMember: GuildMember, level: PermissionLevel, requestId?: string) { public async upsertUser(newMember: GuildMember, level: PermissionLevel, requestId?: string) {
logger.error(`Trying to upsert user ${newMember.displayName}, with permissionLevel ${level}`, { guildId: newMember.guild.id, requestId }) logger.error(`Trying to upsert user ${newMember.displayName}, with permissionLevel ${level}`)
const jfuser = await this.getUser(newMember, requestId) const jfuser = await this.getUser(newMember, requestId)
if (jfuser) { if (jfuser) {
logger.info(`User with name ${newMember.displayName} is already present`, { guildId: newMember.guild.id, requestId }) logger.info(`User with name ${newMember.displayName} is already present`)
await this.enableUser(jfuser, newMember.guild.id, requestId) await this.enableUser(jfuser, newMember.guild.id, requestId)
} else { } else {
this.createUserAccountForDiscordUser(newMember, level, newMember.guild.id, requestId) this.createUserAccountForDiscordUser(newMember, level, newMember.guild.id, requestId)