2022-01-19 22:18:52 +01:00
|
|
|
import { Collection, Guild, GuildScheduledEvent, Snowflake } from "discord.js";
|
|
|
|
|
|
|
|
export default class eventHandler {
|
|
|
|
|
|
|
|
public constructor() {
|
|
|
|
console.log('constructed')
|
|
|
|
}
|
2022-02-27 16:20:42 +01:00
|
|
|
public getNextEvent(guild: Guild): string {
|
|
|
|
const eventManager = guild.scheduledEvents
|
|
|
|
const events = eventManager.cache
|
|
|
|
const sortedEvents = events.sort(function(a, b) { return Number(a.scheduledStartAt) - Number(b.scheduledStartAt) })
|
|
|
|
|
|
|
|
console.log(JSON.stringify(events))
|
|
|
|
console.log(JSON.stringify(sortedEvents))
|
|
|
|
|
|
|
|
return sortedEvents.first()?.toString() ?? ""
|
|
|
|
}
|
2022-01-19 22:18:52 +01:00
|
|
|
public listAllEvents(guild: Guild): string {
|
|
|
|
|
|
|
|
const eventManager = guild.scheduledEvents
|
|
|
|
const events: Collection<Snowflake, GuildScheduledEvent> = eventManager.cache
|
|
|
|
const entries = events.values()
|
|
|
|
let output = ""
|
|
|
|
|
|
|
|
for (const e of entries) {
|
|
|
|
console.log(e)
|
2022-02-27 16:20:42 +01:00
|
|
|
output += "\n"
|
2022-01-19 22:18:52 +01:00
|
|
|
output += e.toString()
|
|
|
|
}
|
|
|
|
console.log(output)
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
}
|