Started moving common log messages to one spot

This commit is contained in:
Ean Milligan (Bastion) 2022-06-22 21:43:57 -04:00
parent bff208d560
commit 021f33fc38
25 changed files with 90 additions and 127 deletions

12
mod.ts
View File

@ -85,22 +85,16 @@ startBot({
}],
status: 'online',
});
sendMessage(config.logChannel, `${config.name} has started, running version ${config.version}.`).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(e)}`);
});
sendMessage(config.logChannel, `${config.name} has started, running version ${config.version}.`).catch((e: Error) => utils.commonLoggers.messageSendError('mod.ts:88', 'Startup', e));
}, 1000);
},
guildCreate: (guild: DiscordenoGuild) => {
log(LT.LOG, `Handling joining guild ${JSON.stringify(guild)}`);
sendMessage(config.logChannel, `New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(e)}`);
});
sendMessage(config.logChannel, `New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`).catch((e: Error) => utils.commonLoggers.messageSendError('mod.ts:95', 'Join Guild', e));
},
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) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(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) => {
log(LT.ERROR, `Failed to DELETE guild from DB: ${JSON.stringify(e)}`);
});

View File

@ -9,6 +9,7 @@ import {
} from '../../deps.ts';
import apiCommands from './apiCmd/_index.ts';
import { failColor } from '../commandUtils.ts';
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
@ -26,9 +27,7 @@ export const api = async (message: DiscordenoMessage, args: string[]) => {
color: failColor,
title: 'API commands are only available in guilds.',
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('apiCmd.ts:30', message, e));
return;
}
@ -75,8 +74,6 @@ export const api = async (message: DiscordenoMessage, args: string[]) => {
title: 'API commands are powerful and can only be used by guild Owners and Admins.',
description: 'For information on how to use the API, please check the GitHub README for more information [here](https://github.com/Burn-E99/TheArtificer).',
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('apiCmd.ts:77', message, e));
}
};

View File

@ -7,14 +7,13 @@ import {
LT,
} from '../../../deps.ts';
import { generateApiFailed, generateApiSuccess } from '../../commandUtils.ts';
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)}`);
message.send(generateApiFailed(apiArg)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:16', message, e));
errorOutInitial = true;
});
if (errorOutInitial) return;
@ -25,9 +24,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
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)}`);
message.send(generateApiFailed(apiArg)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:27', message, e));
errorOut = true;
},
);
@ -36,9 +33,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
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)}`);
message.send(generateApiFailed(apiArg)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
message.send(generateApiFailed(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:36', message, e));
errorOut = true;
},
);
@ -46,7 +41,5 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
if (errorOut) 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}ed`)).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(generateApiSuccess(`${apiArg}ed`)).catch((e: Error) => utils.commonLoggers.messageSendError('allowBlock.ts:44', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../../deps.ts';
import { infoColor1, infoColor2 } from '../../commandUtils.ts';
import utils from '../../utils.ts';
export const help = (message: DiscordenoMessage) => {
message.send({
@ -63,7 +64,5 @@ You may enable and disable the API rolls for your guild as needed.`,
],
},
],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('apiHelp.ts:67', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../../deps.ts';
import { failColor, successColor } from '../../commandUtils.ts';
import utils from '../../utils.ts';
export const deleteGuild = async (message: DiscordenoMessage) => {
let errorOut = false;
@ -18,9 +19,7 @@ export const deleteGuild = async (message: DiscordenoMessage) => {
title: 'Failed to delete this guild from the database.',
description: 'If this issue persists, please report this to the developers.',
}],
}).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteGuild.ts:22', message, e));
errorOut = true;
});
if (errorOut) return;
@ -31,7 +30,5 @@ export const deleteGuild = async (message: DiscordenoMessage) => {
color: successColor,
title: 'This guild\'s API setting has been removed from The Artifier\'s Database.',
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteGuild.ts:33', message, e));
};

