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