move preparation of vote Message sending into vote controller
event only needs to supply information, text creation, sending and pinning happens in the vote controller
This commit is contained in:
parent
4a3e8809be
commit
4600820889
|
@ -4,7 +4,6 @@ import { client, yavinJellyfinHandler } from "../..";
|
||||||
import { Maybe } from "../interfaces";
|
import { Maybe } from "../interfaces";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
|
|
||||||
|
|
||||||
export const name = 'guildScheduledEventCreate'
|
export const name = 'guildScheduledEventCreate'
|
||||||
|
|
||||||
export async function execute(event: GuildScheduledEvent) {
|
export async function execute(event: GuildScheduledEvent) {
|
||||||
|
@ -25,15 +24,21 @@ export async function execute(event: GuildScheduledEvent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
||||||
|
|
||||||
if (!event.scheduledStartAt) {
|
if (!event.scheduledStartAt) {
|
||||||
logger.info("EVENT DOES NOT HAVE STARTDATE; CANCELLING", { guildId: event.guildId, requestId })
|
logger.info("Event does not have a start date, cancelling", { guildId: event.guildId, requestId })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const sentMessageText = client.voteController.createVoteMessageText(event.id, event.scheduledStartAt, movies, event.guild?.id ?? "", requestId)
|
const sentMessage = await client.voteController.prepareAndSendVoteMessage({
|
||||||
const sentMessage = await client.voteController.sendVoteMessage(sentMessageText, movies.length, announcementChannel)
|
movies,
|
||||||
|
startDate: event.scheduledStartAt,
|
||||||
|
event,
|
||||||
|
announcementChannel,
|
||||||
|
pinAfterSending: true
|
||||||
|
},
|
||||||
|
event.guildId,
|
||||||
|
requestId)
|
||||||
|
|
||||||
sentMessage.pin()
|
logger.debug(JSON.stringify(sentMessage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { getMembersWithRoleFromGuild } from "./roleFilter"
|
||||||
import { config } from "../configuration"
|
import { config } from "../configuration"
|
||||||
import { VoteMessage, isVoteEndedMessage, isVoteMessage } from "./messageIdentifiers"
|
import { VoteMessage, isVoteEndedMessage, isVoteMessage } from "./messageIdentifiers"
|
||||||
import { createDateStringFromEvent } from "./dateHelper"
|
import { createDateStringFromEvent } from "./dateHelper"
|
||||||
import { Maybe } from "../interfaces"
|
import { Maybe, voteMessageInputInformation as prepareVoteMessageInput } from "../interfaces"
|
||||||
import format from "date-fns/format"
|
import format from "date-fns/format"
|
||||||
import toDate from "date-fns/toDate"
|
import toDate from "date-fns/toDate"
|
||||||
import differenceInDays from "date-fns/differenceInDays"
|
import differenceInDays from "date-fns/differenceInDays"
|
||||||
|
@ -161,6 +161,14 @@ export default class VoteController {
|
||||||
throw Error(`Could not find eventId in Vote Message`)
|
throw Error(`Could not find eventId in Vote Message`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async prepareAndSendVoteMessage(inputInfo: prepareVoteMessageInput, guildId: string, requestId: string) {
|
||||||
|
const messageText = this.createVoteMessageText(inputInfo.event.id, inputInfo.startDate, inputInfo.movies, guildId, requestId)
|
||||||
|
const sentMessage = await this.sendVoteMessage(messageText, inputInfo.movies.length, inputInfo.announcementChannel)
|
||||||
|
if (inputInfo.pinAfterSending)
|
||||||
|
sentMessage.pin()
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
|
||||||
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {
|
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {
|
||||||
let message = `[Abstimmung] für https://discord.com/events/${guildId}/${eventId} \n<@&${config.bot.announcement_role}> Es gibt eine neue Abstimmung für die nächste Watchparty ${createDateStringFromEvent(eventStartDate, guildId, requestId)}! Stimme hierunter für den nächsten Film ab!\n`
|
let message = `[Abstimmung] für https://discord.com/events/${guildId}/${eventId} \n<@&${config.bot.announcement_role}> Es gibt eine neue Abstimmung für die nächste Watchparty ${createDateStringFromEvent(eventStartDate, guildId, requestId)}! Stimme hierunter für den nächsten Film ab!\n`
|
||||||
|
|
||||||
|
@ -171,6 +179,7 @@ export default class VoteController {
|
||||||
|
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
|
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
|
||||||
|
|
||||||
const options: MessageCreateOptions = {
|
const options: MessageCreateOptions = {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Collection } from "@discordjs/collection"
|
import { Collection } from "@discordjs/collection"
|
||||||
import { Role } from "discord.js"
|
import { GuildScheduledEvent, Role, TextChannel } from "discord.js"
|
||||||
|
|
||||||
export type Maybe<T> = T | undefined | null
|
export type Maybe<T> = T | undefined | null
|
||||||
export interface Player {
|
export interface Player {
|
||||||
|
@ -39,3 +39,10 @@ export interface JellyfinConfig {
|
||||||
collectionUser: string
|
collectionUser: string
|
||||||
}
|
}
|
||||||
export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY"
|
export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY"
|
||||||
|
export interface voteMessageInputInformation {
|
||||||
|
movies: string[],
|
||||||
|
startDate: Date,
|
||||||
|
event: GuildScheduledEvent,
|
||||||
|
announcementChannel: TextChannel,
|
||||||
|
pinAfterSending: boolean,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue