feat/40-reroll-on-disinterest #54
@ -57,31 +57,53 @@ export default class VoteController {
|
||||
}
|
||||
}
|
||||
|
||||
private async removeMessage(msg: Message): Promise<Message<boolean>> {
|
||||
magnetotail marked this conversation as resolved
Outdated
|
||||
if (msg.pinned) {
|
||||
await msg.unpin()
|
||||
}
|
||||
return await msg.delete()
|
||||
}
|
||||
public isAboveThreshold(vote: Vote): boolean {
|
||||
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
|
||||
const aboveThreshold = (vote.count - 1) >= 1
|
||||
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
|
||||
logger.debug(`${vote.movie} : ${vote.count} -> above: ${aboveThreshold}`)
|
||||
return aboveThreshold
|
||||
}
|
||||
public async handleReroll(voteMessage: VoteMessage, guild: Guild, guildId: string, requestId: string) {
|
||||
|
||||
//get movies that already had votes to give them a second chance
|
||||
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
|
||||
const voteInfo: VoteMessageInfo = await this.parseVoteInfoFromVoteMessage(voteMessage, requestId)
|
||||
const votedOnMovies = voteInfo.votes.filter(this.isAboveThreshold).filter(x => x.emote !== NONE_OF_THAT)
|
||||
logger.info(`Found ${votedOnMovies.length} with votes`, { requestId, guildId })
|
||||
|
||||
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
|
||||
// get movies from jellyfin to fill the remaining slots
|
||||
const newMovieCount: number = config.bot.random_movie_count - voteInfo.votes.filter(x => x.count > 2).length
|
||||
const newMovieCount: number = config.bot.random_movie_count - votedOnMovies.length
|
||||
logger.info(`Fetching ${newMovieCount} from jellyfin`)
|
||||
const newMovies: string[] = await this.yavinJellyfinHandler.getRandomMovieNames(newMovieCount, guildId, requestId)
|
||||
|
||||
// merge
|
||||
const movies: string[] = newMovies.concat(voteInfo.votes.map(x => x.movie))
|
||||
const movies: string[] = newMovies.concat(votedOnMovies.map(x => x.movie))
|
||||
|
||||
// create new message
|
||||
await this.closePoll(guild, requestId)
|
||||
const message = this.createVoteMessageText(guild.id, voteInfo.eventDate, movies, guildId, requestId)
|
||||
|
||||
logger.info(`Creating new poll message with new movies: ${movies}`, { requestId, guildId })
|
||||
const message = this.createVoteMessageText(voteInfo.eventId, voteInfo.eventDate, movies, guildId, requestId)
|
||||
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
||||
if (!announcementChannel) {
|
||||
logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
|
||||
return
|
||||
}
|
||||
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
|
||||
|
||||
try {
|
||||
logger.info(`Trying to remove old vote Message`, { requestId, guildId })
|
||||
this.removeMessage(voteMessage)
|
||||
} catch (err) {
|
||||
logger.error(`Error during removeMessage: ${err}`)
|
||||
}
|
||||
|
||||
const sentMessage = await this.sendVoteMessage(message, movies.length, announcementChannel)
|
||||
sentMessage.pin()
|
||||
logger.info(`Sent and pinned new poll message`, { requestId, guildId })
|
||||
}
|
||||
|
||||
|
||||
private async fetchEventStartDateByEventId(guild: Guild, eventId: string, requestId: string): Promise<Maybe<Date>> {
|
||||
const guildEvent: GuildScheduledEvent = await guild.scheduledEvents.fetch(eventId)
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
why not pin message in method above? why not pin message in method above?
kenobi
commented
7d794a8001a66d068f949c893d689a068c3caeed
should have been moved to prepareAndSendVoteMessage()
|
||||
if (!guildEvent) logger.error(`GuildScheduledEvent with id${eventId} could not be found`, { requestId, guildId: guild.id })
|
||||
@ -196,14 +218,15 @@ export default class VoteController {
|
||||
logger.info("Deleting vote message")
|
||||
await lastMessage.delete()
|
||||
const event = await this.getEvent(guild, guild.id, requestId)
|
||||
if (event) {
|
||||
if (event && votes?.length > 0) {
|
||||
this.updateEvent(event, votes, guild, guildId, requestId)
|
||||
this.sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
|
||||
}
|
||||
|
||||
lastMessage.unpin() //todo: uncomment when bot has permission to pin/unpin
|
||||
|
||||
}
|
||||
/**
|
||||
* gets votes for the movies without the NONE_OF_THAT votes
|
||||
*/
|
||||
public async getVotesByEmote(message: Message, guildId: string, requestId: string): Promise<Vote[]> {
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
remove todo remove todo
kenobi
commented
removed removed
ca99987a20baeceda27cb5e206bff42a54f31b04
|
||||
const votes: Vote[] = []
|
||||
logger.debug(`Number of items in emotes: ${Object.values(Emotes).length}`, { guildId, requestId })
|
||||
@ -241,10 +264,10 @@ export default class VoteController {
|
||||
logger.info("Updating event.", { guildId, requestId })
|
||||
voteEvent.edit(options)
|
||||
}
|
||||
public async sendVoteClosedMessage(event: GuildScheduledEvent, movie: string, guildId: string, requestId: string) {
|
||||
const date = event.scheduledStartAt ? format(event.scheduledStartAt, "dd.MM") : "Fehler, event hatte kein Datum"
|
||||
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 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 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,
|
||||
allowedMentions: { parse: ["roles"] }
|
||||
@ -252,13 +275,14 @@ export default class VoteController {
|
||||
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
||||
logger.info("Sending vote closed message.", { guildId, requestId })
|
||||
if (!announcementChannel) {
|
||||
logger.error("Could not find announcement channel. Please fix!", { guildId, requestId })
|
||||
return
|
||||
const errorMessages = "Could not find announcement channel. Please fix!"
|
||||
logger.error(errorMessages, { guildId, requestId })
|
||||
throw errorMessages
|
||||
}
|
||||
announcementChannel.send(options)
|
||||
return announcementChannel.send(options)
|
||||
}
|
||||
magnetotail marked this conversation as resolved
Outdated
magnetotail
commented
why plural? why plural?
kenobi
commented
Because this was unintentional :)
Because this was unintentional :)
ca99987a20baeceda27cb5e206bff42a54f31b04
fixed
|
||||
private extractMovieFromMessageByEmote(message: Message, emote: string): string {
|
||||
const lines = message.cleanContent.split("\n")
|
||||
private extractMovieFromMessageByEmote(lastMessages: Message, emote: string): string {
|
||||
const lines = lastMessages.cleanContent.split("\n")
|
||||
const emoteLines = lines.filter(line => line.includes(emote))
|
||||
|
||||
if (!emoteLines) {
|
||||
|
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.