From df3e4e8e6eaad6d0d1aeae2c05af8fb74277d0af Mon Sep 17 00:00:00 2001 From: WatDuhHekBro <44940783+WatDuhHekBro@users.noreply.github.com> Date: Wed, 31 Mar 2021 02:00:03 -0500 Subject: [PATCH] Made some minor changes to modules --- src/commands/system/admin.ts | 2 +- src/commands/system/help.ts | 2 ++ src/index.ts | 5 +++-- src/{ => modules}/globals.ts | 0 src/modules/lavalink.ts | 34 +++------------------------------- src/modules/presence.ts | 30 ++++++++++++++++++++++++++++++ src/{ => modules}/setup.ts | 4 ++-- 7 files changed, 41 insertions(+), 36 deletions(-) rename src/{ => modules}/globals.ts (100%) create mode 100644 src/modules/presence.ts rename src/{ => modules}/setup.ts (96%) diff --git a/src/commands/system/admin.ts b/src/commands/system/admin.ts index 15ab73d..8dae940 100644 --- a/src/commands/system/admin.ts +++ b/src/commands/system/admin.ts @@ -4,7 +4,7 @@ import {botHasPermission} from "../../core/libd"; import {Config, Storage} from "../../core/structures"; import {getPermissionLevel, getPermissionName} from "../../core/permissions"; import {Permissions} from "discord.js"; -import {logs} from "../../globals"; +import {logs} from "../../modules/globals"; function getLogBuffer(type: string) { return { diff --git a/src/commands/system/help.ts b/src/commands/system/help.ts index fdf1249..8ef9fe2 100644 --- a/src/commands/system/help.ts +++ b/src/commands/system/help.ts @@ -65,6 +65,8 @@ export default new Command({ command = command.get(param); permLevel = command.permission ?? permLevel; + if (permLevel === -1) permLevel = command.permission; + switch (type) { case Command.TYPES.SUBCOMMAND: header += ` ${command.originalCommandName}`; diff --git a/src/index.ts b/src/index.ts index 9f709e0..497c4f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ // Bootstrapping Section // -import "./globals"; +import "./modules/globals"; import {Client} from "discord.js"; -import setup from "./setup"; +import setup from "./modules/setup"; import {Config} from "./core/structures"; // This is here in order to make it much less of a headache to access the client from other files. @@ -15,6 +15,7 @@ setup.init().then(() => { // Initialize Modules // import "./core/handler"; // Command loading will start as soon as an instance of "core/command" is loaded, which is loaded in "core/handler". +import "./modules/presence"; import "./modules/lavalink"; import "./modules/emoteRegistry"; import "./modules/channelListener"; diff --git a/src/globals.ts b/src/modules/globals.ts similarity index 100% rename from src/globals.ts rename to src/modules/globals.ts diff --git a/src/modules/lavalink.ts b/src/modules/lavalink.ts index 39dc5c8..92d6ee9 100644 --- a/src/modules/lavalink.ts +++ b/src/modules/lavalink.ts @@ -1,37 +1,9 @@ -import {Presence} from "discord.js"; -import LavalinkMusic from "discord.js-lavalink-lib"; +import attachClientToLavalink from "discord.js-lavalink-lib"; import {Config} from "../core/structures"; import {client} from "../index"; -declare module "discord.js" { - interface Presence { - patch(data: any): void; - } -} - -// The terrible hacks were written by none other than The Noble Programmer On The White PC. - -// NOTE: Terrible hack ahead!!! In order to reduce the memory usage of the bot -// we only store the information from presences that we actually end up using, -// which currently is only the (online/idle/dnd/offline/...) status (see -// `src/commands/info.ts`). What data is retrieved from the `data` object -// (which contains the data received from the Gateway) and how can be seen -// here: -// . -const oldPresencePatch = Presence.prototype.patch; -Presence.prototype.patch = function patch(data: any) { - oldPresencePatch.call(this, {status: data.status}); -}; - -// NOTE: Terrible hack continued!!! Unfortunately we can't receive the presence -// data at all when the GUILD_PRESENCES intent is disabled, so while we do -// waste network bandwidth and the CPU time for decoding the incoming packets, -// the function which handles those packets is NOP-ed out, which, among other -// things, skips the code which caches the referenced users in the packet. See -// . -(client["actions"] as any)["PresenceUpdate"].handle = () => {}; - -(client as any).music = LavalinkMusic(client, { +// Although the example showed to do "client.music = LavaLink(...)" and "(client as any).music = Lavalink(...)" was done to match that, nowhere in the library is client.music ever actually used nor does the function return anything. In other words, client.music is undefined and is never used. +attachClientToLavalink(client, { lavalink: { restnode: { host: "localhost", diff --git a/src/modules/presence.ts b/src/modules/presence.ts new file mode 100644 index 0000000..50c5f64 --- /dev/null +++ b/src/modules/presence.ts @@ -0,0 +1,30 @@ +import {Presence} from "discord.js"; +import {client} from "../index"; + +declare module "discord.js" { + interface Presence { + patch(data: any): void; + } +} + +// The terrible hacks were written by none other than The Noble Programmer On The White PC. + +// NOTE: Terrible hack ahead!!! In order to reduce the memory usage of the bot +// we only store the information from presences that we actually end up using, +// which currently is only the (online/idle/dnd/offline/...) status (see +// `src/commands/info.ts`). What data is retrieved from the `data` object +// (which contains the data received from the Gateway) and how can be seen +// here: +// . +const oldPresencePatch = Presence.prototype.patch; +Presence.prototype.patch = function patch(data: any) { + oldPresencePatch.call(this, {status: data.status}); +}; + +// NOTE: Terrible hack continued!!! Unfortunately we can't receive the presence +// data at all when the GUILD_PRESENCES intent is disabled, so while we do +// waste network bandwidth and the CPU time for decoding the incoming packets, +// the function which handles those packets is NOP-ed out, which, among other +// things, skips the code which caches the referenced users in the packet. See +// . +(client["actions"] as any)["PresenceUpdate"].handle = () => {}; diff --git a/src/setup.ts b/src/modules/setup.ts similarity index 96% rename from src/setup.ts rename to src/modules/setup.ts index 97dc6e6..99ca135 100644 --- a/src/setup.ts +++ b/src/modules/setup.ts @@ -1,7 +1,7 @@ import {existsSync as exists, readFileSync as read, writeFile as write} from "fs"; import inquirer from "inquirer"; -import Storage, {generateHandler} from "./core/storage"; -import {Config} from "./core/structures"; +import Storage, {generateHandler} from "../core/storage"; +import {Config} from "../core/structures"; // The template should be built with a reductionist mentality. // Provide everything the user needs and then let them remove whatever they want.