Compare commits

..

No commits in common. "d3fff38e369ff35a4d96b5b03b7cecbd5515f84f" and "7e37641e0b98200ed2e37d7e56ab78d7684b690f" have entirely different histories.

3 changed files with 18 additions and 59 deletions

View File

@ -1,17 +0,0 @@
import { ApplicationCommandOptionType, BurstHandlerMajorIdKey } from 'discord.js'
import { Command } from '../structures/command'
import { RunOptions } from '../types/commandTypes'
import { jellyfinHandler } from "../.."
import { v4 as uuid } from 'uuid'
export default new Command({
name: 'passwort_reset',
description: 'Ich vergebe dir ein neues Passwort und schicke es dir per DM zu. Kostet auch nix! Versprochen! 😉',
options: [],
run: async (interaction: RunOptions) => {
console.log('PasswortReset called')
interaction.interaction.followUp('Yo, ich schick dir eins!')
console.log(JSON.stringify(interaction.interaction.member, null, 2))
jellyfinHandler.resetUserPasswort(interaction.interaction.member, uuid())
}
})

View File

@ -19,7 +19,6 @@ export interface Config {
jellfin_token: string jellfin_token: string
jellyfin_url: string jellyfin_url: string
port: number port: number
workaround_token: string
} }
} }
export const config: Config = { export const config: Config = {
@ -48,7 +47,6 @@ export const config: Config = {
guild_id: process.env.GUILD_ID ?? "", guild_id: process.env.GUILD_ID ?? "",
client_id: process.env.CLIENT_ID ?? "", client_id: process.env.CLIENT_ID ?? "",
jellfin_token: process.env.JELLYFIN_TOKEN ?? "", jellfin_token: process.env.JELLYFIN_TOKEN ?? "",
jellyfin_url: process.env.JELLYFIN_URL ?? "", jellyfin_url: process.env.JELLYFIN_URL ?? ""
workaround_token: process.env.TOKEN ?? ""
} }
} }

View File

@ -14,7 +14,7 @@ export class JellyfinHandler {
private userApi: UserApi private userApi: UserApi
private systemApi: SystemApi private systemApi: SystemApi
private token: string private token: string
private authHeader: { headers: { 'X-Emby-Authorization': string } } private authHeader: { headers: { 'X-MediaBrowser-Token': string } }
private config: Config private config: Config
private serverName = ""; private serverName = "";
@ -30,7 +30,7 @@ export class JellyfinHandler {
this.token = this.config.bot.jellfin_token this.token = this.config.bot.jellfin_token
this.authHeader = { this.authHeader = {
headers: { headers: {
"X-Emby-Authorization": this.config.bot.workaround_token "X-MediaBrowser-Token": this.token
} }
} }
const userApiConfigurationParams: ConfigurationParameters = { const userApiConfigurationParams: ConfigurationParameters = {
@ -69,19 +69,19 @@ export class JellyfinHandler {
} }
logger.debug(JSON.stringify(req)) 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}"!` )
return createResult return createResult
} }
else throw new Error('Could not create User in Jellyfin') else throw new Error('Could not create User in Jellyfin')
} }
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}`) logger.debug(`Presence for DiscordUser ${discordUser.id}:${jfuser !== undefined}`)
return jfuser !== undefined return jfuser !== undefined
} }
public async getCurrentUsers(guildId: string, requestId?: string): Promise<UserDto[]> { public async getCurrentUsers(guildId: string, requestId?: string): Promise<UserDto[]> {
try { try {
logger.info(`Fetching current users from Jellyfin`, { requestId, guildId }) logger.info(`Fetching current users from Jellyfin`, { requestId, guildId })
@ -92,17 +92,16 @@ export class JellyfinHandler {
} }
return [] return []
} }
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})
const jfUsernameFromDiscordUsername = this.generateJFUserName(discordUser) const jfUsernameFromDiscordUsername = this.generateJFUserName(discordUser)
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 === jfUsernameFromDiscordUsername) const foundUser = jfUsers.find(x => x.name === jfUsernameFromDiscordUsername)
return foundUser return foundUser
} }
public async removeUser(newMember: GuildMember, requestId?: string) { public async removeUser(newMember: GuildMember, requestId?: string) {
logger.error(`Trying to remove user ${newMember.displayName}, but method is not implemented`, {requestId}) logger.error(`Trying to remove user ${newMember.displayName}, but method is not implemented`)
const jfuser = await this.getUser(newMember, requestId) const jfuser = await this.getUser(newMember, requestId)
if (jfuser) { if (jfuser) {
await this.disableUser(jfuser, newMember.guild.id, requestId) await this.disableUser(jfuser, newMember.guild.id, requestId)
@ -110,41 +109,20 @@ 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})
const jfUser = await this.getUser(member, requestId) const jfUser = await this.getUser(member, requestId)
if (jfUser && jfUser.id) { if (jfUser && jfUser.id) {
// const reset: UpdateUserPasswordRequest = { const r: UpdateUserPasswordRequest = {
// resetPassword: true newPw: this.generatePasswordForUser()
// }
// const shit: UpdateUserPasswordOperationRequest = {
// updateUserPasswordRequest: reset,
// userId: jfUser.id
// }
// logger.info(JSON.stringify(jfUser.policy, null, 2))
// logger.info("Resetting password", {requestId})
// await this.userApi.updateUserPassword(shit);
const password = this.generatePasswordForUser()
const passwordRequest: UpdateUserPasswordRequest = {
// resetPassword: true,
currentPw: "",
newPw: password
} }
const passwordOperationRequest: UpdateUserPasswordOperationRequest = { const shit: UpdateUserPasswordOperationRequest = {
updateUserPasswordRequest: passwordRequest, updateUserPasswordRequest: r,
userId: jfUser.id userId: jfUser.id
} }
logger.info("Setting new password", {requestId}) this.userApi.updateUserPassword(shit)
await this.userApi.updateUserPassword(passwordOperationRequest);
(await member.createDM()).send(`Hier ist dein neues Passwort: ${password}`)
} else { } else {
(await member.createDM()).send("Ich konnte leider keinen User von dir auf Jellyfin finden. Bitte melde dich bei Markus oder Samantha!") (await member.createDM()).send("Ich konnte leider keinen User von dir auf Jellyfin finden. Bitte melde dich bei Markus oder Samantha!")
} }
@ -154,7 +132,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)}`) 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 ?? "",
@ -170,10 +148,10 @@ export class JellyfinHandler {
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 })
} }
} }
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)}`) 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 ?? "",