feat/40-reroll-on-disinterest #54
@ -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)
|
||||
magnetotail marked this conversation as resolved
Outdated
|
||||
sentMessage.pin()
|
||||
}
|
||||
logger.info(`No reroll`, { requestId, guildId })
|
||||
}
|
||||
private fetchEventStartDateByEventId(eventId: string, requestId: string): Date {
|
||||
throw new Error("Method not implemented.")
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
above WHAT threshold? What does it do?? above WHAT threshold? What does it do??
kenobi
commented
20da25f2bf9a473704f8b4660e5f05183679ba39
kenobi
commented
Mit einem Kommentar versehen und entsprechend deines vorschlags umbenannt Mit einem Kommentar versehen und entsprechend deines vorschlags umbenannt
|
||||
}
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
threshold seems to be a magic number threshold seems to be a magic number
magnetotail
commented
Or rename method to "hasAtLeastOneVote" Or rename method to "hasAtLeastOneVote"
kenobi
commented
296a490e935cbdb79b70d73d2df9bc12a5774c53
kenobi
commented
done done
|
||||
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.")
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
comment is misleading, voteinfo is also used to get the eventid and eventdate in line 93 comment is misleading, voteinfo is also used to get the eventid and eventdate in line 93
kenobi
commented
119343c916b023a926e534575ae803cdec5b9594
|
||||
}
|
||||
|
||||
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {
|
||||
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
maybe extract this if-else to a method to keep code more compact maybe extract this if-else to a method to keep code more compact
kenobi
commented
7d794a8001a66d068f949c893d689a068c3caeed
done
|
||||
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)
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
is not a message, only messagetext is not a message, only messagetext
kenobi
commented
a455fd8ff7e6b8ffb032fb4aed9389da68ee513b
kenobi
commented
done done
|
||||
|
||||
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
Parameter die eine Message sind heißen oft "message", manchmal aber auch "msg". sollte vereinheitlicht sein
66507cb08f
fc64728a78
Jetzt sollten alle Occurences beseitigt sein.