From fe9a4f9d7ea194b3b97d987d332ea85b9838f1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=BA=E3=82=AD?= Date: Mon, 26 Apr 2021 13:16:37 +0200 Subject: [PATCH] Added command to set default VC name Co-authored-by: Lexi Sother --- package-lock.json | 14 +++++++------- src/commands/system/admin.ts | 21 +++++++++++++++++++++ src/index.ts | 1 + src/modules/channelDefaults.ts | 11 +++++++++++ src/structures.ts | 12 ++++++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/modules/channelDefaults.ts diff --git a/package-lock.json b/package-lock.json index 17d0ff9..68e4b12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "mathjs": "^9.3.0", "moment": "^2.29.1", "ms": "^2.1.3", - "onion-lasers": "^1.1.0", + "onion-lasers": "^1.1.1", "relevant-urban": "^2.0.0", "translate-google": "^1.4.3", "weather-js": "^2.0.0" @@ -5140,9 +5140,9 @@ } }, "node_modules/onion-lasers": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/onion-lasers/-/onion-lasers-1.1.1.tgz", - "integrity": "sha512-aX1jZtDMDjXN3N/k5Ca/6N3aQ1ozN6/1iylhbjB9u5xj97KcqhITx8jH5u2JEjUBZRQ3var9PuF1jNz/DrEgdQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/onion-lasers/-/onion-lasers-1.1.2.tgz", + "integrity": "sha512-gQHQCdcfDSLeWFFXMTBCy2PZR/n603B+Q2L3vTj+9T1CmJS7OfO7zoFM5QrTkOY4N5hESboOdJ8eRvPXQgdxDg==", "dependencies": { "discord.js": "^12.5.3", "glob": "^7.1.6" @@ -11845,9 +11845,9 @@ } }, "onion-lasers": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/onion-lasers/-/onion-lasers-1.1.1.tgz", - "integrity": "sha512-aX1jZtDMDjXN3N/k5Ca/6N3aQ1ozN6/1iylhbjB9u5xj97KcqhITx8jH5u2JEjUBZRQ3var9PuF1jNz/DrEgdQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/onion-lasers/-/onion-lasers-1.1.2.tgz", + "integrity": "sha512-gQHQCdcfDSLeWFFXMTBCy2PZR/n603B+Q2L3vTj+9T1CmJS7OfO7zoFM5QrTkOY4N5hESboOdJ8eRvPXQgdxDg==", "requires": { "discord.js": "^12.5.3", "glob": "^7.1.6" diff --git a/src/commands/system/admin.ts b/src/commands/system/admin.ts index 45ff624..ba953a7 100644 --- a/src/commands/system/admin.ts +++ b/src/commands/system/admin.ts @@ -204,6 +204,27 @@ export default new NamedCommand({ }) }) } + }), + name: new NamedCommand({ + aliases: ["defaultname"], + description: + "Sets the name that the channel will be reset to once no more members are in the channel.", + usage: "()", + run: "Please provide a new voice channel name.", + any: new RestCommand({ + async run({send, guild, message, combined}) { + const voiceChannel = message.member?.voice.channel; + const guildID = guild!.id; + const guildStorage = Storage.getGuild(guildID); + const newName = combined; + + if (!voiceChannel) return send("You are not in a voice channel."); + + guildStorage.channelNames[voiceChannel.id] = newName; + Storage.save(); + return await send(`Set default channel name to "${newName}".`); + } + }) }) } }), diff --git a/src/index.ts b/src/index.ts index 156aeb4..65e7d70 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,3 +74,4 @@ import "./modules/intercept"; import "./modules/messageEmbed"; import "./modules/guildMemberAdd"; import "./modules/streamNotifications"; +import "./modules/channelDefaults"; diff --git a/src/modules/channelDefaults.ts b/src/modules/channelDefaults.ts new file mode 100644 index 0000000..5fcb84a --- /dev/null +++ b/src/modules/channelDefaults.ts @@ -0,0 +1,11 @@ +import {client} from "../index"; +import {Storage} from "../structures"; + +client.on("voiceStateUpdate", async (before, after) => { + const channel = before.channel!; + const {channelNames} = Storage.getGuild(after.guild.id); + + if (channel?.members.size === 0 && channel?.id in channelNames) { + channel.setName(channelNames[channel.id]); + } +}); diff --git a/src/structures.ts b/src/structures.ts index 6da13a7..a9fbe0c 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -72,6 +72,7 @@ class Guild { public welcomeMessage: string | null; public streamingChannel: string | null; public streamingRoles: {[role: string]: string}; // Role ID: Category Name + public channelNames: {[channel: string]: string}; public members: {[id: string]: Member}; constructor(data?: GenericJSON) { @@ -80,6 +81,7 @@ class Guild { this.welcomeMessage = select(data?.welcomeMessage, null, String); this.streamingChannel = select(data?.streamingChannel, null, String); this.streamingRoles = {}; + this.channelNames = {}; this.members = {}; switch (data?.welcomeType) { @@ -104,6 +106,16 @@ class Guild { } } + if (data?.channelNames) { + for (const id in data.channelNames) { + const name = data.channelNames[id]; + + if (/\d{17,}/g.test(id) && typeof name === "string") { + this.channelNames[id] = name; + } + } + } + if (data?.members) { for (let id in data.members) { if (/\d{17,}/g.test(id)) {