clean up variable and function names
Some checks failed
Compile the repository / compile (pull_request) Failing after 16s
Run unit tests / test (pull_request) Failing after 13s

This commit is contained in:
kenobi 2023-11-19 18:21:51 +01:00
parent fc64728a78
commit ca99987a20

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 {
}
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 {
}
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"
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) {