Made some minor changes to modules

This commit is contained in:
WatDuhHekBro 2021-03-31 02:00:03 -05:00
parent 974985586d
commit df3e4e8e6e
7 changed files with 41 additions and 36 deletions

View file

@ -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 {

View file

@ -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}`;

View file

@ -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";

View file

@ -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:
// <https://github.com/discordjs/discord.js/blob/cee6cf70ce76e9b06dc7f25bfd77498e18d7c8d4/src/structures/Presence.js#L81-L110>.
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
// <https://github.com/discordjs/discord.js/blob/cee6cf70ce76e9b06dc7f25bfd77498e18d7c8d4/src/client/actions/PresenceUpdate.js#L7-L41>.
(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",

30
src/modules/presence.ts Normal file
View file

@ -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:
// <https://github.com/discordjs/discord.js/blob/cee6cf70ce76e9b06dc7f25bfd77498e18d7c8d4/src/structures/Presence.js#L81-L110>.
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
// <https://github.com/discordjs/discord.js/blob/cee6cf70ce76e9b06dc7f25bfd77498e18d7c8d4/src/client/actions/PresenceUpdate.js#L7-L41>.
(client["actions"] as any)["PresenceUpdate"].handle = () => {};

View file

@ -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.