diff --git a/src/bot.ts b/src/bot.ts index 8557d54..cf607b6 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -11,8 +11,6 @@ import { import { getBotToken, getServerListScheduleRule, - getSundayEventScheduleRule, - getFridayEventScheduleRule, } from "./config"; import { Command, @@ -25,7 +23,7 @@ import { } from "./core"; import { LoggerFactory } from "./logger.factory"; import { runMigrations, SchedulerService } from "./services"; -import { ServerListJob, SundayEventScheduleJob } from "./tasks"; +import { ServerListJob } from "./tasks"; const logger = LoggerFactory.getLogger("Bot"); @@ -168,8 +166,6 @@ export class Bot { private scheduleJobs() { const serverListScheduleRule = getServerListScheduleRule(); - const sundayEventScheduleRule = getSundayEventScheduleRule(); - const fridayEventScheduleRule = getFridayEventScheduleRule(); if (serverListScheduleRule) { SchedulerService.schedule( @@ -178,14 +174,6 @@ export class Bot { new ServerListJob() ); } - - if (sundayEventScheduleRule) { - SchedulerService.schedule( - "SundayEvent", - sundayEventScheduleRule, - new SundayEventScheduleJob() - ); - } } } diff --git a/src/config.ts b/src/config.ts index 7d3aa7a..a06b6fb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -58,7 +58,3 @@ export const getCommunityEventRoleId = () => getRequiredEnvVariable("COMMUNITY_EVENT_ROLE_ID"); export const getCommunityEventChannelId = () => getRequiredEnvVariable("COMMUNITY_EVENT_CHANNEL_ID"); -export const getSundayEventScheduleRule = () => - getEnvVariable("SUNDAY_EVENT_SCHEDULE_RULE"); -export const getFridayEventScheduleRule = () => - getEnvVariable("FRIDAY_EVENT_SCHEDULE_RULE"); diff --git a/src/tasks/index.ts b/src/tasks/index.ts index 8b74fd9..60bec6d 100644 --- a/src/tasks/index.ts +++ b/src/tasks/index.ts @@ -1,2 +1 @@ export * from "./serverlist.task"; -export * from "./sunday-events.task"; diff --git a/src/tasks/sunday-events.task.ts b/src/tasks/sunday-events.task.ts deleted file mode 100644 index 8803185..0000000 --- a/src/tasks/sunday-events.task.ts +++ /dev/null @@ -1,86 +0,0 @@ -import dayjs from "dayjs"; -import { - GuildScheduledEventEntityType, - GuildScheduledEventManager, - GuildScheduledEventPrivacyLevel, -} from "discord.js"; - -import { - getCommunityEventChannelId, - getCommunityEventRoleId, - getGuildId, -} from "../config"; -import { getClientInstance } from "../core"; -import { LoggerFactory } from "../logger.factory"; -import { ScheduleJob } from "../services"; -import { fetchTextChannel } from "../utils"; - -const logger = LoggerFactory.getLogger("ServerEventsScheduleJob"); - -const eventName = "Reality Mod Sundays"; -const eventDescription = - "UKF invites you to the weekly Sunday Reality Mod event to play with the rest of the community. Everyone is invited to join!"; - -export class SundayEventScheduleJob implements ScheduleJob { - async execute() { - const client = getClientInstance(); - - const guild = client.guilds.cache.get(getGuildId()); - if (!guild) { - logger.error( - "Failed to find guild %s, can not create event", - getGuildId() - ); - return; - } - - await this.createEvent(guild.scheduledEvents); - } - - async createEvent(eventManager: GuildScheduledEventManager) { - // const existingEvent = eventManager.cache.find( - // (it) => it.creator === eventManager.client.user && it.name === eventName - // ); - // if (existingEvent) { - // logger.info("Found existing sunday event %s", existingEvent.id); - // return; - // } - - // in dayjs Sunday is the first day of the week...weird, okay lets work around it - // First we go to the next week - // Then we set the day to 0 which is Sunday, not Monday ;) - // And set the time to 19:00:00 - const sundayStartDate = dayjs() - .add(1, "week") - .day(0) - .hour(18) - .minute(0) - .second(0); - const sundayEndDate = sundayStartDate.add(4, "hour"); - - const createdEvent = await eventManager.create({ - name: eventName, - description: eventDescription, - scheduledStartTime: sundayStartDate.toDate(), - scheduledEndTime: sundayEndDate.toDate(), - privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly, - entityType: GuildScheduledEventEntityType.External, - entityMetadata: { - location: "UKF RealityMod Server", - }, - }); - logger.info( - "Created sunday event %s, which is scheduled at %s", - createdEvent.id, - sundayStartDate - ); - - const eventChannel = await fetchTextChannel( - getClientInstance(), - getCommunityEventChannelId() - ); - await eventChannel.send({ - content: `<@&${getCommunityEventRoleId()}> ${createdEvent.url}`, - }); - } -}