mirror of
https://github.com/Burn-E99/TheArtificer.git
synced 2026-06-04 09:03:50 -04:00
Update to use Log4Deno dep
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage, hasGuildPermissions } from "../../deps.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, hasGuildPermissions,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import apiCommands from "./apiCmd/_apiIndex.ts";
|
||||
import utils from "../utils.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const api = async (message: DiscordenoMessage, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("api");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Local apiArg in lowercase
|
||||
@@ -17,7 +21,7 @@ export const api = async (message: DiscordenoMessage, args: string[]) => {
|
||||
// Alert users who DM the bot that this command is for guilds only
|
||||
if (message.guildId === 0n) {
|
||||
message.send(constantCmds.apiGuildOnly).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -49,7 +53,7 @@ export const api = async (message: DiscordenoMessage, args: string[]) => {
|
||||
}
|
||||
} else {
|
||||
message.send(constantCmds.apiPermError).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { DiscordenoMessage } from "../../../deps.ts";
|
||||
import utils from "../../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { generateApiFailed, generateApiSuccess } from "../../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../../utils.enums.ts";
|
||||
|
||||
export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
const guildQuery = await dbClient.query(`SELECT guildid FROM allowed_guilds WHERE guildid = ?`, [message.guildId]).catch(e0 => {
|
||||
utils.log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
@@ -16,24 +20,24 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
||||
if (guildQuery.length === 0) {
|
||||
// Since guild is not in our DB, add it in
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,active) values(?,?)`, [BigInt(message.guildId), ((apiArg === "allow" || apiArg === "enable") ? 1 : 0)]).catch(e0 => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
// Since guild is in our DB, update it
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET active = ? WHERE guildid = ?`, [((apiArg === "allow" || apiArg === "enable") ? 1 : 0), BigInt(message.guildId)]).catch(e0 => {
|
||||
utils.log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
}
|
||||
// We won't get here if there's any errors, so we know it has bee successful, so report as such
|
||||
message.send(generateApiSuccess(apiArg)).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { DiscordenoMessage } from "../../../deps.ts";
|
||||
import utils from "../../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds } from "../../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../../utils.enums.ts";
|
||||
|
||||
export const help = (message: DiscordenoMessage) => {
|
||||
message.send(constantCmds.apiHelp).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { DiscordenoMessage } from "../../../deps.ts";
|
||||
import utils from "../../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds } from "../../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../../utils.enums.ts";
|
||||
|
||||
export const deleteGuild = async (message: DiscordenoMessage) => {
|
||||
await dbClient.execute(`DELETE FROM allowed_guilds WHERE guildid = ?`, [message.guildId]).catch(e0 => {
|
||||
utils.log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(constantCmds.apiDeleteFail).catch(e1 => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
|
||||
// We won't get here if there's any errors, so we know it has bee successful, so report as such
|
||||
message.send(constantCmds.apiRemoveGuild).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { DiscordenoMessage } from "../../../deps.ts";
|
||||
import utils from "../../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds, generateApiStatus } from "../../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../../utils.enums.ts";
|
||||
|
||||
export const status = async (message: DiscordenoMessage) => {
|
||||
// Get status of guild from the db
|
||||
const guildQuery = await dbClient.query(`SELECT active, banned FROM allowed_guilds WHERE guildid = ?`, [message.guildId]).catch(e0 => {
|
||||
utils.log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(constantCmds.apiStatusFail).catch(e1 => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
@@ -19,17 +23,17 @@ export const status = async (message: DiscordenoMessage) => {
|
||||
// Check if guild is banned from using API and return appropriate message
|
||||
if (guildQuery[0].banned) {
|
||||
message.send(generateApiStatus(true, false)).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
} else {
|
||||
message.send(generateApiStatus(false, guildQuery[0].active)).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Guild is not in DB, therefore they are blocked
|
||||
message.send(generateApiStatus(false, false)).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import config from "../../config.ts";
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { EmojiConf } from "../mod.d.ts";
|
||||
|
||||
const allEmojiAliases: string[] = [];
|
||||
@@ -16,22 +20,22 @@ export const emoji = (message: DiscordenoMessage, command: string) => {
|
||||
if (allEmojiAliases.indexOf(command)) {
|
||||
// Start looping thru the possible emojis
|
||||
config.emojis.some((emoji: EmojiConf) => {
|
||||
utils.log(LT.LOG, `Checking if command was emoji ${JSON.stringify(emoji)}`);
|
||||
log(LT.LOG, `Checking if command was emoji ${JSON.stringify(emoji)}`);
|
||||
// If a match gets found
|
||||
if (emoji.aliases.indexOf(command || "") > -1) {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("emojis");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Send the needed emoji1
|
||||
message.send(`<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
// And attempt to delete if needed
|
||||
if (emoji.deleteSender) {
|
||||
message.delete().catch(e => {
|
||||
utils.log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const help = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("help");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.help).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const info = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("info");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.info).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { generatePing } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const ping = async (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("ping");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Calculates ping between sending a message and editing it, giving a nice round-trip latency.
|
||||
@@ -15,6 +19,6 @@ export const ping = async (message: DiscordenoMessage) => {
|
||||
const m = await message.send(generatePing(-1));
|
||||
m.edit(generatePing(m.timestamp - message.timestamp));
|
||||
} catch (e) {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const privacy = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("privacy");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.privacy).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
import config from "../../config.ts";
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage, sendMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, sendMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds, generateReport } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const report = (message: DiscordenoMessage, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("report");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
if (args.join(" ")) {
|
||||
sendMessage(config.reportChannel, generateReport(args.join(" "))).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
message.send(constantCmds.report).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
} else {
|
||||
message.send(constantCmds.reportFail).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const rip = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("rip");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.rip).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
import config from "../../config.ts";
|
||||
import { DEVMODE } from "../../flags.ts";
|
||||
import { dbClient, queries } from "../db.ts";
|
||||
import { DiscordenoMessage, sendDirectMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, sendDirectMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import solver from "../solver.ts";
|
||||
import { constantCmds, generateDMFailed } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
import rollFuncs from "./roll/_rollIndex.ts";
|
||||
|
||||
export const roll = async (message: DiscordenoMessage, args: string[], command: string) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("roll");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// If DEVMODE is on, only allow this command to be used in the devServer
|
||||
if (DEVMODE && message.guildId !== config.devServer) {
|
||||
message.send(constantCmds.indev).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -50,7 +54,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, returnmsg.errorCode, m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return;
|
||||
@@ -72,7 +76,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
// And message the full details to each of the GMs, alerting roller of every GM that could not be messaged
|
||||
modifiers.gms.forEach(async e => {
|
||||
utils.log(LT.LOG, `Messaging GM ${e}`);
|
||||
log(LT.LOG, `Messaging GM ${e}`);
|
||||
// If its too big, collapse it into a .txt file and send that instead.
|
||||
const b = await new Blob([returnText as BlobPart], { "type": "text" });
|
||||
|
||||
@@ -103,7 +107,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -136,11 +140,11 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
utils.log(LT.ERROR, `Undandled Error: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Undandled Error: ${JSON.stringify(e)}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import config from "../../../config.ts";
|
||||
import { DEVMODE } from "../../../flags.ts";
|
||||
import { dbClient, queries } from "../../db.ts";
|
||||
import { DiscordenoMessage } from "../../../deps.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { generateRollError } from "../../constantCmds.ts";
|
||||
import utils from "../../utils.ts";
|
||||
import { LogTypes as LT } from "../../utils.enums.ts";
|
||||
import { RollModifiers } from "../../mod.d.ts";
|
||||
|
||||
export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => {
|
||||
@@ -22,7 +26,7 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
|
||||
// Check if any of the args are command flags and pull those out into the modifiers object
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
utils.log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`);
|
||||
log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`);
|
||||
switch (args[i].toLowerCase()) {
|
||||
case "-nd":
|
||||
modifiers.noDetails = true;
|
||||
@@ -53,7 +57,7 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
|
||||
// -gm is a little more complex, as we must get all of the GMs that need to be DMd
|
||||
while (((i + 1) < args.length) && args[i + 1].startsWith("<@")) {
|
||||
utils.log(LT.LOG, `Finding all GMs, checking args ${JSON.stringify(args)}`);
|
||||
log(LT.LOG, `Finding all GMs, checking args ${JSON.stringify(args)}`);
|
||||
// Keep looping thru the rest of the args until one does not start with the discord mention code
|
||||
modifiers.gms.push(args[i + 1].replace(/[!]/g, ""));
|
||||
args.splice((i + 1), 1);
|
||||
@@ -65,7 +69,7 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "NoGMsFound", m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return modifiers;
|
||||
@@ -86,7 +90,7 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "NoOrderFound", m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return modifiers;
|
||||
@@ -109,7 +113,7 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "MaxAndNominal", m.id]).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return modifiers;
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const rollHelp = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("rollhelp");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.rollHelp).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { cache, cacheHandlers, DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
cache, cacheHandlers, DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { generateStats } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const stats = async (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("stats");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Calculate how many times commands have been run
|
||||
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const rolls = BigInt(rollQuery[0].count);
|
||||
const total = BigInt(totalQuery[0].count);
|
||||
@@ -24,6 +28,6 @@ export const stats = async (message: DiscordenoMessage) => {
|
||||
const cachedChannels = await cacheHandlers.size("channels");
|
||||
const cachedMembers = await cacheHandlers.size("members");
|
||||
message.send(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { DiscordenoMessage } from "../../deps.ts";
|
||||
import utils from "../utils.ts";
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
import { LogTypes as LT } from "../utils.enums.ts";
|
||||
|
||||
export const version = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("version");`).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.version).catch(e => {
|
||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user