diff --git a/src/index.js b/src/index.js index e48ccff..c158b33 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -const Eris = require("eris"); +const {Client, Collection} = require("oceanic.js"); const logger = require("./lib/logger.js"); const fs = require("fs"); const {resolve} = require("path"); @@ -10,13 +10,16 @@ const Command = require("./lib/command.js"); const events = require("./lib/events.js"); const timer = require("./lib/timer.js"); -const bot = new Eris(config.token, { +const bot = new Client({ + auth: config.token, defaultImageFormat: "png", defaultImageSize: 1024, - intents: Object.keys(Eris.Constants.Intents), + gateway: { + intents: ["ALL"], + }, }); -const commands = new Eris.Collection(); +const commands = new Collection(); const database = new sqlite3.Database(resolve(__dirname, "..", "database.db")); @@ -52,18 +55,6 @@ for (const file of fs.readdirSync(resolve(__dirname, "modules"))) { } bot.on("messageCreate", async (msg) => { - // fix DMs cause of gateway v8 changes - if ( - !(msg.channel instanceof Eris.Channel) && - msg.author.id != bot.user.id && - !msg.guildID - ) { - const newChannel = await bot.getDMChannel(msg.author.id); - if (msg.channel.id == newChannel.id) msg.channel = newChannel; - } - - if (!(msg.channel instanceof Eris.Channel)) return; - await CommandDispatcher(msg); }); bot.on("messageUpdate", (msg) => { @@ -73,17 +64,17 @@ bot.on("messageUpdate", (msg) => { } }); -bot.on("ready", async () => { +bot.once("ready", async () => { logger.info("hf:main", "Connected to Discord."); - logger.info( - "hf:main", - `Logged in as: ${bot.user.username}#${bot.user.discriminator} (${bot.user.id})` - ); + logger.info("hf:main", `Logged in as: ${bot.user.tag} (${bot.user.id})`); - const channel = await bot.getDMChannel(config.owner_id); + const channel = await bot.users.get(config.owner_id)?.createDM(); if (channel) { channel.createMessage("<:ms_tick:503341995348066313> Loaded HiddenPhox."); } + bot.on("ready", () => { + logger.info("hf:main", "Reconnected to Discord."); + }); }); bot.on("error", (err) => { diff --git a/src/lib/unicode.js b/src/lib/unicode.js index eea5d8b..a4db5b4 100644 --- a/src/lib/unicode.js +++ b/src/lib/unicode.js @@ -1,5 +1,3 @@ -const fetch = require("node-fetch"); - const mappings = {}; async function cacheList() { diff --git a/src/lib/utils.js b/src/lib/utils.js index 6cdab42..bee16b4 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -1,7 +1,6 @@ -const Eris = require("eris"); +const {Collection} = require("oceanic.js"); const murmurhash = require("murmurhash").v3; const {tinycolor} = require("@ctrl/tinycolor"); -const fetch = require("node-fetch"); function pastelize(id) { const hue = murmurhash(id) % 360; @@ -159,7 +158,7 @@ async function hastebin(body) { return ""; } -hf.selectionMessages = hf.selectionMessages || new Eris.Collection(); +hf.selectionMessages = hf.selectionMessages || new Collection(); async function selectionMessage( msg, heading, @@ -215,47 +214,45 @@ async function selectionMessage( return await new Promise((resolve, reject) => { function listener(interaction) { - if (interaction instanceof Eris.ComponentInteraction) { - const user = interaction.member.user || interaction.user; + const user = interaction.member.user || interaction.user; - if ( - user.id == msg.author.id && - interaction.channel.id == msg.channel.id && - interaction.message.components[0].components[0].custom_id == msg.id - ) { - if (interaction.data.custom_id == "cancel") { - hf.events.remove("interactionCreate", `selection.${msg.id}`); - clearTimeout(hf.selectionMessages.get(msg.id)); - hf.selectionMessages.remove(msg.id); + if ( + user.id == msg.author.id && + interaction.channel.id == msg.channel.id && + interaction.message.components[0].components[0].custom_id == msg.id + ) { + if (interaction.data.custom_id == "cancel") { + hf.events.remove("interactionCreate", `selection.${msg.id}`); + clearTimeout(hf.selectionMessages.get(msg.id)); + hf.selectionMessages.remove(msg.id); - interaction.deferUpdate(); + interaction.deferUpdate(); - displayMessage.delete(); + displayMessage.delete(); - reject("Canceled"); + reject("Canceled"); + } else { + hf.events.remove("interactionCreate", `selection.${msg.id}`); + clearTimeout(hf.selectionMessages.get(msg.id)); + hf.selectionMessages.remove(msg.id); + + interaction.deferUpdate(); + + displayMessage.delete(); + + let result; + + if (maxItems > 1) { + result = options + .filter((opt) => interaction.data.values.includes(opt.key)) + .map((opt) => opt.key); } else { - hf.events.remove("interactionCreate", `selection.${msg.id}`); - clearTimeout(hf.selectionMessages.get(msg.id)); - hf.selectionMessages.remove(msg.id); - - interaction.deferUpdate(); - - displayMessage.delete(); - - let result; - - if (maxItems > 1) { - result = options - .filter((opt) => interaction.data.values.includes(opt.key)) - .map((opt) => opt.key); - } else { - result = options.filter( - (opt) => opt.key == interaction.data.values[0] - )[0].value; - } - - resolve(result); + result = options.filter( + (opt) => opt.key == interaction.data.values[0] + )[0].value; } + + resolve(result); } } } diff --git a/src/modules/codePreviews.js b/src/modules/codePreviews.js index 0a21026..b689753 100644 --- a/src/modules/codePreviews.js +++ b/src/modules/codePreviews.js @@ -1,6 +1,5 @@ const events = require("../lib/events.js"); const {hasFlag} = require("../lib/guildSettings.js"); -const fetch = require("node-fetch"); const REGEX_GITHUB = /(?:\s|^)https?:\/\/(www\.)?github\.com\/.+?\/.+?\/blob\/([a-zA-Z0-9-_.#/]*)/g; diff --git a/src/modules/utsuholights.js b/src/modules/foxwells.js similarity index 98% rename from src/modules/utsuholights.js rename to src/modules/foxwells.js index 85cba40..e56e9f6 100644 --- a/src/modules/utsuholights.js +++ b/src/modules/foxwells.js @@ -1,7 +1,6 @@ const Command = require("../lib/command.js"); const CATEGORY = "misc"; -const fetch = require("node-fetch"); const {tinycolor} = require("@ctrl/tinycolor"); const logger = require("../lib/logger.js"); diff --git a/src/modules/misc.js b/src/modules/misc.js index 388619b..dd4d213 100644 --- a/src/modules/misc.js +++ b/src/modules/misc.js @@ -1,7 +1,6 @@ const Command = require("../lib/command.js"); const CATEGORY = "misc"; -const fetch = require("node-fetch"); const { hastebin, safeString, diff --git a/src/modules/music.js b/src/modules/music.js index 2103987..b6fe33b 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -1,6 +1,5 @@ -const fetch = require("node-fetch"); const ytdl = require("ytdl-core"); -const Eris = require("eris"); +const {Collection} = require("oceanic.js"); const ffprobe = require("node-ffprobe"); const Command = require("../lib/command.js"); @@ -19,7 +18,7 @@ const REGEX_FILE = let SOUNDCLOUD_CLIENTID; -hf.voiceStorage = hf.voiceStorage || new Eris.Collection(); +hf.voiceStorage = hf.voiceStorage || new Collection(); const voiceStorage = hf.voiceStorage; // https://stackoverflow.com/a/12646864 ยง "Updating to ES6 / ECMAScript 2015" diff --git a/src/modules/private_reminders.js b/src/modules/private_reminders.js index 6b85645..6ba7134 100644 --- a/src/modules/private_reminders.js +++ b/src/modules/private_reminders.js @@ -18,7 +18,6 @@ if (!fs.existsSync(resolve(__dirname, "..", "..", "private_reminders.json"))) return; const tzFormatterCache = {}; -const dmCache = {}; const reminderData = require(resolve( __dirname, @@ -82,9 +81,7 @@ hf.bot.once("ready", () => { }); } - if (!dmCache[data.user]) { - dmCache[data.user] = await hf.bot.getDMChannel(data.user); - } + const channel = await hf.bot.users.get(data.user)?.createDM(); const [date, time] = tzFormatterCache[data.tz] .format(Date.now()) @@ -94,8 +91,13 @@ hf.bot.once("ready", () => { minutes = parseInt(minutes); const lastRan = await getLastRun(data.user); - if (date != lastRan && hour == data.hour && minutes == 0) { - dmCache[data.user].createMessage(":alarm_clock: " + data.message); + if ( + date != lastRan && + hour == data.hour && + minutes == 0 && + channel != null + ) { + await channel.createMessage(":alarm_clock: " + data.message); await setLastRun(data.user, date); } } diff --git a/src/modules/utility.js b/src/modules/utility.js index ed2f79e..6aada23 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -57,7 +57,6 @@ EMOJI_SETS.fb = EMOJI_SETS.facebook; const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/; -const fetch = require("node-fetch"); const sharp = require("sharp"); const {hastebin, lookupUser} = require("../lib/utils.js");