Compare commits

..

No commits in common. "2fae61fc1fb1bc77965816f2eb6f590a90e0cb63" and "8caf80f54ebc8dacfc91b9b35c74234779df81e4" have entirely different histories.

7 changed files with 27 additions and 33 deletions

View File

@ -5,8 +5,7 @@ import { JellyfinHandler } from "./server/jellyfin/handler"
import { attachedImages } from "./server/assets/attachments" import { attachedImages } from "./server/assets/attachments"
const requestId = 'startup' const requestId = 'startup'
export const jellyfinHandler = new JellyfinHandler({jellyfinToken: config.bot.workaround_token, jellyfinUrl: config.bot.jellyfin_url, movieCollectionId: config.bot.jf_collection_id, collectionUser: config.bot.jf_user}) export const jellyfinHandler = new JellyfinHandler(config)
export const yavinJellyfinHandler = new JellyfinHandler({jellyfinToken: config.bot.yavin_jellyfin_token, jellyfinUrl: config.bot.yavin_jellyfin_url, movieCollectionId: config.bot.yavin_collection_id, collectionUser: config.bot.yavin_jellyfin_collection_user})
export const client = new ExtendedClient(jellyfinHandler) export const client = new ExtendedClient(jellyfinHandler)

View File

@ -67,7 +67,7 @@ async function sendInitialAnnouncement(guildId: string, requestId: string): Prom
const body = `[initial] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett. const body = `[initial] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett.
Wir machen in Zukunft regelmäßig Watchparties in denen wir zusammen Filme gucken! Falls du mitmachen möchtest, reagiere einfach auf diesen Post mit 🎫, dann bekommst du automatisch eine Rolle zugewiesen und wirst benachrichtigt sobald es in der Zukunft weitere Watchparties und Filme zum abstimmen gibt. Wir machen in Zukunft regelmäßig Watchparties! Falls du mitmachen möchtest, reagiere einfach auf diesen Post mit 🎫, dann bekommst du automatisch eine Rolle zugewiesen und wirst benachrichtigt sobald es in der Zukunft weitere Watchparties und Filme zum abstimmen gibt.
Für eine Erklärung wie das alles funktioniert mach einfach /mitgucken für eine lange Erklärung am Stück oder /guides wenn du auswählen möchtest wozu du Infos bekommst.` Für eine Erklärung wie das alles funktioniert mach einfach /mitgucken für eine lange Erklärung am Stück oder /guides wenn du auswählen möchtest wozu du Infos bekommst.`

View File

@ -25,11 +25,6 @@ export interface Config {
announcement_role: string announcement_role: string
announcement_channel_id: string announcement_channel_id: string
jf_collection_id: string jf_collection_id: string
jf_user: string
yavin_collection_id: string
yavin_jellyfin_url: string
yavin_jellyfin_token: string
yavin_jellyfin_collection_user: string
} }
} }
export const config: Config = { export const config: Config = {
@ -64,11 +59,6 @@ export const config: Config = {
jf_admin_role: process.env.ADMIN_ROLE ?? "", jf_admin_role: process.env.ADMIN_ROLE ?? "",
announcement_role: process.env.WATCHPARTY_ANNOUNCEMENT_ROLE ?? "", announcement_role: process.env.WATCHPARTY_ANNOUNCEMENT_ROLE ?? "",
announcement_channel_id: process.env.CHANNEL_ID ?? "", announcement_channel_id: process.env.CHANNEL_ID ?? "",
jf_collection_id: process.env.JELLYFIN_COLLECTION_ID ?? "", jf_collection_id: process.env.JELLYFIN_COLLECTION_ID ?? ""
yavin_collection_id: process.env.YAVIN_COLLECTION_ID ?? "",
yavin_jellyfin_url: process.env.YAVIN_JELLYFIN_URL ?? "",
yavin_jellyfin_token: process.env.YAVIN_TOKEN ?? "",
yavin_jellyfin_collection_user: process.env.YAVIN_COLLECTION_USER ?? "",
jf_user: process.env.JELLYFIN_USER ?? ""
} }
} }

View File

