Skip to content

Commit

Permalink
set nickname on event and switch gamemode automatically (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Apr 23, 2024
1 parent ab7b549 commit 8101deb
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions app/services/discord/modules/discord-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ import { join } from "path";
import Discord from "discord.js";
import DiscordConfig from "@/config/discord.json";

const events = [
{
icon: "vr",
triggers: ["vrchat", "vr"],
},
{
icon: "ttt",
triggers: ["ttt"],
},
];
const iconsPath = join(process.cwd(), "resources/discord-event-icons");

export default (bot: DiscordBot): void => {
const events = [
{
icon: "vr",
triggers: ["vrchat", "vr"],
nicks: ["VR"],
},
{
icon: "ttt",
triggers: ["ttt"],
nicks: ["Terror", "Detective", "Innocent"],
execute: () =>
bot.container
.getService("GameBridge")
?.servers[3].sendLua(`require("gm_request"):SwitchGamemodeAsync("ttt",print)`),
},
];

const data = bot.container.getService("Data");
if (!data) return;

Expand All @@ -41,6 +48,7 @@ export default (bot: DiscordBot): void => {
});
await event.guild?.setIcon(data.lastDiscordGuildIcon);
await bot.discord.user?.setAvatar(data.lastDiscordGuildIcon);
await bot.setNickname(data.lastDiscordNickName, event.name + " ended");
};

bot.discord.on("guildScheduledEventUpdate", async (old, now) => {
Expand All @@ -54,7 +62,7 @@ export default (bot: DiscordBot): void => {
if (!usr.roles.cache.some(role => role.id === DiscordConfig.roles.event))
usr.roles.add(DiscordConfig.roles.event);
});
for (const { icon, triggers } of events) {
for (const { icon, triggers, nicks, execute } of events) {
const regex = new RegExp("\\b" + triggers.join("\\b|\\b") + "\\b");
const match =
regex.test(event.name.toLowerCase()) ||
Expand All @@ -65,6 +73,11 @@ export default (bot: DiscordBot): void => {
const path = join(iconsPath, `${icon}.png`);
await event.guild?.setIcon(path);
await bot.discord.user?.setAvatar(path);
await bot.setNickname(
nicks[(Math.random() * nicks.length) | 0],
event.name
);
if (execute) execute();
break;
}
}
Expand Down

0 comments on commit 8101deb

Please sign in to comment.