move date parsing to separate function
This commit is contained in:
parent
146848b759
commit
fdfe7ce404
@ -13,7 +13,6 @@ import addDays from "date-fns/addDays"
|
||||
import isAfter from "date-fns/isAfter"
|
||||
import { ExtendedClient } from "../structures/client"
|
||||
import { JellyfinHandler } from "../jellyfin/handler"
|
||||
import { getYear } from "date-fns"
|
||||
|
||||
export type Vote = {
|
||||
emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen
|
||||
@ -76,6 +75,9 @@ export default class VoteController {
|
||||
}
|
||||
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 {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
@ -91,18 +93,16 @@ export default class VoteController {
|
||||
if (!result) throw Error('No event url found in Message')
|
||||
eventId = result?.[0].split('/').at(-1) ?? ""
|
||||
} 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)
|
||||
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)
|
||||
eventDate = this.parseEventDateFromLine(line)
|
||||
} else if (line.slice(0, 5).includes(':')) {
|
||||
const splitLine = line.split(":")
|
||||
const [emoji, movie] = splitLine
|
||||
if (emoji === NONE_OF_THAT) continue
|
||||
const fetchedVoteFromMessage = message.reactions.cache.get(emoji)
|
||||
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 {
|
||||
logger.error(`No vote reaction found for movie, assuming 0`, requestId)
|
||||
votes.push({ movie, emote: emoji, count: 0 })
|
||||
@ -111,8 +111,12 @@ export default class VoteController {
|
||||
}
|
||||
return <VoteMessageInfo>{ eventId, eventDate, votes }
|
||||
}
|
||||
private parseEventIdFromMessage(message: Message<boolean> | PartialMessage, requestId: string): string {
|
||||
throw new Error("Method not implemented.")
|
||||
public parseEventDateFromLine(line: string): Date {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user