Fix message command counts

This commit is contained in:
Essem 2022-09-10 17:51:00 -05:00
parent f4ad285e74
commit 86f6811e6e
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
3 changed files with 22 additions and 14 deletions

View File

@ -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]);

View File

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

View File

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