move preparation of vote Message sending into vote controller
All checks were successful
Compile the repository / compile (pull_request) Successful in 17s
Run unit tests / test (pull_request) Successful in 13s

event only needs to supply information, text creation, sending and pinning happens in the vote controller
This commit is contained in:
2023-11-18 17:28:44 +01:00
parent 4a3e8809be
commit 4600820889
3 changed files with 29 additions and 8 deletions

View File

@ -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 = {