Fix error that was causing crash when posting statistics
Additionally, added system logging to rc.service
This commit is contained in:
parent
766dff179e
commit
23ca3a2665
|
@ -1,4 +1,4 @@
|
|||
# The Artificer - A Dice Rolling Discord Bot | V2.1.1 - 2022/07/10
|
||||
# The Artificer - A Dice Rolling Discord Bot | V2.1.2 - 2022/07/31
|
||||
[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=TheArtificer) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=TheArtificer) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=TheArtificer) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=bugs)](https://sonarcloud.io/summary/new_code?id=TheArtificer) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=TheArtificer) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=TheArtificer&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||
|
||||
|
|
|
@ -11,10 +11,11 @@ pidfile="/var/dbots/TheArtificer/artificer.pid"
|
|||
artificer_root="/var/dbots/TheArtificer"
|
||||
artificer_write="./logs/,./src/endpoints/gets/heatmap.png"
|
||||
artificer_read="./src/solver/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png"
|
||||
artificer_log="/var/log/artificer.log"
|
||||
|
||||
artificer_chdir="${artificer_root}"
|
||||
command="/usr/sbin/daemon"
|
||||
command_args="-f -R 5 -P ${pidfile} /usr/local/bin/deno run --allow-write=${artificer_write} --allow-read=${artificer_read} --allow-net ${artificer_root}/mod.ts"
|
||||
command_args="-f -R 5 -P ${pidfile} -o ${artificer_log} /usr/local/bin/deno run --allow-write=${artificer_write} --allow-read=${artificer_read} --allow-net ${artificer_root}/mod.ts"
|
||||
|
||||
load_rc_config artificer
|
||||
run_rc_command "$1"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export const config = {
|
||||
'name': 'The Artificer', // Name of the bot
|
||||
'version': '2.1.1', // Version of the bot
|
||||
'version': '2.1.2', // Version of the bot
|
||||
'token': 'the_bot_token', // Discord API Token for this bot
|
||||
'localtoken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
||||
'prefix': '[[', // Prefix for all commands
|
||||
|
|
|
@ -47,18 +47,22 @@ const getRandomStatus = async (): Promise<string> => {
|
|||
// Sends the current server count to all bot list sites we are listed on
|
||||
const updateListStatistics = (botID: bigint, serverCount: number): void => {
|
||||
config.botLists.forEach(async (e) => {
|
||||
log(LT.LOG, `Updating statistics for ${JSON.stringify(e)}`);
|
||||
if (e.enabled) {
|
||||
const tempHeaders = new Headers();
|
||||
tempHeaders.append(e.headers[0].header, e.headers[0].value);
|
||||
tempHeaders.append('Content-Type', 'application/json');
|
||||
// ?{} is a template used in config, just need to replace it with the real value
|
||||
const response = await fetch(e.apiUrl.replace('?{bot_id}', botID.toString()), {
|
||||
'method': 'POST',
|
||||
'headers': tempHeaders,
|
||||
'body': JSON.stringify(e.body).replace('"?{server_count}"', serverCount.toString()), // ?{server_count} needs the "" removed from around it aswell to make sure its sent as a number
|
||||
});
|
||||
log(LT.INFO, `Posted server count to ${e.name}. Results: ${JSON.stringify(response)}`);
|
||||
try {
|
||||
log(LT.LOG, `Updating statistics for ${JSON.stringify(e)}`);
|
||||
if (e.enabled) {
|
||||
const tempHeaders = new Headers();
|
||||
tempHeaders.append(e.headers[0].header, e.headers[0].value);
|
||||
tempHeaders.append('Content-Type', 'application/json');
|
||||
// ?{} is a template used in config, just need to replace it with the real value
|
||||
const response = await fetch(e.apiUrl.replace('?{bot_id}', botID.toString()), {
|
||||
'method': 'POST',
|
||||
'headers': tempHeaders,
|
||||
'body': JSON.stringify(e.body).replace('"?{server_count}"', serverCount.toString()), // ?{server_count} needs the "" removed from around it aswell to make sure its sent as a number
|
||||
});
|
||||
log(LT.INFO, `Posted server count to ${e.name}. Results: ${JSON.stringify(response)}`);
|
||||
}
|
||||
} catch (err) {
|
||||
log(LT.ERROR, `Failed to update statistics for ${e.name} | Error: ${err.name} - ${err.message}`)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue