Compare commits
No commits in common. "master" and "V2.1.0" have entirely different histories.
|
@ -1,4 +1,4 @@
|
||||||
# The Artificer - A Dice Rolling Discord Bot | V2.1.2 - 2022/07/31
|
# The Artificer - A Dice Rolling Discord Bot | V2.1.0 - 2022/07/10
|
||||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
[](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
[](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ The Artificer comes with a few supplemental commands to the main rolling command
|
||||||
* `[[report [[2+2]] returned 5 when I expected it to return 4` will send the entire message after `[[report` to the devs via Discord.
|
* `[[report [[2+2]] returned 5 when I expected it to return 4` will send the entire message after `[[report` to the devs via Discord.
|
||||||
* `[[opt-out` or `[[ignore-me`
|
* `[[opt-out` or `[[ignore-me`
|
||||||
* Adds you to an ignore list so the bot will never respond to you
|
* Adds you to an ignore list so the bot will never respond to you
|
||||||
* `[[opt-in` **Available via DM ONLY**
|
* `[[opt-in`
|
||||||
* Removes you from the ignore list
|
* Removes you from the ignore list
|
||||||
* `[[xdydzracsq!]]`
|
* `[[xdydzracsq!]]`
|
||||||
* This is the command the bot was built specifically for.
|
* This is the command the bot was built specifically for.
|
||||||
|
@ -220,7 +220,7 @@ The Artificer is built on [Deno](https://deno.land/) `v1.22.0` using [Discordeno
|
||||||
|
|
||||||
You will also need to install and setup a MySQL database with a user for the bot to use to add/modify the database. This user must have the "DB Manager" admin rights and "REFERENCES" Global Privileges. Once the DB is installed and a user is setup, run the provided `db\initialize.ts` to create the schema and tables. After this, run `db\populateDefaults.ts` to insert some needed values into the tables.
|
You will also need to install and setup a MySQL database with a user for the bot to use to add/modify the database. This user must have the "DB Manager" admin rights and "REFERENCES" Global Privileges. Once the DB is installed and a user is setup, run the provided `db\initialize.ts` to create the schema and tables. After this, run `db\populateDefaults.ts` to insert some needed values into the tables.
|
||||||
|
|
||||||
Once everything is set up, starting the bot can simply be done with the command in `start.command`.
|
Once everything is set up, starting the bot can simply be done with `deno run --allow-net .\mod.ts`.
|
||||||
|
|
||||||
If you choose to run version `1.1.0` or newer, ensure you disable the API in `config.ts` or verify you have properly secured your instance of The Artificer. If you enable the API, you should manually generate a 25 char nanoid and place it in `config.api.adminKey` and copy your `userid` and place it in `config.api.admin` before running `db\populateDefaults.ts`.
|
If you choose to run version `1.1.0` or newer, ensure you disable the API in `config.ts` or verify you have properly secured your instance of The Artificer. If you enable the API, you should manually generate a 25 char nanoid and place it in `config.api.adminKey` and copy your `userid` and place it in `config.api.admin` before running `db\populateDefaults.ts`.
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,11 @@ pidfile="/var/dbots/TheArtificer/artificer.pid"
|
||||||
|
|
||||||
artificer_root="/var/dbots/TheArtificer"
|
artificer_root="/var/dbots/TheArtificer"
|
||||||
artificer_write="./logs/,./src/endpoints/gets/heatmap.png"
|
artificer_write="./logs/,./src/endpoints/gets/heatmap.png"
|
||||||
artificer_read="./src/solver/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./src/mod.d.ts"
|
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}"
|
artificer_chdir="${artificer_root}"
|
||||||
command="/usr/sbin/daemon"
|
command="/usr/sbin/daemon"
|
||||||
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"
|
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"
|
||||||
|
|
||||||
load_rc_config artificer
|
load_rc_config artificer
|
||||||
run_rc_command "$1"
|
run_rc_command "$1"
|
||||||
|
|
|
@ -6,7 +6,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
PIDFile=/run/deno.pid
|
PIDFile=/run/deno.pid
|
||||||
ExecStart=/root/.deno/bin/deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png,./config.ts,./deps.ts,./src/mod.d.ts --allow-net .\mod.ts
|
ExecStart=/root/.deno/bin/deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png --allow-net .\mod.ts
|
||||||
RestartSec=60
|
RestartSec=60
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export const config = {
|
export const config = {
|
||||||
'name': 'The Artificer', // Name of the bot
|
'name': 'The Artificer', // Name of the bot
|
||||||
'version': '2.1.3', // Version of the bot
|
'version': '2.1.0', // Version of the bot
|
||||||
'token': 'the_bot_token', // Discord API Token for this 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"
|
'localtoken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
||||||
'prefix': '[[', // Prefix for all commands
|
'prefix': '[[', // Prefix for all commands
|
||||||
|
|
6
mod.ts
6
mod.ts
|
@ -71,7 +71,7 @@ startBot({
|
||||||
// Interval to update bot list stats every 24 hours
|
// Interval to update bot list stats every 24 hours
|
||||||
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : setInterval(() => {
|
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : setInterval(() => {
|
||||||
log(LT.LOG, 'Updating all bot lists statistics');
|
log(LT.LOG, 'Updating all bot lists statistics');
|
||||||
intervals.updateListStatistics(botId, cache.guilds.size + cache.dispatchedGuildIds.size);
|
intervals.updateListStatistics(botId, cache.guilds.size);
|
||||||
}, 86400000);
|
}, 86400000);
|
||||||
|
|
||||||
// Interval to update hourlyRates every hour
|
// Interval to update hourlyRates every hour
|
||||||
|
@ -89,7 +89,7 @@ startBot({
|
||||||
// setTimeout added to make sure the startup message does not error out
|
// setTimeout added to make sure the startup message does not error out
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
LOCALMODE && editBotNickname(config.devServer, `LOCAL - ${config.name}`);
|
LOCALMODE && editBotNickname(config.devServer, `LOCAL - ${config.name}`);
|
||||||
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : intervals.updateListStatistics(botId, cache.guilds.size + cache.dispatchedGuildIds.size);
|
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : intervals.updateListStatistics(botId, cache.guilds.size);
|
||||||
intervals.updateHourlyRates();
|
intervals.updateHourlyRates();
|
||||||
intervals.updateHeatmapPng();
|
intervals.updateHeatmapPng();
|
||||||
editBotStatus({
|
editBotStatus({
|
||||||
|
@ -174,7 +174,7 @@ startBot({
|
||||||
if (message.isBot) return;
|
if (message.isBot) return;
|
||||||
|
|
||||||
// Ignore users who requested to be ignored
|
// Ignore users who requested to be ignored
|
||||||
if (ignoreList.includes(message.authorId) && (!message.content.startsWith(`${config.prefix}opt-in`) || message.guildId !== 0n)) return;
|
if (ignoreList.includes(message.authorId) && !message.content.startsWith(`${config.prefix}opt-in`)) return;
|
||||||
|
|
||||||
// Ignore all messages that are not commands
|
// Ignore all messages that are not commands
|
||||||
if (message.content.indexOf(config.prefix) !== 0) {
|
if (message.content.indexOf(config.prefix) !== 0) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ export const help = (message: DiscordenoMessage) => {
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `\`${config.prefix}opt-in\` **Available via DM ONLY**`,
|
name: `\`${config.prefix}opt-in\``,
|
||||||
value: 'Removes you from the ignore list',
|
value: 'Removes you from the ignore list',
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,29 +11,29 @@ export const optIn = 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(queries.callIncCnt('opt-out')).catch((e) => utils.commonLoggers.dbError('optIn.ts:11', 'call sproc INC_CNT on', e));
|
dbClient.execute(queries.callIncCnt('opt-out')).catch((e) => utils.commonLoggers.dbError('optIn.ts:11', 'call sproc INC_CNT on', e));
|
||||||
|
|
||||||
const idIdx = ignoreList.indexOf(message.authorId);
|
try {
|
||||||
if (idIdx !== -1) {
|
const idIdx = ignoreList.indexOf(message.authorId);
|
||||||
try {
|
if (idIdx !== -1) {
|
||||||
ignoreList.splice(idIdx, 1);
|
ignoreList.splice(idIdx, 1);
|
||||||
await dbClient.execute('DELETE FROM ignore_list WHERE userid = ?', [message.authorId]);
|
await dbClient.execute('DELETE FROM ignore_list WHERE userid = ?', [message.authorId]);
|
||||||
|
|
||||||
message.reply({
|
|
||||||
embeds: [{
|
|
||||||
color: successColor,
|
|
||||||
title: `${config.name} will now respond to you again.`,
|
|
||||||
description: `If you want ${config.name} to ignore to you again, please run the following command:
|
|
||||||
|
|
||||||
\`${config.prefix}opt-out\``,
|
|
||||||
}],
|
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('optIn.ts:27', message, e));
|
|
||||||
} catch (err) {
|
|
||||||
message.reply({
|
|
||||||
embeds: [{
|
|
||||||
color: failColor,
|
|
||||||
title: 'Opt-In failed',
|
|
||||||
description: 'Please try the command again. If the issue persists, please join the support server, linked in my About Me section.',
|
|
||||||
}],
|
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('optIn.ts:27', message, e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.reply({
|
||||||
|
embeds: [{
|
||||||
|
color: successColor,
|
||||||
|
title: `${config.name} will now respond to you again.`,
|
||||||
|
description: `If you want ${config.name} to ignore to you again, please run the following command:
|
||||||
|
|
||||||
|
\`${config.prefix}opt-out\``,
|
||||||
|
}],
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('optIn.ts:27', message, e));
|
||||||
|
} catch (err) {
|
||||||
|
message.reply({
|
||||||
|
embeds: [{
|
||||||
|
color: failColor,
|
||||||
|
title: 'Opt-In failed',
|
||||||
|
description: 'Please try the command again. If the issue persists, please join the support server, linked in my About Me section.',
|
||||||
|
}],
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('optIn.ts:27', message, e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const optOut = async (message: DiscordenoMessage) => {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: successColor,
|
color: successColor,
|
||||||
title: `${config.name} will no longer respond to you.`,
|
title: `${config.name} will no longer respond to you.`,
|
||||||
description: `If you want ${config.name} to respond to you again, please DM ${config.name} the following command:
|
description: `If you want ${config.name} to respond to you again, please run the following command:
|
||||||
|
|
||||||
\`${config.prefix}opt-in\``,
|
\`${config.prefix}opt-in\``,
|
||||||
}],
|
}],
|
||||||
|
|
|
@ -47,22 +47,18 @@ const getRandomStatus = async (): Promise<string> => {
|
||||||
// Sends the current server count to all bot list sites we are listed on
|
// Sends the current server count to all bot list sites we are listed on
|
||||||
const updateListStatistics = (botID: bigint, serverCount: number): void => {
|
const updateListStatistics = (botID: bigint, serverCount: number): void => {
|
||||||
config.botLists.forEach(async (e) => {
|
config.botLists.forEach(async (e) => {
|
||||||
try {
|
log(LT.LOG, `Updating statistics for ${JSON.stringify(e)}`);
|
||||||
log(LT.LOG, `Updating statistics for ${JSON.stringify(e)}`);
|
if (e.enabled) {
|
||||||
if (e.enabled) {
|
const tempHeaders = new Headers();
|
||||||
const tempHeaders = new Headers();
|
tempHeaders.append(e.headers[0].header, e.headers[0].value);
|
||||||
tempHeaders.append(e.headers[0].header, e.headers[0].value);
|
tempHeaders.append('Content-Type', 'application/json');
|
||||||
tempHeaders.append('Content-Type', 'application/json');
|
// ?{} is a template used in config, just need to replace it with the real value
|
||||||
// ?{} 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()), {
|
||||||
const response = await fetch(e.apiUrl.replace('?{bot_id}', botID.toString()), {
|
'method': 'POST',
|
||||||
'method': 'POST',
|
'headers': tempHeaders,
|
||||||
'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
|
||||||
'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)}`);
|
||||||
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}`)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png,./config.ts,./deps.ts,./src/mod.d.ts --allow-net .\mod.ts
|
deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png --allow-net .\mod.ts
|
Loading…
Reference in New Issue