feat/40-reroll-on-disinterest #54

Merged
kenobi merged 73 commits from feat/40-reroll-on-disinterest into master 2023-11-19 20:24:36 +01:00
Showing only changes of commit 9383cee4a0 - Show all commits

View File

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

Parameter die eine Message sind heißen oft "message", manchmal aber auch "msg". sollte vereinheitlicht sein

Parameter die eine Message sind heißen oft "message", manchmal aber auch "msg". sollte vereinheitlicht sein
66507cb08fa50ba3a7be28388c55b21227fb2261

fc64728a78

Jetzt sollten alle Occurences beseitigt sein.

fc64728a780f99b56aebff7f0a7c5d24a901d90d Jetzt sollten alle Occurences beseitigt sein.
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

above WHAT threshold? What does it do??

above WHAT threshold? What does it do??
20da25f2bf9a473704f8b4660e5f05183679ba39

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

threshold seems to be a magic number

threshold seems to be a magic number

Or rename method to "hasAtLeastOneVote"

Or rename method to "hasAtLeastOneVote"
296a490e935cbdb79b70d73d2df9bc12a5774c53

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

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
119343c916b023a926e534575ae803cdec5b9594
}
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {
magnetotail marked this conversation as resolved Outdated

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

7d794a8001
done

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

is not a message, only messagetext

is not a message, only messagetext
a455fd8ff7e6b8ffb032fb4aed9389da68ee513b

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)