View File

@ -7,14 +7,13 @@ import {
LT,
} from '../../../deps.ts';
import { generateApiFailed, generateApiSuccess } from '../../commandUtils.ts';
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)}`);
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
message.send(generateApiFailed(`${apiArg} on`)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:16', message, e));
errorOutInitial = true;
});
if (errorOutInitial) return;
@ -24,25 +23,19 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
// 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)}`);
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
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)}`);
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
message.send(generateApiFailed(`${apiArg} on`)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:33', message, e));
errorOut = true;
});
}
if (errorOut) 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) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(generateApiSuccess(apiArg)).catch((e: Error) => utils.commonLoggers.messageSendError('showHideWarn.ts:40', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../../deps.ts';
import { failColor, generateApiStatus } from '../../commandUtils.ts';
import utils from '../../utils.ts';
export const status = async (message: DiscordenoMessage) => {
// Get status of guild from the db
@ -19,9 +20,7 @@ export const status = async (message: DiscordenoMessage) => {
title: 'Failed to check API rolls status for this guild.',
description: 'If this issue persists, please report this to the developers.',
}],
}).catch((e1) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('status.ts:23', message, e));
errorOut = true;
});
if (errorOut) return;
@ -30,18 +29,12 @@ export const status = async (message: DiscordenoMessage) => {
if (guildQuery.length > 0) {
// Check if guild is banned from using API and return appropriate message
if (guildQuery[0].banned) {
message.send(generateApiStatus(true, false)).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(generateApiStatus(true, false)).catch((e: Error) => utils.commonLoggers.messageSendError('status.ts:32', message, e));
} else {
message.send(generateApiStatus(false, guildQuery[0].active)).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(generateApiStatus(false, guildQuery[0].active)).catch((e: Error) => utils.commonLoggers.messageSendError('status.ts:34', message, e));
}
} else {
// Guild is not in DB, therefore they are blocked
message.send(generateApiStatus(false, false)).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(generateApiStatus(false, false)).catch((e: Error) => utils.commonLoggers.messageSendError('status.ts:38', message, e));
}
};

View File

@ -9,6 +9,7 @@ import {
} from '../../deps.ts';
import auditCommands from './auditCmd/_index.ts';
import { failColor } from '../commandUtils.ts';
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
@ -47,8 +48,6 @@ export const audit = async (message: DiscordenoMessage, args: string[]) => {
color: failColor,
title: `Audit commands are powerful and can only be used by ${config.name}'s owner.`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('audit.ts:51', message, e));
}
};

View File

@ -9,6 +9,7 @@ import {
} from '../../../deps.ts';
import { infoColor2 } from '../../commandUtils.ts';
import { compilingStats } from '../../commonEmbeds.ts';
import utils from '../../utils.ts';
export const auditDB = async (message: DiscordenoMessage) => {
try {
@ -39,10 +40,8 @@ export const auditDB = async (message: DiscordenoMessage) => {
timestamp: new Date().toISOString(),
fields: embedFields,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('auditDB.ts:43', message, e));
} catch (e) {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
utils.commonLoggers.messageSendError('auditDB.ts:45', message, e)
}
};

View File

