added db error message log, added edit message log
This commit is contained in:
parent
57518f75a9
commit
d769ac0e5a
4
mod.ts
4
mod.ts
|
@ -97,9 +97,7 @@ startBot({
|
|||
guildDelete: (guild: DiscordenoGuild) => {
|
||||
log(LT.LOG, `Handling leaving guild ${JSON.stringify(guild)}`);
|
||||
sendMessage(config.logChannel, `I have been removed from: ${guild.name} (id: ${guild.id}).`).catch((e: Error) => utils.commonLoggers.messageSendError('mod.ts:99', 'Leave Guild', e));
|
||||
dbClient.execute('DELETE FROM allowed_guilds WHERE guildid = ? AND banned = 0', [guild.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to DELETE guild from DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute('DELETE FROM allowed_guilds WHERE guildid = ? AND banned = 0', [guild.id]).catch((e) => utils.commonLoggers.dbError('mod.ts:100', 'delete from', e));
|
||||
},
|
||||
debug: DEVMODE ? (dmsg) => log(LT.LOG, `Debug Message | ${JSON.stringify(dmsg)}`) : undefined,
|
||||
messageCreate: (message: DiscordenoMessage) => {
|
||||
|
|
|
@ -13,9 +13,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("api");`).catch((e) => utils.commonLoggers.dbError('apiCmd.ts:16', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Local apiArg in lowercase
|
||||
const apiArg = (args[0] || 'help').toLowerCase();
|
||||
|
|
|
@ -12,7 +12,7 @@ import utils from '../../utils.ts';
|
|||
export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
let errorOutInitial = false;
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('allowBlock.ts:15', 'query', e0)
|
||||
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:16', message, e));
|
||||
errorOutInitial = true;
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
|||
// Since guild is not in our DB, add it in
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,channelid,active) values(?,?,?)`, [message.guildId, message.channelId, (apiArg === 'allow' || apiArg === 'enable') ? 1 : 0]).catch(
|
||||
(e0) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('allowBlock:26', 'insert into', e0)
|
||||
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:27', message, e));
|
||||
errorOut = true;
|
||||
},
|
||||
|
@ -32,7 +32,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
|||
// Since guild is in our DB, update it
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET active = ? WHERE guildid = ? AND channelid = ?`, [(apiArg === 'allow' || apiArg === 'enable') ? 1 : 0, message.guildId, message.channelId]).catch(
|
||||
(e0) => {
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('allowBlock.ts:35', 'update', e0)
|
||||
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:36', message, e));
|
||||
errorOut = true;
|
||||
},
|
||||
|
|
|
@ -12,7 +12,7 @@ import utils from '../../utils.ts';
|
|||
export const deleteGuild = async (message: DiscordenoMessage) => {
|
||||
let errorOut = false;
|
||||
await dbClient.execute(`DELETE FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('deleteGuild.ts:15', 'query', e0)
|
||||
message.send({
|
||||
embeds: [{
|
||||
color: failColor,
|
||||
|
|
|
@ -12,7 +12,7 @@ import utils from '../../utils.ts';
|
|||
export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
let errorOutInitial = false;
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('showHideWarn.ts:15', 'query', e0);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:16', message, e));
|
||||
errorOutInitial = true;
|
||||
});
|
||||
|
@ -22,14 +22,14 @@ export const showHideWarn = 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,channelid,hidewarn) values(?,?,?)`, [message.guildId, message.channelId, (apiArg === 'hide-warn') ? 1 : 0]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('showHideWarn.ts:25', 'insert inot', e0);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:26', message, e));
|
||||
errorOut = true;
|
||||
});
|
||||
} else {
|
||||
// Since guild is in our DB, update it
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET hidewarn = ? WHERE guildid = ? AND channelid = ?`, [(apiArg === 'hide-warn') ? 1 : 0, message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('showHideWarn.ts:32', 'update', e0);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:33', message, e));
|
||||
errorOut = true;
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ export const status = async (message: DiscordenoMessage) => {
|
|||
// Get status of guild from the db
|
||||
let errorOut = false;
|
||||
const guildQuery = await dbClient.query(`SELECT active, banned FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
utils.commonLoggers.dbError('status.ts:16', 'query', e0);
|
||||
message.send({
|
||||
embeds: [{
|
||||
color: failColor,
|
||||
|
|
|
@ -13,9 +13,7 @@ import utils from '../utils.ts';
|
|||
|
||||
export const audit = async (message: DiscordenoMessage, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("audit");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("audit");`).catch((e) => utils.commonLoggers.dbError('audit.ts:16', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Local apiArg in lowercase
|
||||
const auditArg = (args[0] || 'help').toLowerCase();
|
||||
|
|
|
@ -16,9 +16,7 @@ export const auditDB = async (message: DiscordenoMessage) => {
|
|||
const m = await message.send(compilingStats);
|
||||
|
||||
// Get DB statistics
|
||||
const auditQuery = await dbClient.query(`SELECT * FROM db_size;`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const auditQuery = await dbClient.query(`SELECT * FROM db_size;`).catch((e) => utils.commonLoggers.dbError('auditDB.ts:19', 'query', e));
|
||||
|
||||
// Turn all tables into embed fields, currently only properly will handle 25 tables, but we'll fix that when artificer gets 26 tables
|
||||
const embedFields: Array<EmbedField> = [];
|
||||
|
|
|
@ -25,9 +25,7 @@ export const emoji = (message: DiscordenoMessage, command: string) => {
|
|||
// If a match gets found
|
||||
if (emji.aliases.indexOf(command || '') > -1) {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("emojis");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("emojis");`).catch((e) => utils.commonLoggers.dbError('emojis.ts:28', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Send the needed emoji
|
||||
message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e: Error) => utils.commonLoggers.messageSendError('emoji.ts:33', message, e));
|
||||
|
|
|
@ -14,9 +14,7 @@ export const handleMentions = (message: DiscordenoMessage) => {
|
|||
log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`);
|
||||
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("mention");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("mention");`).catch((e) => utils.commonLoggers.dbError('handleMentions.ts:17', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -12,9 +12,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("help");`).catch((e) => utils.commonLoggers.dbError('htlp.ts:15', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -11,9 +11,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("info");`).catch((e) => utils.commonLoggers.dbError('info.ts:14', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -11,9 +11,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("ping");`).catch((e) => utils.commonLoggers.dbError('ping.ts:14', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Calculates ping between sending a message and editing it, giving a nice round-trip latency.
|
||||
try {
|
||||
|
|
|
@ -12,9 +12,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("privacy");`).catch((e) => utils.commonLoggers.dbError('privacy.ts:15', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -14,9 +14,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("report");`).catch((e) => utils.commonLoggers.dbError('report.ts:17', 'call sproc INC_CNT on', e));
|
||||
|
||||
if (args.join(' ')) {
|
||||
sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e));
|
||||
|
|
|
@ -11,9 +11,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("rip");`).catch((e) => utils.commonLoggers.dbError('rip.ts:14', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -16,9 +16,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("roll");`).catch((e) => utils.commonLoggers.dbError('roll.ts:19', 'call sproc INC_CNT on', e));
|
||||
|
||||
// If DEVMODE is on, only allow this command to be used in the devServer
|
||||
if (DEVMODE && message.guildId !== config.devServer) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
} from '../../../deps.ts';
|
||||
import { generateRollError } from '../../commandUtils.ts';
|
||||
import { RollModifiers } from '../../mod.d.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => {
|
||||
const errorType = 'Modifiers invalid:';
|
||||
|
@ -62,15 +63,11 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
|||
}
|
||||
if (modifiers.gms.length < 1) {
|
||||
// If -gm is on and none were found, throw an error
|
||||
m.edit(generateRollError(errorType, 'Must specifiy at least one GM by @mentioning them')).catch((e) => {
|
||||
log(LT.ERROR, `Failed to edit message: ${JSON.stringify(m)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
m.edit(generateRollError(errorType, 'Must specifiy at least one GM by @mentioning them')).catch((e) => utils.commonLoggers.messageEditError('getModifiers.ts:66', m, e));
|
||||
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'NoGMsFound', m.id]).catch((e) => utils.commonLoggers.dbError('getModifiers.ts:72', 'insert into', e));
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
@ -81,15 +78,11 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
|||
|
||||
if (!args[i] || args[i].toLowerCase()[0] !== 'd' && args[i].toLowerCase()[0] !== 'a') {
|
||||
// If -o is on and asc or desc was not specified, error out
|
||||
m.edit(generateRollError(errorType, 'Must specifiy `a` or `d` to order the rolls ascending or descending')).catch((e) => {
|
||||
log(LT.ERROR, `Failed to edit message: ${JSON.stringify(m)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
m.edit(generateRollError(errorType, 'Must specifiy `a` or `d` to order the rolls ascending or descending')).catch((e) => utils.commonLoggers.messageEditError('getModifiers.ts:81', m, e));
|
||||
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'NoOrderFound', m.id]).catch((e) => utils.commonLoggers.dbError('getModifiers.ts:89', 'insert into', e));
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
@ -110,15 +103,11 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
|||
|
||||
// maxRoll and nominalRoll cannot both be on, throw an error
|
||||
if (modifiers.maxRoll && modifiers.nominalRoll) {
|
||||
m.edit(generateRollError(errorType, 'Cannot maximise and nominise the roll at the same time')).catch((e) => {
|
||||
log(LT.ERROR, `Failed to edit message: ${JSON.stringify(m)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
m.edit(generateRollError(errorType, 'Cannot maximise and nominise the roll at the same time')).catch((e) => utils.commonLoggers.messageEditError('getModifiers.ts:106', m, e));
|
||||
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'MaxAndNominal', m.id]).catch((e) => utils.commonLoggers.dbError('getModifiers.ts:120', 'insert into', e));
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
|
|
@ -12,9 +12,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("rollhelp");`).catch((e) => utils.commonLoggers.dbError('rollHelp.ts:15', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [
|
||||
|
|
|
@ -14,20 +14,14 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("stats");`).catch((e) => utils.commonLoggers.dbError('stats.ts', 'call sproc INC_CNT on', e));
|
||||
|
||||
try {
|
||||
const m = await message.send(compilingStats);
|
||||
|
||||
// Calculate how many times commands have been run
|
||||
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch((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) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch((e) => utils.commonLoggers.dbError('stats.ts:23', 'query', e));
|
||||
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch((e) => utils.commonLoggers.dbError('stats.ts:24', 'query', e));
|
||||
const rolls = BigInt(rollQuery[0].count);
|
||||
const total = BigInt(totalQuery[0].count);
|
||||
|
||||
|
|
|
@ -12,9 +12,7 @@ import utils from '../utils.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) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(`CALL INC_CNT("version");`).catch((e) => utils.commonLoggers.dbError('version.ts:15', 'call sproc INC_CNT on', e));
|
||||
|
||||
message.send({
|
||||
embeds: [{
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
sendMessage,
|
||||
} from '../../../deps.ts';
|
||||
import { generateApiDeleteEmail } from '../../commandUtils.ts';
|
||||
import utils from '../../utils.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
|
||||
export const apiKeyDelete = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt, apiUserEmail: string, apiUserDelCode: string) => {
|
||||
|
@ -21,7 +22,7 @@ export const apiKeyDelete = async (requestEvent: Deno.RequestEvent, query: Map<s
|
|||
let erroredOut = false;
|
||||
|
||||
await dbClient.execute('DELETE FROM allowed_channels WHERE userid = ?', [apiUserid]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKeyDelete.ts:25', 'insert into', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Channel Clean Failed.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
@ -30,7 +31,7 @@ export const apiKeyDelete = async (requestEvent: Deno.RequestEvent, query: Map<s
|
|||
}
|
||||
|
||||
await dbClient.execute('DELETE FROM all_keys WHERE userid = ?', [apiUserid]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKeyDelete.ts:34', 'delete from', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Delete Key Failed.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
@ -53,7 +54,7 @@ export const apiKeyDelete = async (requestEvent: Deno.RequestEvent, query: Map<s
|
|||
|
||||
// Execute the DB modification
|
||||
await dbClient.execute('UPDATE all_keys SET deleteCode = ? WHERE userid = ?', [deleteCode, apiUserid]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKeyDelete.ts:57', 'update', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Delete Code Failed'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiChannel = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt) => {
|
||||
if (query.has('user') && ((query.get('user') || '').length > 0)) {
|
||||
|
@ -14,7 +15,7 @@ export const apiChannel = async (requestEvent: Deno.RequestEvent, query: Map<str
|
|||
|
||||
// Get all channels userid has authorized
|
||||
const dbAllowedChannelQuery = await dbClient.query('SELECT * FROM allowed_channels WHERE userid = ?', [apiUserid]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiChannel.ts', 'query', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to get channels.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
sendMessage,
|
||||
} from '../../../deps.ts';
|
||||
import { generateApiKeyEmail } from '../../commandUtils.ts';
|
||||
import utils from '../../utils.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
|
||||
export const apiKey = async (requestEvent: Deno.RequestEvent, query: Map<string, string>) => {
|
||||
|
@ -23,7 +24,7 @@ export const apiKey = async (requestEvent: Deno.RequestEvent, query: Map<string,
|
|||
// Insert new key/user pair into the db
|
||||
await dbClient.execute('INSERT INTO all_keys(userid,apiKey,email) values(?,?,?)', [BigInt(query.get('user') || '0'), newKey, (query.get('email') || '').toLowerCase()]).catch(
|
||||
(e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKey.ts:27', 'insert into', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to store key.'));
|
||||
erroredOut = true;
|
||||
},
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
nanoid,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiKeyAdmin = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt) => {
|
||||
if ((query.has('user') && ((query.get('user') || '').length > 0)) && (query.has('a') && ((query.get('a') || '').length > 0))) {
|
||||
|
@ -20,7 +21,7 @@ export const apiKeyAdmin = async (requestEvent: Deno.RequestEvent, query: Map<st
|
|||
|
||||
// Insert new key/user pair into the db
|
||||
await dbClient.execute('INSERT INTO all_keys(userid,apiKey) values(?,?)', [apiUserid, newKey]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKeyAdmin.ts:24', 'insert into', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to store key.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { QueuedRoll, RollModifiers } from '../../mod.d.ts';
|
||||
import utils from '../../utils.ts';
|
||||
import { queueRoll } from '../../solver/rollQueue.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
|
||||
|
@ -60,9 +61,7 @@ export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map<string
|
|||
requestEvent.respondWith(stdResp.BadRequest('rollCmd is required.'));
|
||||
|
||||
// Always log API rolls for abuse detection
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 1), [originalCommand, 'EmptyInput', null]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 1), [originalCommand, 'EmptyInput', null]).catch((e) => utils.commonLoggers.dbError('apiRoll.ts:65', 'insert', e));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,9 +70,7 @@ export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map<string
|
|||
requestEvent.respondWith(stdResp.BadRequest('Order must be set to \'a\' or \'d\'.'));
|
||||
|
||||
// Always log API rolls for abuse detection
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 1), [originalCommand, 'BadOrder', null]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 1), [originalCommand, 'BadOrder', null]).catch((e) => utils.commonLoggers.dbError('apiRoll.ts:66', 'insert', e));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiChannelAdd = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt) => {
|
||||
if ((query.has('user') && ((query.get('user') || '').length > 0)) && (query.has('channel') && ((query.get('channel') || '').length > 0))) {
|
||||
|
@ -14,7 +15,7 @@ export const apiChannelAdd = async (requestEvent: Deno.RequestEvent, query: Map<
|
|||
|
||||
// Insert new user/channel pair into the db
|
||||
await dbClient.execute('INSERT INTO allowed_channels(userid,channelid) values(?,?)', [apiUserid, BigInt(query.get('channel') || '0')]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiChannelAdd.ts:17', 'insert into', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to store channel.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiChannelManageActive = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt, path: string) => {
|
||||
if ((query.has('channel') && ((query.get('channel') || '').length > 0)) && (query.has('user') && ((query.get('user') || '').length > 0))) {
|
||||
|
@ -21,7 +22,7 @@ export const apiChannelManageActive = async (requestEvent: Deno.RequestEvent, qu
|
|||
|
||||
// Update the requested entry
|
||||
await dbClient.execute('UPDATE allowed_channels SET active = ? WHERE userid = ? AND channelid = ?', [value, apiUserid, BigInt(query.get('channel') || '0')]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiChannelManageActive.ts:25', 'update', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to update channel.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiChannelManageBan = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt, path: string) => {
|
||||
if (
|
||||
|
@ -25,7 +26,7 @@ export const apiChannelManageBan = async (requestEvent: Deno.RequestEvent, query
|
|||
|
||||
// Execute the DB modification
|
||||
await dbClient.execute('UPDATE allowed_channels SET banned = ? WHERE userid = ? AND channelid = ?', [value, apiUserid, BigInt(query.get('channel') || '0')]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiChannelManageBan.ts:28', 'update', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError('Failed to update channel.'));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import stdResp from '../stdResponses.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
export const apiKeyManage = async (requestEvent: Deno.RequestEvent, query: Map<string, string>, apiUserid: BigInt, path: string) => {
|
||||
if ((query.has('a') && ((query.get('a') || '').length > 0)) && (query.has('user') && ((query.get('user') || '').length > 0))) {
|
||||
|
@ -31,7 +32,7 @@ export const apiKeyManage = async (requestEvent: Deno.RequestEvent, query: Map<s
|
|||
|
||||
// Execute the DB modification
|
||||
await dbClient.execute('UPDATE all_keys SET ?? = ? WHERE userid = ?', [key, value, apiUserid]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into database: ${JSON.stringify(e)}`);
|
||||
utils.commonLoggers.dbError('apiKeyManage.ts', 'update', e);
|
||||
requestEvent.respondWith(stdResp.InternalServerError(`Failed to ${key} to ${value}.`));
|
||||
erroredOut = true;
|
||||
});
|
||||
|
|
|
@ -48,9 +48,7 @@ const handleRollWorker = async (rq: QueuedRoll) => {
|
|||
<RollModifiers> {},
|
||||
)).embed,
|
||||
],
|
||||
}).catch((e) => {
|
||||
log(LT.ERROR, `Failed to edit message: ${JSON.stringify(rq.dd.m)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}).catch((e) => utils.commonLoggers.messageEditError('rollQueue.ts:51', rq.dd.m, e));
|
||||
}
|
||||
}, config.limits.workerTimeout);
|
||||
|
||||
|
@ -79,9 +77,7 @@ const handleRollWorker = async (rq: QueuedRoll) => {
|
|||
|
||||
if (rq.apiRoll || DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can see what went wrong
|
||||
dbClient.execute(queries.insertRollLogCmd(rq.apiRoll ? 1 : 0, 1), [rq.originalCommand, returnmsg.errorCode, rq.apiRoll ? null : rq.dd.m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(rq.apiRoll ? 1 : 0, 1), [rq.originalCommand, returnmsg.errorCode, rq.apiRoll ? null : rq.dd.m.id]).catch((e) => utils.commonLoggers.dbError('rollQueue.ts:82', 'insert into', e));
|
||||
}
|
||||
} else {
|
||||
let n: DiscordenoMessage | void;
|
||||
|
@ -154,9 +150,7 @@ const handleRollWorker = async (rq: QueuedRoll) => {
|
|||
}
|
||||
|
||||
if (rq.apiRoll && !apiErroredOut) {
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnmsg.errorCode, n ? n.id : null]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
dbClient.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnmsg.errorCode, n ? n.id : null]).catch((e) => utils.commonLoggers.dbError('rollQueue.ts:155', 'insert into', e));
|
||||
|
||||
rq.api.requestEvent.respondWith(stdResp.OK(JSON.stringify(
|
||||
rq.modifiers.count
|
||||
|
|
|
@ -95,13 +95,18 @@ Available Commands:
|
|||
};
|
||||
|
||||
const genericLogger = (level: LT, message: string) => log(level, message);
|
||||
const messageEditError = (location: string, message: DiscordenoMessage | string, err: Error) =>
|
||||
genericLogger(LT.ERROR, `${location} | Failed to edit message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message}`);
|
||||
const messageSendError = (location: string, message: DiscordenoMessage | string, err: Error) =>
|
||||
genericLogger(LT.ERROR, `${location} | Failed to send message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message} `);
|
||||
genericLogger(LT.ERROR, `${location} | Failed to send message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message}`);
|
||||
const messageDeleteError = (location: string, message: DiscordenoMessage | string, err: Error) =>
|
||||
genericLogger(LT.ERROR, `${location} | Failed to delete message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message} `);
|
||||
genericLogger(LT.ERROR, `${location} | Failed to delete message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message}`);
|
||||
const dbError = (location: string, type: string, err: Error) => genericLogger(LT.ERROR, `${location} | Failed to ${type} database | Error: ${err.name} - ${err.message}`);
|
||||
|
||||
export default {
|
||||
commonLoggers: {
|
||||
dbError,
|
||||
messageEditError,
|
||||
messageSendError,
|
||||
messageDeleteError,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue