clean up variable and function names
This commit is contained in:
parent
fc64728a78
commit
ca99987a20
@ -186,11 +186,11 @@ export default class VoteController {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendVoteMessage(message: string, movieCount: number, announcementChannel: TextChannel) {
|
public async sendVoteMessage(messageText: string, movieCount: number, announcementChannel: TextChannel) {
|
||||||
|
|
||||||
const options: MessageCreateOptions = {
|
const options: MessageCreateOptions = {
|
||||||
allowedMentions: { parse: ["roles"] },
|
allowedMentions: { parse: ["roles"] },
|
||||||
content: message,
|
content: messageText,
|
||||||
}
|
}
|
||||||
|
|
||||||
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(options)
|
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(options)
|
||||||
@ -237,12 +237,12 @@ export default class VoteController {
|
|||||||
|
|
||||||
logger.info("Deleting vote message")
|
logger.info("Deleting vote message")
|
||||||
await lastMessage.delete()
|
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) {
|
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)
|
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
|
* gets votes for the movies without the NONE_OF_THAT votes
|
||||||
@ -262,7 +262,7 @@ export default class VoteController {
|
|||||||
}
|
}
|
||||||
return votes
|
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())
|
const voteEvents = (await guild.scheduledEvents.fetch())
|
||||||
.map((value) => value)
|
.map((value) => value)
|
||||||
.filter(event => event.name.toLowerCase().includes("voting offen"))
|
.filter(event => event.name.toLowerCase().includes("voting offen"))
|
||||||
@ -274,7 +274,7 @@ export default class VoteController {
|
|||||||
}
|
}
|
||||||
return voteEvents[0]
|
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 })
|
logger.info(`Updating event with movie ${votes[0].movie}.`, { guildId, requestId })
|
||||||
const options: GuildScheduledEventEditOptions<GuildScheduledEventStatus.Scheduled, GuildScheduledEventSetStatusArg<GuildScheduledEventStatus.Scheduled>> = {
|
const options: GuildScheduledEventEditOptions<GuildScheduledEventStatus.Scheduled, GuildScheduledEventSetStatusArg<GuildScheduledEventStatus.Scheduled>> = {
|
||||||
name: votes[0].movie,
|
name: votes[0].movie,
|
||||||
@ -285,8 +285,8 @@ export default class VoteController {
|
|||||||
voteEvent.edit(options)
|
voteEvent.edit(options)
|
||||||
}
|
}
|
||||||
public async sendVoteClosedMessage(event: GuildScheduledEvent, movie: string, guildId: string, requestId: string): Promise<Message<boolean>> {
|
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 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 time = event.scheduledStartAt ? format(event.scheduledStartAt, "HH:mm") : "Fehler, Event hatte keine Uhrzeit"
|
||||||
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 = {
|
const options: MessageCreateOptions = {
|
||||||
content: body,
|
content: body,
|
||||||
@ -295,14 +295,14 @@ export default class VoteController {
|
|||||||
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
||||||
logger.info("Sending vote closed message.", { guildId, requestId })
|
logger.info("Sending vote closed message.", { guildId, requestId })
|
||||||
if (!announcementChannel) {
|
if (!announcementChannel) {
|
||||||
const errorMessages = "Could not find announcement channel. Please fix!"
|
const errorMessageText = "Could not find announcement channel. Please fix!"
|
||||||
logger.error(errorMessages, { guildId, requestId })
|
logger.error(errorMessageText, { guildId, requestId })
|
||||||
throw errorMessages
|
throw errorMessageText
|
||||||
}
|
}
|
||||||
return announcementChannel.send(options)
|
return announcementChannel.send(options)
|
||||||
}
|
}
|
||||||
private extractMovieFromMessageByEmote(lastMessages: Message, emote: string): string {
|
private extractMovieFromMessageByEmote(voteMessage: VoteMessage, emote: string): string {
|
||||||
const lines = lastMessages.cleanContent.split("\n")
|
const lines = voteMessage.cleanContent.split("\n")
|
||||||
const emoteLines = lines.filter(line => line.includes(emote))
|
const emoteLines = lines.filter(line => line.includes(emote))
|
||||||
|
|
||||||
if (!emoteLines) {
|
if (!emoteLines) {
|
||||||
|
Loading…
Reference in New Issue
Block a user