@ -6,6 +6,7 @@ import {
LT,
} from '../../../deps.ts';
import { infoColor2 } from '../../commandUtils.ts';
import utils from '../../utils.ts';
export const auditGuilds = (message: DiscordenoMessage) => {
message.send({
@ -15,7 +16,5 @@ export const auditGuilds = (message: DiscordenoMessage) => {
description: 'WIP',
timestamp: new Date().toISOString(),
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('auditGuild.ts:19', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../../deps.ts';
import { infoColor1 } from '../../commandUtils.ts';
import utils from '../../utils.ts';
export const auditHelp = (message: DiscordenoMessage) => {
message.send({
@ -31,7 +32,5 @@ export const auditHelp = (message: DiscordenoMessage) => {
},
],
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('auditHelp.ts:35', message, e));
};

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { EmojiConf } from '../mod.d.ts';
import utils from '../utils.ts';
const allEmojiAliases: string[] = [];
@ -29,14 +30,10 @@ export const emoji = (message: DiscordenoMessage, command: string) => {
});
// Send the needed emoji
message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e: Error) => utils.commonLoggers.messageSendError('emoji.ts:33', message, e));
// And attempt to delete if needed
if (emji.deleteSender) {
message.delete().catch((e) => {
log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
message.delete().catch((e: Error) => utils.commonLoggers.messageDeleteError('emoji.ts:36', message, e));
}
return true;
}

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor1 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const handleMentions = (message: DiscordenoMessage) => {
log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`);
@ -26,7 +27,5 @@ export const handleMentions = (message: DiscordenoMessage) => {
value: `To learn about my available commands, please run \`${config.prefix}help\``,
}],
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('handleMentions.ts:30', message, e));
};

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor2 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const help = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -78,7 +79,5 @@ export const help = (message: DiscordenoMessage) => {
},
],
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('help.ts:82', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor2 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const info = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -23,7 +24,5 @@ Additional information can be found on my website [here](https://discord.burne99
Want to check out my source code? Check it out [here](https://github.com/Burn-E99/TheArtificer).
Need help with this bot? Join my support server [here](https://discord.gg/peHASXMZYv).`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('info.ts:27', message, e));
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../deps.ts';
import { generatePing } from '../commandUtils.ts';
import utils from '../utils.ts';
export const ping = async (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -19,6 +20,6 @@ export const ping = async (message: DiscordenoMessage) => {
const m = await message.send(generatePing(-1));
m.edit(generatePing(m.timestamp - message.timestamp));
} catch (e) {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
utils.commonLoggers.messageSendError('ping.ts:23', message, e);
}
};

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor1 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const privacy = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -29,7 +30,5 @@ For more details, please check out the Privacy Policy on the GitHub [here](https
Terms of Service can also be found on GitHub [here](https://github.com/Burn-E99/TheArtificer/blob/master/TERMS.md).`,
}],
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('privacy.ts:33', message, e));
};

View File

@ -10,6 +10,7 @@ import {
sendMessage,
} from '../../deps.ts';
import { failColor, generateReport, successColor } from '../commandUtils.ts';
import utils from '../utils.ts';
export const report = (message: DiscordenoMessage, args: string[]) => {
// Light telemetry to see how many times a command is being run
@ -18,18 +19,14 @@ export const report = (message: DiscordenoMessage, args: string[]) => {
});
if (args.join(' ')) {
sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e));
message.send({
embeds: [{
color: successColor,
title: 'Failed command has been reported to my developer.',
description: `For more in depth support, and information about planned maintenance, please join the support server [here](https://discord.gg/peHASXMZYv).`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:29', message, e));
} else {
message.send({
embeds: [{
@ -37,8 +34,6 @@ export const report = (message: DiscordenoMessage, args: string[]) => {
title: 'Please provide a short description of what failed',
description: 'Providing a short description helps my developer quickly diagnose what went wrong.',
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:37', message, e));
}
};

View File

@ -7,6 +7,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor2 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const rip = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -22,7 +23,5 @@ export const rip = (message: DiscordenoMessage) => {
December 21, 2020`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('rip.ts:26', message, e));
};

View File

@ -12,6 +12,7 @@ import { rollingEmbed, warnColor } from '../commandUtils.ts';
import rollFuncs from './roll/_index.ts';
import { queueRoll } from '../solver/rollQueue.ts';
import { QueuedRoll } from '../mod.d.ts';
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
@ -26,9 +27,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
color: warnColor,
title: 'Command is in development, please try again later.',
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('roll.ts:30', message, e));
return;
}

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor1, infoColor2, successColor } from '../commandUtils.ts';
import utils from '../utils.ts';
export const rollHelp = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -243,7 +244,5 @@ Available directions:
],
},
],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('rollHelp.ts:247', message, e));
};

View File

@ -10,6 +10,7 @@ import {
} from '../../deps.ts';
import { generateStats } from '../commandUtils.ts';
import { compilingStats } from '../commonEmbeds.ts';
import utils from '../utils.ts';
export const stats = async (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -33,10 +34,8 @@ export const stats = async (message: DiscordenoMessage) => {
const cachedGuilds = await cacheHandlers.size('guilds');
const cachedChannels = await cacheHandlers.size('channels');
const cachedMembers = await cacheHandlers.size('members');
m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch((e: Error) => utils.commonLoggers.messageSendError('stats.ts:37', message, e));
} catch (e) {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
utils.commonLoggers.messageSendError('stats.ts:39', message, e);
}
};

View File

@ -8,6 +8,7 @@ import {
LT,
} from '../../deps.ts';
import { infoColor1 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const version = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -20,7 +21,5 @@ export const version = (message: DiscordenoMessage) => {
color: infoColor1,
title: `My current version is ${config.version}`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('version.ts:24', message, e));
};

View File

@ -15,6 +15,7 @@ import { SolvedRoll } from '../solver/solver.d.ts';
import { QueuedRoll, RollModifiers } from '../mod.d.ts';
import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed, infoColor2, rollingEmbed } from '../commandUtils.ts';
import stdResp from '../endpoints/stdResponses.ts';
import utils from '../utils.ts';
let currentWorkers = 0;
const rollQueue: Array<QueuedRoll> = [];
@ -193,9 +194,7 @@ export const queueRoll = async (rq: QueuedRoll) => {
The results for this roll will replace this message when it is done.`,
}],
}).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(rq.dd.m)} | ${JSON.stringify(e)}`);
});
}).catch((e: Error) => utils.commonLoggers.messageSendError('rollQueue.ts:197', rq.dd.m, e));
rollQueue.push(rq);
}
};
@ -206,9 +205,7 @@ setInterval(async () => {
if (rollQueue.length && currentWorkers < config.limits.maxWorkers) {
const temp = rollQueue.shift();
if (temp) {
temp.dd.m.edit(rollingEmbed).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(temp.dd.m)} | ${JSON.stringify(e)}`);
});
temp.dd.m.edit(rollingEmbed).catch((e: Error) => utils.commonLoggers.messageSendError('rollQueue.ts:208', temp.dd.m, e));
handleRollWorker(temp);
}
}

