Compare commits
No commits in common. "c022cc32d5de3f2bb695f7dad3a19d6347fbc9b8" and "fdfe7ce404ee085f093f42284fd5f71b5ca8e2df" have entirely different histories.
c022cc32d5
...
fdfe7ce404
@ -18,6 +18,6 @@ export function createDateStringFromEvent(eventStartDate:Date, requestId: string
|
|||||||
return `heute um ${time}`
|
return `heute um ${time}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const date = format(zonedDateTime, "eeee dd.MM.", { locale: de })
|
const date = format(zonedDateTime, "eeee dd.MM", { locale: de })
|
||||||
return `am ${date} um ${time}`
|
return `am ${date} um ${time}`
|
||||||
}
|
}
|
||||||
|
@ -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 { ObjectGroupUpdateToJSON } from "../jellyfin"
|
|
||||||
|
|
||||||
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
|
||||||
@ -53,8 +52,8 @@ export default class VoteController {
|
|||||||
messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
|
messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
|
||||||
// get movies that _had_ votes
|
// get movies that _had_ votes
|
||||||
//const oldMovieNames: Vote[] = this.parseVotesFromVoteMessage(messageReaction.message, requestId)
|
//const oldMovieNames: Vote[] = this.parseVotesFromVoteMessage(messageReaction.message, requestId)
|
||||||
const parsedIds = this.parseGuildIdAndEventIdFromWholeMessage(messageReaction.message.cleanContent ?? '')
|
const eventId = this.parseEventIdFromMessage(messageReaction.message, requestId)
|
||||||
const eventStartDate: Date = this.fetchEventStartDateByEventId(parsedIds.eventId, requestId) //TODO
|
const eventStartDate: Date = this.fetchEventStartDateByEventId(eventId, requestId) //TODO
|
||||||
//
|
//
|
||||||
// get movies from jellyfin to fill the remaining slots
|
// get movies from jellyfin to fill the remaining slots
|
||||||
const newMovieCount = config.bot.random_movie_count //- oldMovieNames.length
|
const newMovieCount = config.bot.random_movie_count //- oldMovieNames.length
|
||||||
@ -65,7 +64,7 @@ export default class VoteController {
|
|||||||
|
|
||||||
// create new message
|
// create new message
|
||||||
await this.closePoll(messageReaction.message.guild, requestId)
|
await this.closePoll(messageReaction.message.guild, requestId)
|
||||||
const message = this.createVoteMessageText(parsedIds.guildId, eventStartDate, movies, guildId, requestId)
|
const message = this.createVoteMessageText(eventId, eventStartDate, movies, guildId, requestId)
|
||||||
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
|
||||||
if (!announcementChannel) {
|
if (!announcementChannel) {
|
||||||
logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
|
logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
|
||||||
@ -76,23 +75,26 @@ 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.")
|
||||||
}
|
}
|
||||||
public parseGuildIdAndEventIdFromWholeMessage(message: string) {
|
|
||||||
const idmatch = RegExp(/(?:http|https):\/\/discord\.com\/events\/(\d*)\/(\d*)/)
|
|
||||||
const matches = message.match(idmatch)
|
|
||||||
if (matches && matches.length == 3)
|
|
||||||
return { guildId: matches[1], eventId: matches[2] }
|
|
||||||
throw Error(`Could not find eventId in Vote Message`)
|
|
||||||
}
|
|
||||||
public parseVotesFromVoteMessage(message: VoteMessage, requestId: string): VoteMessageInfo {
|
public parseVotesFromVoteMessage(message: VoteMessage, requestId: string): VoteMessageInfo {
|
||||||
const lines = message.cleanContent.split('\n')
|
const lines = message.cleanContent.split('\n')
|
||||||
let parsedIds = this.parseGuildIdAndEventIdFromWholeMessage(message.cleanContent)
|
let eventId = ""
|
||||||
let eventDate: Date = this.parseEventDateFromMessage(message.cleanContent)
|
let eventDate: Date = new Date()
|
||||||
let votes: Vote[] = []
|
let votes: Vote[] = []
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.slice(0, 5).includes(':')) {
|
if (line.includes('https://discord.com/events')) {
|
||||||
|
const urlMatcher = RegExp(/(http|https|ftp):\/\/(\S*)/ig)
|
||||||
|
const result = line.match(urlMatcher)
|
||||||
|
if (!result) throw Error('No event url found in Message')
|
||||||
|
eventId = result?.[0].split('/').at(-1) ?? ""
|
||||||
|
} else if (!line.slice(0, 5).includes(':')) {
|
||||||
|
eventDate = this.parseEventDateFromLine(line)
|
||||||
|
} else if (line.slice(0, 5).includes(':')) {
|
||||||
const splitLine = line.split(":")
|
const splitLine = line.split(":")
|
||||||
const [emoji, movie] = splitLine
|
const [emoji, movie] = splitLine
|
||||||
const fetchedVoteFromMessage = message.reactions.cache.get(emoji)
|
const fetchedVoteFromMessage = message.reactions.cache.get(emoji)
|
||||||
@ -107,13 +109,13 @@ export default class VoteController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <VoteMessageInfo>{ eventId: parsedIds.eventId, eventDate, votes }
|
return <VoteMessageInfo>{ eventId, eventDate, votes }
|
||||||
}
|
}
|
||||||
public parseEventDateFromMessage(message: string): Date {
|
public parseEventDateFromLine(line: string): Date {
|
||||||
const datematcher = RegExp(/((?:0[1-9]|[12][0-9]|3[01])\.(?:0[1-9]|1[012])\.)(?:\ um\ )((?:(?:[01][0-9]|[2][0-3])\:[0-5][0-9])|(?:[2][4]\:00))!/i)
|
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 = message.match(datematcher)
|
const result: RegExpMatchArray | null = line.match(datematcher)
|
||||||
const timeFromResult = result?.at(-1)
|
const timeFromResult = result?.at(-1)
|
||||||
const dateFromResult = result?.at(1)?.concat(format(new Date(), 'yyyy')).concat(" " + timeFromResult) ?? ""
|
const dateFromResult = result?.at(1)?.concat(format(new Date(), '.yyyy')).concat(" " + timeFromResult) ?? ""
|
||||||
return new Date(dateFromResult)
|
return new Date(dateFromResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,8 @@ test('parse votes from vote message', () => {
|
|||||||
]
|
]
|
||||||
const testEventId = '1234321'
|
const testEventId = '1234321'
|
||||||
const testEventDate = new Date('2023-01-01')
|
const testEventDate = new Date('2023-01-01')
|
||||||
const testGuildId = "888999888"
|
|
||||||
const voteController: VoteController = new VoteController(<ExtendedClient>{}, <JellyfinHandler>{})
|
const voteController: VoteController = new VoteController(<ExtendedClient>{}, <JellyfinHandler>{})
|
||||||
const testMessage = voteController.createVoteMessageText(testEventId, testEventDate, testMovies, testGuildId, "requestId")
|
const testMessage = voteController.createVoteMessageText(testEventId, testEventDate, testMovies, "guildid", "requestId")
|
||||||
|
|
||||||
|
|
||||||
const expectedResult: VoteMessageInfo = {
|
const expectedResult: VoteMessageInfo = {
|
||||||
@ -54,21 +53,3 @@ test('parse votes from vote message', () => {
|
|||||||
expect(result.votes.length).toEqual(expectedResult.votes.length)
|
expect(result.votes.length).toEqual(expectedResult.votes.length)
|
||||||
expect(result).toEqual(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parse votes from vote message', () => {
|
|
||||||
const testMovies = [
|
|
||||||
'Movie1',
|
|
||||||
'Movie2',
|
|
||||||
'Movie3',
|
|
||||||
'Movie4',
|
|
||||||
'Movie5',
|
|
||||||
]
|
|
||||||
const testEventId = '1234321'
|
|
||||||
const testEventDate = new Date('2023-01-01')
|
|
||||||
const testGuildId = "888999888"
|
|
||||||
const voteController: VoteController = new VoteController(<ExtendedClient>{}, <JellyfinHandler>{})
|
|
||||||
const testMessage = voteController.createVoteMessageText(testEventId, testEventDate, testMovies, testGuildId, "requestId")
|
|
||||||
|
|
||||||
const result = voteController.parseGuildIdAndEventIdFromWholeMessage(testMessage)
|
|
||||||
expect(result).toEqual({ guildId: testGuildId, eventId: testEventId })
|
|
||||||
})
|
|
||||||
|
@ -10,6 +10,6 @@ function getTestDate(date: string): Date {
|
|||||||
}
|
}
|
||||||
test('createDateStringFromEvent - correct formatting', () => {
|
test('createDateStringFromEvent - correct formatting', () => {
|
||||||
expect(createDateStringFromEvent(getTestDate('01-01-2023 12:30'), "")).toEqual('heute um 12:30')
|
expect(createDateStringFromEvent(getTestDate('01-01-2023 12:30'), "")).toEqual('heute um 12:30')
|
||||||
expect(createDateStringFromEvent(getTestDate('01-02-2023 12:30'), "")).toEqual('am Montag 02.01. um 12:30')
|
expect(createDateStringFromEvent(getTestDate('01-02-2023 12:30'), "")).toEqual('am Montag 02.01 um 12:30')
|
||||||
expect(createDateStringFromEvent(getTestDate('01-03-2023 12:30'), "")).toEqual('am Dienstag 03.01. um 12:30')
|
expect(createDateStringFromEvent(getTestDate('01-03-2023 12:30'), "")).toEqual('am Dienstag 03.01 um 12:30')
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user