scaffolding for poll reroll function
This commit is contained in:
parent
0748097a1f
commit
9383cee4a0
@ -1,5 +1,5 @@
|
||||
import { Guild, GuildScheduledEvent, GuildScheduledEventEditOptions, GuildScheduledEventSetStatusArg, GuildScheduledEventStatus, Message, MessageCreateOptions, MessageReaction, TextChannel, User } from "discord.js"
|
||||
import { client } from "../.."
|
||||
import { client, yavinJellyfinHandler } from "../.."
|
||||
import { Emotes, NONE_OF_THAT } from "../constants"
|
||||
import { logger, newRequestId } from "../logger"
|
||||
import { getMembersWithRoleFromGuild } from "./roleFilter"
|
||||
@ -37,21 +37,54 @@ export default class VoteController {
|
||||
if (noneOfThatReactions > memberThreshold) {
|
||||
logger.info('Starting poll reroll', { requestId, guildId })
|
||||
messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
|
||||
// get movies that _had_ votes
|
||||
const oldMovieNames: string[] = this.parseMoviesFromVoteMessage(messageReaction.message,requestId)
|
||||
const eventId = this.parseEventIdFromMessage(messageReaction.message, requestId)
|
||||
const eventStartDate: Date = this.fetchEventStartDateByEventId(eventId,requestId) //TODO
|
||||
//
|
||||
// get movies from jellyfin to fill the remaining slots
|
||||
const newMovieCount = config.bot.random_movie_count - oldMovieNames.length
|
||||
const newMovies = await yavinJellyfinHandler.getRandomMovieNames(newMovieCount, guildId, requestId)
|
||||
|
||||
// merge
|
||||
const movies = oldMovieNames.concat(newMovies)
|
||||
|
||||
// create new message
|
||||
await this.closePoll(messageReaction.message.guild, requestId)
|
||||
const message = this.createVoteMessageText(eventId, eventStartDate, movies, guildId, requestId)
|
||||
const announcementChannel = client.getAnnouncementChannelForGuild(guildId)
|
||||
if (!announcementChannel) {
|
||||
logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
|
||||
return
|
||||
}
|
||||
const sentMessage = await this.sendVoteMessage(message, movies.length, announcementChannel)
|
||||
sentMessage.pin()
|
||||
}
|
||||
logger.info(`No reroll`, { requestId, guildId })
|
||||
}
|
||||
private fetchEventStartDateByEventId(eventId: string, requestId: string): Date {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
private parseMoviesFromVoteMessage(message: Message<boolean> | import("discord.js").PartialMessage, requestId: string): string[] {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
private parseEventIdFromMessage(message: Message<boolean> | import("discord.js").PartialMessage, requestId: string): string {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {
|
||||
|
||||
public async createVoteMessage(event: GuildScheduledEvent, announcementChannel: TextChannel, movies: string[], guildId: string, requestId: string): Promise<Message<boolean>> {
|
||||
|
||||
let message = `[Abstimmung] für https://discord.com/events/${event.guildId}/${event.id}\n<@&${config.bot.announcement_role}> Es gibt eine neue Abstimmung für die nächste Watchparty ${createDateStringFromEvent(event, event.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`
|
||||
|
||||
for (let i = 0; i < movies.length; i++) {
|
||||
message = message.concat(Emotes[i]).concat(": ").concat(movies[i]).concat("\n")
|
||||
}
|
||||
message = message.concat(NONE_OF_THAT).concat(": Wenn dir nichts davon gefällt.")
|
||||
|
||||
return message
|
||||
}
|
||||
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
|
||||
|
||||
const options: MessageCreateOptions = {
|
||||
allowedMentions: { parse: ["roles"] },
|
||||
content: message,
|
||||
@ -59,7 +92,7 @@ export default class VoteController {
|
||||
|
||||
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(options)
|
||||
|
||||
for (let i = 0; i < movies.length; i++) {
|
||||
for (let i = 0; i < movieCount; i++) {
|
||||
sentMessage.react(Emotes[i])
|
||||
}
|
||||
sentMessage.react(NONE_OF_THAT)
|
||||
|
Loading…
Reference in New Issue
Block a user