feat/40-reroll-on-disinterest #54
|
@ -4,7 +4,6 @@ import { client, yavinJellyfinHandler } from "../..";
|
|||
import { Maybe } from "../interfaces";
|
||||
import { logger } from "../logger";
|
||||
|
||||
|
||||
export const name = 'guildScheduledEventCreate'
|
||||
|
||||
export async function execute(event: GuildScheduledEvent) {
|
||||
|
@ -25,15 +24,21 @@ export async function execute(event: GuildScheduledEvent) {
|
|||
return
|
||||
}
|
||||
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
||||
|
||||
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
|
||||
}
|
||||
const sentMessageText = client.voteController.createVoteMessageText(event.id, event.scheduledStartAt, movies, event.guild?.id ?? "", requestId)
|
||||
const sentMessage = await client.voteController.sendVoteMessage(sentMessageText, movies.length, announcementChannel)
|
||||
const sentMessage = await client.voteController.prepareAndSendVoteMessage({
|
||||
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 { VoteMessage, isVoteEndedMessage, isVoteMessage } from "./messageIdentifiers"
|
||||
import { createDateStringFromEvent } from "./dateHelper"
|
||||
import { Maybe } from "../interfaces"
|
||||
import { Maybe, voteMessageInputInformation as prepareVoteMessageInput } from "../interfaces"
|
||||
import format from "date-fns/format"
|
||||
import toDate from "date-fns/toDate"
|
||||
import differenceInDays from "date-fns/differenceInDays"
|
||||
|
@ -161,6 +161,14 @@ export default class VoteController {
|
|||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
|
||||
|
||||
const options: MessageCreateOptions = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 interface Player {
|
||||
|
@ -39,3 +39,10 @@ export interface JellyfinConfig {
|
|||
collectionUser: string
|
||||
}
|
||||
export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY"
|
||||
export interface voteMessageInputInformation {
|
||||
movies: string[],
|
||||
startDate: Date,
|
||||
event: GuildScheduledEvent,
|
||||
announcementChannel: TextChannel,
|
||||
pinAfterSending: boolean,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue