Fix message command counts
This commit is contained in:
parent
f4ad285e74
commit
86f6811e6e
3 changed files with 22 additions and 14 deletions
|
@ -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 * as logger from "../logger.js";
|
||||||
|
|
||||||
import Postgres from "pg";
|
import Postgres from "pg";
|
||||||
|
@ -21,13 +21,15 @@ export async function setup() {
|
||||||
counts = { rows: [] };
|
counts = { rows: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const merged = new Map([...commands, ...messageCommands]);
|
||||||
|
|
||||||
if (!counts.rows[0]) {
|
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]);
|
await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const exists = [];
|
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]);
|
const count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]);
|
||||||
if (!count.rows[0]) {
|
if (!count.rows[0]) {
|
||||||
await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
|
await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
|
||||||
|
|
|
@ -12,13 +12,15 @@ const sqliteUpdates = [
|
||||||
|
|
||||||
export async function setup() {
|
export async function setup() {
|
||||||
const counts = connection.prepare("SELECT * FROM counts").all();
|
const counts = connection.prepare("SELECT * FROM counts").all();
|
||||||
|
const merged = new Map([...collections.commands, ...collections.messageCommands]);
|
||||||
|
|
||||||
if (!counts) {
|
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);
|
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const exists = [];
|
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);
|
const count = connection.prepare("SELECT * FROM counts WHERE command = ?").get(command);
|
||||||
if (!count) {
|
if (!count) {
|
||||||
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0);
|
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0);
|
||||||
|
|
|
@ -170,15 +170,19 @@ export default async (client, cmdMessage, interaction, options, extraReturnTypes
|
||||||
}
|
}
|
||||||
if (!singleMessage) {
|
if (!singleMessage) {
|
||||||
// if there aren't any replies or interaction attachments then iterate over the last few messages in the channel
|
// 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);
|
try {
|
||||||
// iterate over each message
|
const messages = await client.getMessages((interaction ? interaction : cmdMessage).channel.id);
|
||||||
for (const message of messages) {
|
// iterate over each message
|
||||||
const result = await checkImages(message, extraReturnTypes, video, sticker);
|
for (const message of messages) {
|
||||||
if (result === false) {
|
const result = await checkImages(message, extraReturnTypes, video, sticker);
|
||||||
continue;
|
if (result === false) {
|
||||||
} else {
|
continue;
|
||||||
return result;
|
} else {
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// no-op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue