From 86f6811e6e9cea7d762072508cbd55014ba4bef8 Mon Sep 17 00:00:00 2001 From: Essem Date: Sat, 10 Sep 2022 17:51:00 -0500 Subject: [PATCH] Fix message command counts --- utils/database/postgresql.js | 8 +++++--- utils/database/sqlite.js | 6 ++++-- utils/imagedetect.js | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/utils/database/postgresql.js b/utils/database/postgresql.js index 33a84d4..1d108ed 100644 --- a/utils/database/postgresql.js +++ b/utils/database/postgresql.js @@ -1,4 +1,4 @@ -import { prefixCache, disabledCmdCache, disabledCache, commands } from "../collections.js"; +import { prefixCache, disabledCmdCache, disabledCache, commands, messageCommands } from "../collections.js"; import * as logger from "../logger.js"; import Postgres from "pg"; @@ -21,13 +21,15 @@ export async function setup() { counts = { rows: [] }; } + const merged = new Map([...commands, ...messageCommands]); + if (!counts.rows[0]) { - for (const command of commands.keys()) { + for (const command of merged.keys()) { await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]); } } else { const exists = []; - for (const command of commands.keys()) { + for (const command of merged.keys()) { const count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]); if (!count.rows[0]) { await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]); diff --git a/utils/database/sqlite.js b/utils/database/sqlite.js index 4bcff28..9d24417 100644 --- a/utils/database/sqlite.js +++ b/utils/database/sqlite.js @@ -12,13 +12,15 @@ const sqliteUpdates = [ export async function setup() { const counts = connection.prepare("SELECT * FROM counts").all(); + const merged = new Map([...collections.commands, ...collections.messageCommands]); + if (!counts) { - for (const command of collections.commands.keys()) { + for (const command of merged.keys()) { connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0); } } else { const exists = []; - for (const command of collections.commands.keys()) { + for (const command of merged.keys()) { const count = connection.prepare("SELECT * FROM counts WHERE command = ?").get(command); if (!count) { connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0); diff --git a/utils/imagedetect.js b/utils/imagedetect.js index d9868e2..4857a79 100644 --- a/utils/imagedetect.js +++ b/utils/imagedetect.js @@ -170,15 +170,19 @@ export default async (client, cmdMessage, interaction, options, extraReturnTypes } if (!singleMessage) { // if there aren't any replies or interaction attachments then iterate over the last few messages in the channel - const messages = await client.getMessages((interaction ? interaction : cmdMessage).channel.id); - // iterate over each message - for (const message of messages) { - const result = await checkImages(message, extraReturnTypes, video, sticker); - if (result === false) { - continue; - } else { - return result; - } + try { + const messages = await client.getMessages((interaction ? interaction : cmdMessage).channel.id); + // iterate over each message + for (const message of messages) { + const result = await checkImages(message, extraReturnTypes, video, sticker); + if (result === false) { + continue; + } else { + return result; + } + } + } catch { + // no-op } } };