move date parsing to separate function
All checks were successful
Compile the repository / compile (pull_request) Successful in 1m10s
Run unit tests / test (pull_request) Successful in 2m6s

This commit is contained in:
kenobi 2023-07-17 21:30:02 +02:00
parent 146848b759
commit fdfe7ce404

View File

@ -13,7 +13,6 @@ import addDays from "date-fns/addDays"
import isAfter from "date-fns/isAfter" import isAfter from "date-fns/isAfter"
import { ExtendedClient } from "../structures/client" import { ExtendedClient } from "../structures/client"
import { JellyfinHandler } from "../jellyfin/handler" import { JellyfinHandler } from "../jellyfin/handler"
import { getYear } from "date-fns"
export type Vote = { export type Vote = {
emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen
@ -76,6 +75,9 @@ export default class VoteController {
} }
logger.info(`No reroll`, { requestId, guildId }) logger.info(`No reroll`, { requestId, guildId })
} }
parseEventIdFromMessage(message: Message<boolean> | PartialMessage, requestId: string): string {
throw new Error("Method not implemented.")
}
private fetchEventStartDateByEventId(eventId: string, requestId: string): Date { private fetchEventStartDateByEventId(eventId: string, requestId: string): Date {
throw new Error("Method not implemented.") throw new Error("Method not implemented.")
} }
@ -91,18 +93,16 @@ export default class VoteController {
if (!result) throw Error('No event url found in Message') if (!result) throw Error('No event url found in Message')
eventId = result?.[0].split('/').at(-1) ?? "" eventId = result?.[0].split('/').at(-1) ?? ""
} else if (!line.slice(0, 5).includes(':')) { } else if (!line.slice(0, 5).includes(':')) {
const datematcher = RegExp(/((0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012]))(\ um\ )(([012][0-9]:[0-5][0-9]))/i) eventDate = this.parseEventDateFromLine(line)
const result: RegExpMatchArray | null = line.match(datematcher)
const timeFromResult = result?.at(-1)
const dateFromResult = result?.at(1)?.concat(format(new Date(), '.yyyy')).concat(" " + timeFromResult) ?? ""
eventDate = new Date(dateFromResult)
} else if (line.slice(0, 5).includes(':')) { } else if (line.slice(0, 5).includes(':')) {
const splitLine = line.split(":") const splitLine = line.split(":")
const [emoji, movie] = splitLine const [emoji, movie] = splitLine
if (emoji === NONE_OF_THAT) continue
const fetchedVoteFromMessage = message.reactions.cache.get(emoji) const fetchedVoteFromMessage = message.reactions.cache.get(emoji)
if (fetchedVoteFromMessage) { if (fetchedVoteFromMessage) {
votes.push({ movie:movie.trim(), emote: emoji, count: fetchedVoteFromMessage.count }) if (emoji === NONE_OF_THAT) {
votes.push({ movie: NONE_OF_THAT, emote: NONE_OF_THAT, count: fetchedVoteFromMessage.count })
} else
votes.push({ movie: movie.trim(), emote: emoji, count: fetchedVoteFromMessage.count })
} else { } else {
logger.error(`No vote reaction found for movie, assuming 0`, requestId) logger.error(`No vote reaction found for movie, assuming 0`, requestId)
votes.push({ movie, emote: emoji, count: 0 }) votes.push({ movie, emote: emoji, count: 0 })
@ -111,8 +111,12 @@ export default class VoteController {
} }
return <VoteMessageInfo>{ eventId, eventDate, votes } return <VoteMessageInfo>{ eventId, eventDate, votes }
} }
private parseEventIdFromMessage(message: Message<boolean> | PartialMessage, requestId: string): string { public parseEventDateFromLine(line: string): Date {
throw new Error("Method not implemented.") const datematcher = RegExp(/((0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012]))(\ um\ )(([012][0-9]:[0-5][0-9]))/i)
const result: RegExpMatchArray | null = line.match(datematcher)
const timeFromResult = result?.at(-1)
const dateFromResult = result?.at(1)?.concat(format(new Date(), '.yyyy')).concat(" " + timeFromResult) ?? ""
return new Date(dateFromResult)
} }
public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string { public createVoteMessageText(eventId: string, eventStartDate: Date, movies: string[], guildId: string, requestId: string): string {