2021-03-30 08:58:21 +00:00
|
|
|
import "./globals";
|
2021-01-29 19:14:31 +00:00
|
|
|
import * as discord from "discord.js";
|
2020-12-15 01:44:28 +00:00
|
|
|
import setup from "./setup";
|
|
|
|
import {Config} from "./core/structures";
|
|
|
|
import {loadEvents} from "./core/event";
|
|
|
|
import "discord.js-lavalink-lib";
|
|
|
|
import LavalinkMusic from "discord.js-lavalink-lib";
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2021-01-29 19:14:31 +00:00
|
|
|
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 = discord.Presence.prototype.patch;
|
|
|
|
discord.Presence.prototype.patch = function patch(data: any) {
|
|
|
|
oldPresencePatch.call(this, {status: data.status});
|
|
|
|
};
|
|
|
|
|
2020-07-25 11:01:24 +00:00
|
|
|
// This is here in order to make it much less of a headache to access the client from other files.
|
|
|
|
// This of course won't actually do anything until the setup process is complete and it logs in.
|
2021-01-29 19:14:31 +00:00
|
|
|
export const client = new discord.Client();
|
|
|
|
|
|
|
|
// 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 = () => {};
|
2020-07-25 11:01:24 +00:00
|
|
|
|
2020-10-20 19:10:03 +00:00
|
|
|
(client as any).music = LavalinkMusic(client, {
|
2020-12-15 01:44:28 +00:00
|
|
|
lavalink: {
|
|
|
|
restnode: {
|
|
|
|
host: "localhost",
|
|
|
|
port: 2333,
|
|
|
|
password: "youshallnotpass"
|
|
|
|
},
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
host: "localhost",
|
|
|
|
port: 2333,
|
|
|
|
password: "youshallnotpass"
|
|
|
|
}
|
|
|
|
]
|
2020-10-20 19:10:03 +00:00
|
|
|
},
|
2020-12-15 01:44:28 +00:00
|
|
|
prefix: "!!",
|
|
|
|
helpCmd: "mhelp",
|
|
|
|
admins: ["717352467280691331"]
|
2020-10-20 19:10:03 +00:00
|
|
|
});
|
|
|
|
|
2021-01-26 09:52:39 +00:00
|
|
|
// Command loading will start as soon as an instance of "core/command" is loaded, which is loaded during "events/message".
|
2020-07-25 11:01:24 +00:00
|
|
|
setup.init().then(() => {
|
2020-12-15 01:44:28 +00:00
|
|
|
loadEvents(client);
|
|
|
|
client.login(Config.token).catch(setup.again);
|
2020-10-15 09:23:24 +00:00
|
|
|
});
|