@ -3,11 +3,11 @@ import toDate from "date-fns/fp/toDate";
import { GuildScheduledEvent, Message, MessageCreateOptions, TextChannel } from "discord.js"; import { GuildScheduledEvent, Message, MessageCreateOptions, TextChannel } from "discord.js";
import { ScheduledTask, schedule } from "node-cron"; import { ScheduledTask, schedule } from "node-cron";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import { client, yavinJellyfinHandler } from "../.."; import { client, jellyfinHandler } from "../..";
import { closePoll } from "../commands/closepoll"; import { closePoll } from "../commands/closepoll";
import { config } from "../configuration"; import { config } from "../configuration";
import { Maybe } from "../interfaces";
import { logger } from "../logger"; import { logger } from "../logger";
import { Maybe } from "../interfaces";
export const name = 'guildScheduledEventCreate' export const name = 'guildScheduledEventCreate'
@ -24,7 +24,7 @@ export async function execute(event: GuildScheduledEvent) {
logger.info("Event was a placeholder event to start a new watchparty and voting. Creating vote!", { guildId: event.guildId, requestId }) logger.info("Event was a placeholder event to start a new watchparty and voting. Creating vote!", { guildId: event.guildId, requestId })
logger.debug("Renaming event", { guildId: event.guildId, requestId }) logger.debug("Renaming event", { guildId: event.guildId, requestId })
event.edit({ name: "Watchparty - Voting offen" }) event.edit({ name: "Watchparty - Voting offen" })
const movies = await yavinJellyfinHandler.getRandomMovies(5, event.guildId, requestId) const movies = await jellyfinHandler.getRandomMovies(5, event.guildId, requestId)
logger.info(`Got ${movies.length} random movies. Creating voting`, { guildId: event.guildId, requestId }) logger.info(`Got ${movies.length} random movies. Creating voting`, { guildId: event.guildId, requestId })
logger.debug(`Movies: ${JSON.stringify(movies.map(movie => movie.name))}`, { guildId: event.guildId, requestId }) logger.debug(`Movies: ${JSON.stringify(movies.map(movie => movie.name))}`, { guildId: event.guildId, requestId })

View File

@ -32,10 +32,4 @@ export interface ChangedRoles {
addedRoles: Collection<string, Role> addedRoles: Collection<string, Role>
removedRoles: Collection<string, Role> removedRoles: Collection<string, Role>
} }
export interface JellyfinConfig {
jellyfinUrl: string,
jellyfinToken: string,
movieCollectionId: string,
collectionUser: string
}
export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY" export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY"

View File

@ -1,5 +1,6 @@
import { GuildMember } from "discord.js"; import { GuildMember } from "discord.js";
import { JellyfinConfig, Maybe, PermissionLevel } from "../interfaces"; import { Config } from "../configuration";
import { 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 } from "./models"; import { BaseItemDto, UpdateUserPasswordRequest } from "./models";
@ -14,27 +15,34 @@ export class JellyfinHandler {
private moviesApi: ItemsApi private moviesApi: ItemsApi
private token: string private token: string
private authHeader: { headers: { 'X-Emby-Authorization': string } } private authHeader: { headers: { 'X-Emby-Authorization': string } }
private config: JellyfinConfig private config: Config
private serverName = ""; private serverName = "";
constructor(_config: JellyfinConfig, _userApi?: UserApi, _systemApi?: SystemApi, _itemsApi?: ItemsApi) { public async ServerName(): Promise<string> {
if (this.serverName === "") {
const info = await this.systemApi.getSystemInfo(this.authHeader)
this.serverName = info.serverName ?? this.config.bot.jellyfin_url
}
return this.serverName
}
constructor(_config: Config, _userApi?: UserApi, _systemApi?: SystemApi, _itemsApi?: ItemsApi) {
this.config = _config this.config = _config
this.token = this.config.jellyfinToken this.token = this.config.bot.jellfin_token
this.authHeader = { this.authHeader = {
headers: { headers: {
"X-Emby-Authorization": this.config.jellyfinToken "X-Emby-Authorization": this.config.bot.workaround_token
} }
} }
const userApiConfigurationParams: ConfigurationParameters = { const userApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.jellyfinUrl, basePath: this.config.bot.jellyfin_url,
headers: this.authHeader.headers headers: this.authHeader.headers
} }
const systemApiConfigurationParams: ConfigurationParameters = { const systemApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.jellyfinUrl, basePath: this.config.bot.jellyfin_url,
headers: this.authHeader.headers headers: this.authHeader.headers
} }
const libraryApiConfigurationParams: ConfigurationParameters = { const libraryApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.jellyfinUrl, basePath: this.config.bot.jellyfin_url,
headers: this.authHeader.headers headers: this.authHeader.headers
} }
@ -220,9 +228,11 @@ export class JellyfinHandler {
public async getAllMovies(guildId: string, requestId: string): Promise<BaseItemDto[]> { public async getAllMovies(guildId: string, requestId: string): Promise<BaseItemDto[]> {
logger.info("requesting all movies from jellyfin", { guildId, requestId }) logger.info("requesting all movies from jellyfin", { guildId, requestId })
const liloJfUser = await this.getUser(<GuildMember>{ guild: { id: guildId }, displayName: "lilo" }, requestId)
const searchParams: GetItemsRequest = { const searchParams: GetItemsRequest = {
userId: this.config.collectionUser, userId: liloJfUser?.id,
parentId: this.config.movieCollectionId // collection ID for all movies parentId: this.config.bot.jf_collection_id // collection ID for all movies
} }
const movies = (await (this.moviesApi.getItems(searchParams))).items?.filter(item => !item.isFolder) const movies = (await (this.moviesApi.getItems(searchParams))).items?.filter(item => !item.isFolder)
// logger.debug(JSON.stringify(movies, null, 2), { guildId: guildId, requestId }) // logger.debug(JSON.stringify(movies, null, 2), { guildId: guildId, requestId })

View File

@ -33,6 +33,7 @@ export class ExtendedClient extends Client {
Promise.all(promises).then(() => { Promise.all(promises).then(() => {
this.login(config.bot.token) this.login(config.bot.token)
}) })
logger.info(`Connected with ${await this.jellyfin.ServerName()}`)
} }
private async importFile(filepath: string): Promise<any> { private async importFile(filepath: string): Promise<any> {
logger.debug(`Importing ${filepath}`) logger.debug(`Importing ${filepath}`)