Skip to content

Commit

Permalink
we don't need this anymore
Browse files Browse the repository at this point in the history
since discord now implemented recurring events
  • Loading branch information
Techbot121 authored and Meta Construct committed Dec 24, 2023
1 parent de808ae commit 39677d0
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions app/services/discord/modules/discord-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ import { DiscordBot } from "..";
import { join } from "path";
import Discord from "discord.js";
import DiscordConfig from "@/config/discord.json";
import dayjs from "dayjs";

const events = [
{
icon: "vr",
eventData: {
entityType: Discord.GuildScheduledEventEntityType.External,
privacyLevel: Discord.GuildScheduledEventPrivacyLevel.GuildOnly,
entityMetadata: { location: "VRChat" },
name: "VRChat [Automated Event]",
description:
"Wanna join us in VR? Sign up so we know. Discussion in <#1009704968070107148>\n\nAlso checkout our Group at https://vrchat.com/home/group/grp_caeaacf4-a8a7-4e7d-8b66-46094732f85b",
reason: "Automated Event",
} as Discord.GuildScheduledEventCreateOptions,
triggers: ["vrchat", "vr"],
notificationChannel: DiscordConfig.threads.VR,
},
];
const iconsPath = join(process.cwd(), "resources/discord-event-icons");
Expand All @@ -31,39 +20,6 @@ export default (bot: DiscordBot): void => {
return eventUsers.map(evu => evu.member);
};

const checkEvents = async () => {
const guild = bot.getGuild();
if (!guild) return;
const eventList = await guild.scheduledEvents.fetch();
for (const { eventData, notificationChannel } of events) {
const existingEvent = eventList.find(event => event.name === eventData.name);
if (existingEvent) return;

// todo: figure out how to properly schedule this for multiple events, maybe just use cron afterall??
let nextDate = dayjs().day(6).hour(20).minute(0).second(0);
if (nextDate.isBefore(dayjs())) nextDate = nextDate.add(7, "days");

const event = await guild.scheduledEvents.create({
...eventData,
scheduledStartTime: nextDate.toDate(),
scheduledEndTime: nextDate.add(4, "hours").toDate(),
});

if (notificationChannel)
(guild.channels.cache.get(notificationChannel) as Discord.TextChannel).send(
event.url
);
}
};

bot.discord.on("ready", async () => {
await checkEvents();
});

bot.discord.on("guildScheduledEventDelete", async () => {
await checkEvents();
});

bot.discord.on("guildScheduledEventUpdate", async (_, now) => {
const event = now;

Expand Down Expand Up @@ -97,7 +53,6 @@ export default (bot: DiscordBot): void => {
usr.roles.remove(DiscordConfig.roles.event);
});
await event.guild?.setIcon(data.lastDiscordGuildIcon);
checkEvents();
break;
}
}
Expand Down

0 comments on commit 39677d0

Please sign in to comment.