Compare commits
No commits in common. "1966640239bd15b8ab6fd0042ce16059221c0348" and "c1a449bafe4382be0470e291f416a314de9ff7de" have entirely different histories.
1966640239
...
c1a449bafe
@ -2,7 +2,7 @@ import { GuildMember } from "discord.js";
|
|||||||
import { JellyfinConfig, Maybe, PermissionLevel } from "../interfaces";
|
import { JellyfinConfig, Maybe, PermissionLevel } from "../interfaces";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import { CreateUserByNameOperationRequest, DeleteUserRequest, GetItemsRequest, ItemsApi, SystemApi, UpdateUserPasswordOperationRequest, UpdateUserPolicyOperationRequest, UserApi } from "./apis";
|
import { CreateUserByNameOperationRequest, DeleteUserRequest, GetItemsRequest, ItemsApi, SystemApi, UpdateUserPasswordOperationRequest, UpdateUserPolicyOperationRequest, UserApi } from "./apis";
|
||||||
import { BaseItemDto, UpdateUserPasswordRequest, UpdateUserPolicyRequest } from "./models";
|
import { BaseItemDto, UpdateUserPasswordRequest } from "./models";
|
||||||
import { UserDto } from "./models/UserDto";
|
import { UserDto } from "./models/UserDto";
|
||||||
import { Configuration, ConfigurationParameters } from "./runtime";
|
import { Configuration, ConfigurationParameters } from "./runtime";
|
||||||
|
|
||||||
@ -52,46 +52,24 @@ export class JellyfinHandler {
|
|||||||
return (Math.random() * 10000 + 10000).toFixed(0)
|
return (Math.random() * 10000 + 10000).toFixed(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createUserAccountForDiscordUser(discordUser: GuildMember, level: PermissionLevel, requestId: string, guildId?: string): Promise<UserDto> {
|
public async createUserAccountForDiscordUser(discordUser: GuildMember, level: PermissionLevel, guildId?: string, requestId?: string): Promise<UserDto> {
|
||||||
const newUserName = this.generateJFUserName(discordUser, level)
|
const newUserName = this.generateJFUserName(discordUser, level)
|
||||||
logger.info(`New Username for ${discordUser.displayName}: ${newUserName}`, { guildId, requestId })
|
logger.info(`New Username for ${discordUser.displayName}: ${newUserName}`, { guildId, requestId })
|
||||||
const req: CreateUserByNameOperationRequest = {
|
const req: CreateUserByNameOperationRequest = {
|
||||||
createUserByNameRequest: {
|
createUserByNameRequest: {
|
||||||
name: newUserName,
|
name: newUserName,
|
||||||
password: this.generatePasswordForUser()
|
password: this.generatePasswordForUser(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug(JSON.stringify(req), { requestId, guildId })
|
logger.debug(JSON.stringify(req), { requestId, guildId })
|
||||||
const createResult = await this.userApi.createUserByName(req)
|
const createResult = await this.userApi.createUserByName(req)
|
||||||
if (createResult) {
|
if (createResult) {
|
||||||
if(createResult.policy) {
|
|
||||||
this.setUserPermissions(createResult, requestId, guildId)
|
|
||||||
}
|
|
||||||
(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 setUserPermissions(user: UserDto, requestId: string, guildId?: string) {
|
|
||||||
if(!user.policy || !user.id) {
|
|
||||||
logger.error(`Cannot update user policy. User ${user.name} has no policy to modify`, {guildId, requestId})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
user.policy.enableVideoPlaybackTranscoding = false
|
|
||||||
|
|
||||||
const operation: UpdateUserPolicyRequest = {
|
|
||||||
...user.policy,
|
|
||||||
enableVideoPlaybackTranscoding: false
|
|
||||||
}
|
|
||||||
|
|
||||||
const request: UpdateUserPolicyOperationRequest = {
|
|
||||||
userId: user.id,
|
|
||||||
updateUserPolicyRequest: operation
|
|
||||||
}
|
|
||||||
this.userApi.updateUserPolicy(request)
|
|
||||||
}
|
|
||||||
|
|
||||||
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}`, { guildId: discordUser.guild.id, requestId })
|
||||||
|
Loading…
Reference in New Issue
Block a user