2021-03-15 01:41:40 +00:00
|
|
|
const Eris = require("eris");
|
2021-08-22 20:20:49 +00:00
|
|
|
const logger = require("./lib/logger.js");
|
2021-03-15 01:41:40 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const {resolve} = require("path");
|
2021-07-23 23:21:50 +00:00
|
|
|
const sqlite3 = require("sqlite3");
|
2021-03-15 01:41:40 +00:00
|
|
|
|
|
|
|
const config = require("../config.json");
|
2021-06-11 03:54:38 +00:00
|
|
|
const apikeys = require("../apikeys.json");
|
2021-03-15 01:41:40 +00:00
|
|
|
const Command = require("./lib/command.js");
|
2021-05-17 22:35:18 +00:00
|
|
|
const events = require("./lib/events.js");
|
|
|
|
const timer = require("./lib/timer.js");
|
2021-03-15 01:41:40 +00:00
|
|
|
|
|
|
|
const bot = new Eris(config.token, {
|
|
|
|
defaultImageFormat: "png",
|
|
|
|
defaultImageSize: 1024,
|
2021-07-24 00:39:34 +00:00
|
|
|
intents: Object.keys(Eris.Constants.Intents).filter(
|
|
|
|
(x) => x != "guildMembers" && x != "guildPresences"
|
|
|
|
),
|
2021-03-15 01:41:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const commands = new Eris.Collection();
|
|
|
|
|
2021-07-24 00:39:34 +00:00
|
|
|
const database = new sqlite3.Database(resolve(__dirname, "..", "database.db"));
|
|
|
|
|
2021-03-15 01:41:40 +00:00
|
|
|
function registerCommand(cmdObj) {
|
|
|
|
if (cmdObj instanceof Command) {
|
|
|
|
commands.set(cmdObj.name, cmdObj);
|
|
|
|
const aliases = cmdObj.getAliases();
|
|
|
|
logger.info(
|
|
|
|
"hf:cmd",
|
2021-08-22 20:20:49 +00:00
|
|
|
`Registered command '${cmdObj.name}'${
|
|
|
|
aliases.length > 0 ? ` (aliases: ${aliases.join(", ")})` : ""
|
|
|
|
}`
|
2021-03-15 01:41:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
global.hf = {
|
|
|
|
bot,
|
|
|
|
config,
|
2021-06-11 03:54:38 +00:00
|
|
|
apikeys,
|
2021-03-15 01:41:40 +00:00
|
|
|
commands,
|
|
|
|
registerCommand,
|
2021-05-17 22:35:18 +00:00
|
|
|
events,
|
|
|
|
timer,
|
2021-07-24 00:39:34 +00:00
|
|
|
database,
|
2021-03-15 01:41:40 +00:00
|
|
|
};
|
|
|
|
|
2021-08-12 02:44:23 +00:00
|
|
|
const CommandDispatcher = require("./lib/commandDispatcher.js");
|
|
|
|
|
2021-03-15 01:41:40 +00:00
|
|
|
for (const file of fs.readdirSync(resolve(__dirname, "modules"))) {
|
|
|
|
require(resolve(__dirname, "modules", file));
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.info("hf:modules", `Loaded module: '${file}'`);
|
2021-03-15 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 04:48:43 +00:00
|
|
|
bot.on("messageCreate", async (msg) => {
|
2021-07-26 18:26:57 +00:00
|
|
|
// fix DMs cause of gateway v8 changes
|
2021-08-30 18:01:33 +00:00
|
|
|
if (
|
|
|
|
!(msg.channel instanceof Eris.Channel) &&
|
|
|
|
msg.author.id != bot.user.id &&
|
|
|
|
!msg.guildID
|
|
|
|
) {
|
2021-07-26 18:26:57 +00:00
|
|
|
const newChannel = await bot.getDMChannel(msg.author.id);
|
|
|
|
if (msg.channel.id == newChannel.id) msg.channel = newChannel;
|
2021-07-24 04:48:43 +00:00
|
|
|
}
|
2021-07-26 18:26:57 +00:00
|
|
|
|
|
|
|
if (!(msg.channel instanceof Eris.Channel)) return;
|
|
|
|
|
2021-07-24 04:48:43 +00:00
|
|
|
await CommandDispatcher(msg);
|
|
|
|
});
|
2021-03-15 01:41:40 +00:00
|
|
|
bot.on("messageUpdate", (msg) => {
|
|
|
|
const oneDay = Date.now() - 86400000;
|
|
|
|
if (msg.timestamp > oneDay && !msg.hasRan) {
|
|
|
|
CommandDispatcher(msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bot.on("ready", async () => {
|
|
|
|
logger.info("hf:main", "Connected to Discord.");
|
|
|
|
logger.info(
|
|
|
|
"hf:main",
|
2021-08-22 20:20:49 +00:00
|
|
|
`Logged in as: ${bot.user.username}#${bot.user.discriminator} (${bot.user.id})`
|
2021-03-15 01:41:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const channel = await bot.getDMChannel(config.owner_id);
|
|
|
|
if (channel) {
|
2021-07-23 22:21:24 +00:00
|
|
|
channel.createMessage("<:ms_tick:503341995348066313> Loaded HiddenPhox.");
|
2021-03-15 01:41:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-01 18:59:15 +00:00
|
|
|
bot.on("error", (err) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.error("hf:main", "Catching error: " + err);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
bot.on("warn", (err) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.warn("hf:main", "Catching warn: " + err);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
bot.on("shardDisconnect", (err, id) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.verbose("hf:shard", `Disconnecting from shard ${id}: ${err}`);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
bot.on("shardResume", (id) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.verbose("hf:shard", "Resuming on shard " + id);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
bot.on("shardPreReady", (id) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.verbose("hf:shard", `Shard ${id} getting ready`);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
bot.on("shardReady", (id) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.verbose("hf:shard", `Shard ${id} ready`);
|
2021-07-21 16:33:36 +00:00
|
|
|
});
|
|
|
|
bot.on("unknown", (packet, id) => {
|
2021-08-22 20:20:49 +00:00
|
|
|
logger.verbose(
|
|
|
|
"hf:main",
|
|
|
|
`Shard ${id} caught unknown packet: ${JSON.stringify(packet)}`
|
|
|
|
);
|
2021-06-01 18:59:15 +00:00
|
|
|
});
|
|
|
|
|
2021-03-15 01:41:40 +00:00
|
|
|
bot.connect();
|