View File

@ -5,6 +5,11 @@
*/
import {
// Discordeno deps
DiscordenoMessage,
// Log4Deno deps
log,
LT,
// Discordeno deps
sendMessage,
} from '../deps.ts';
@ -74,9 +79,14 @@ const cmdPrompt = async (logChannel: bigint, botName: string): Promise<void> =>
} // help or h
// Shows a basic help menu
else if (command === 'help' || command === 'h') {
console.log(
`${botName} CLI Help:\n\nAvailable Commands:\n exit - closes bot\n stop - closes the CLI\n m [ChannelID] [messgae] - sends message to specific ChannelID as the bot\n ml [message] sends a message to the specified botlog\n help - this message`,
);
console.log(`${botName} CLI Help:
Available Commands:
exit - closes bot
stop - closes the CLI
m [ChannelID] [messgae] - sends message to specific ChannelID as the bot
ml [message] sends a message to the specified botlog
help - this message`);
} // Unhandled commands die here
else {
console.log('undefined command');
@ -84,4 +94,14 @@ const cmdPrompt = async (logChannel: bigint, botName: string): Promise<void> =>
}
};
export default { cmdPrompt };
const genericLogger = (level: LT, message: string) => log(level, 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} `)
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} `)
export default {
commonLoggers: {
messageSendError,
messageDeleteError,
},
cmdPrompt,
};