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 ca99987a20 - Show all commits

View File

@ -186,11 +186,11 @@ export default class VoteController {
return message
}
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
public async sendVoteMessage(messageText: string, movieCount: number, announcementChannel: TextChannel) {
const options: MessageCreateOptions = {
allowedMentions: { parse: ["roles"] },
content: message,
content: messageText,
}
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(options)
@ -237,12 +237,12 @@ export default class VoteController {
logger.info("Deleting vote message")
await lastMessage.delete()
const event = await this.getEvent(guild, guild.id, requestId)
const event = await this.getOpenEvent(guild, guild.id, requestId)
if (event && votes?.length > 0) {
this.updateEvent(event, votes, guild, guildId, requestId)
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId)
this.sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
}
lastMessage.unpin() //todo: uncomment when bot has permission to pin/unpin
lastMessage.unpin()
}
/**
* gets votes for the movies without the NONE_OF_THAT votes
@ -262,7 +262,7 @@ export default class VoteController {
}
magnetotail marked this conversation as resolved
Review

should be renamed so it's clear what the event gets updated with and what it looks like in the end and what kind of event gets updated (I guess open poll events)

should be renamed so it's clear what the event gets updated with and what it looks like in the end and what kind of event gets updated (I guess open poll events)
Review

ca99987a
done

ca99987a done
return votes
}
public async getEvent(guild: Guild, guildId: string, requestId: string): Promise<GuildScheduledEvent | null> {
public async getOpenEvent(guild: Guild, guildId: string, requestId: string): Promise<GuildScheduledEvent | null> {
const voteEvents = (await guild.scheduledEvents.fetch())
.map((value) => value)
.filter(event => event.name.toLowerCase().includes("voting offen"))
@ -274,7 +274,7 @@ export default class VoteController {
}
magnetotail marked this conversation as resolved
Review

"Fehler, event hatte keine Uhrzeit" pls

"Fehler, event hatte keine Uhrzeit" pls
Review

ca99987a20
done

ca99987a20baeceda27cb5e206bff42a54f31b04 done
return voteEvents[0]
}
public async updateEvent(voteEvent: GuildScheduledEvent, votes: Vote[], guild: Guild, guildId: string, requestId: string) {
public async updateOpenPollEventWithVoteResults(voteEvent: GuildScheduledEvent, votes: Vote[], guild: Guild, guildId: string, requestId: string) {
logger.info(`Updating event with movie ${votes[0].movie}.`, { guildId, requestId })
const options: GuildScheduledEventEditOptions<GuildScheduledEventStatus.Scheduled, GuildScheduledEventSetStatusArg<GuildScheduledEventStatus.Scheduled>> = {
name: votes[0].movie,
@ -285,8 +285,8 @@ export default class VoteController {
voteEvent.edit(options)
}
public async sendVoteClosedMessage(event: GuildScheduledEvent, movie: string, guildId: string, requestId: string): Promise<Message<boolean>> {
const date = event.scheduledStartAt ? format(event.scheduledStartAt, "dd.MM.") : "Fehler, event hatte kein Datum"
const time = event.scheduledStartAt ? format(event.scheduledStartAt, "HH:mm") : "Fehler, event hatte kein Datum"
const date = event.scheduledStartAt ? format(event.scheduledStartAt, "dd.MM.") : "Fehler, Event hatte kein Datum"
const time = event.scheduledStartAt ? format(event.scheduledStartAt, "HH:mm") : "Fehler, Event hatte keine Uhrzeit"
magnetotail marked this conversation as resolved Outdated

rename parameter lastMessages to message. "last" seems to be very specific as a parameter, also false plural

rename parameter lastMessages to message. "last" seems to be very specific as a parameter, also false plural

ca99987a20
done

ca99987a20baeceda27cb5e206bff42a54f31b04 done
const body = `[Abstimmung beendet] für https://discord.com/events/${event.guildId}/${event.id}\n<@&${config.bot.announcement_role}> Wir gucken ${movie} am ${date} um ${time}`
const options: MessageCreateOptions = {
content: body,
@ -295,14 +295,14 @@ export default class VoteController {
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
logger.info("Sending vote closed message.", { guildId, requestId })
if (!announcementChannel) {
const errorMessages = "Could not find announcement channel. Please fix!"
logger.error(errorMessages, { guildId, requestId })
throw errorMessages
const errorMessageText = "Could not find announcement channel. Please fix!"
logger.error(errorMessageText, { guildId, requestId })
throw errorMessageText
}
return announcementChannel.send(options)
}
private extractMovieFromMessageByEmote(lastMessages: Message, emote: string): string {
const lines = lastMessages.cleanContent.split("\n")
private extractMovieFromMessageByEmote(voteMessage: VoteMessage, emote: string): string {
const lines = voteMessage.cleanContent.split("\n")
const emoteLines = lines.filter(line => line.includes(emote))
if (!emoteLines) {