aboutsummaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-29 11:42:40 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-29 11:42:40 -0400
commitf18f5fff1fd0b8336df464d6e6f62efbc29aa618 (patch)
treecc23d2aa33ccb9dcd67f6bda811e5f32b0edc766 /bot/src
parent879c2a05c86682564f1f68aa234fd8e5298e95f6 (diff)
downloadAleeBot-f18f5fff1fd0b8336df464d6e6f62efbc29aa618.tar.gz
AleeBot-f18f5fff1fd0b8336df464d6e6f62efbc29aa618.tar.bz2
AleeBot-f18f5fff1fd0b8336df464d6e6f62efbc29aa618.zip
Added analytics; try/catch for ready event
Diffstat (limited to 'bot/src')
-rw-r--r--bot/src/events/ClientReady.js48
-rw-r--r--bot/src/events/GuildMemberUpdate.js2
-rw-r--r--bot/src/events/InteractionCreate.js3
-rw-r--r--bot/src/models/command-usages.js26
-rw-r--r--bot/src/plugins/analytics.js17
-rw-r--r--bot/src/storage/consts.js1
-rw-r--r--bot/src/utils/sync.js5
7 files changed, 79 insertions, 23 deletions
diff --git a/bot/src/events/ClientReady.js b/bot/src/events/ClientReady.js
index eeb8ab0..9669287 100644
--- a/bot/src/events/ClientReady.js
+++ b/bot/src/events/ClientReady.js
@@ -28,28 +28,32 @@ export default {
console.log(`[i] Bot ID: ${client.user.id}`);
console.log(`[i] Running version ${abVersion} | Serving in ${client.guilds.cache.size} guilds`);
- await botActivity(client);
- await QuoteOfTheDay(client);
-
- if (process.env.NODE_ENV !== 'development') {
- const readyEmbed = new EmbedBuilder()
- .setAuthor({ name: 'AleeBot Status', iconURL: client.user.avatarURL() })
- .setDescription('AleeBot has started')
- .addFields(
- { name: 'Version', value: `${abVersion}`, inline: true },
- { name: 'Node.JS Version', value: `${process.versions.node}`, inline: true },
- { name: 'Discord.JS Version', value: `${version}`, inline: true }
- )
- .setColor(abEmbedColour);
-
- let statusChannel = client.channels.cache.get(process.env.STATUS_CHANNEL_ID);
- if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
- await statusChannel.send({ embeds: [readyEmbed] });
+ try {
+ await botActivity(client);
+ await QuoteOfTheDay(client);
+
+ if (process.env.NODE_ENV !== 'development') {
+ const readyEmbed = new EmbedBuilder()
+ .setAuthor({name: 'AleeBot Status', iconURL: client.user.avatarURL()})
+ .setDescription('AleeBot has started')
+ .addFields(
+ {name: 'Version', value: `${abVersion}`, inline: true},
+ {name: 'Node.JS Version', value: `${process.versions.node}`, inline: true},
+ {name: 'Discord.JS Version', value: `${version}`, inline: true}
+ )
+ .setColor(abEmbedColour);
+
+ let statusChannel = client.channels.cache.get(process.env.STATUS_CHANNEL_ID);
+ if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
+ await statusChannel.send({embeds: [readyEmbed]});
+ }
+
+ setInterval(function () {
+ botActivity(client);
+ }, 200000);
+
+ } catch (e) {
+ console.error(e);
}
-
- setInterval(function() {
- botActivity(client);
- }, 200000);
-
}
};
diff --git a/bot/src/events/GuildMemberUpdate.js b/bot/src/events/GuildMemberUpdate.js
index 3c90268..1fec4fe 100644
--- a/bot/src/events/GuildMemberUpdate.js
+++ b/bot/src/events/GuildMemberUpdate.js
@@ -24,7 +24,7 @@ export default {
await guildMember.send({ embeds: [logEmbed] });
} catch (e) {
- console.error(e);
+ console.error(e);
}
}
};
diff --git a/bot/src/events/InteractionCreate.js b/bot/src/events/InteractionCreate.js
index ac979d2..777ce39 100644
--- a/bot/src/events/InteractionCreate.js
+++ b/bot/src/events/InteractionCreate.js
@@ -1,4 +1,5 @@
import { Events, MessageFlags } from 'discord.js';
+import { Analytics } from '../plugins/analytics.js';
function error(e) {
return `Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`js\n${e.stack}\`\`\``;
@@ -14,6 +15,8 @@ export default {
if (!command) return;
try {
+ console.log(`[i] ${interaction.user.username} has executed ${command.data.name}`);
+ await Analytics(command, interaction);
await command.execute(interaction);
} catch (e) {
console.error(e);
diff --git a/bot/src/models/command-usages.js b/bot/src/models/command-usages.js
new file mode 100644
index 0000000..a9dafa4
--- /dev/null
+++ b/bot/src/models/command-usages.js
@@ -0,0 +1,26 @@
+import { INTEGER, STRING } from 'sequelize';
+import { sequelize } from '../utils/sequelize.js';
+
+export const commandUsages = sequelize.define('command-usages', {
+ id: {
+ type: INTEGER,
+ autoIncrement: true,
+ primaryKey: true
+ },
+ command: {
+ type: STRING,
+ allowNull: false
+ },
+ userID: {
+ type: STRING,
+ allowNull: false
+ },
+ guildID: {
+ type: STRING,
+ allowNull: true
+ }
+
+}, {
+ updatedAt: false,
+});
+
diff --git a/bot/src/plugins/analytics.js b/bot/src/plugins/analytics.js
new file mode 100644
index 0000000..137207f
--- /dev/null
+++ b/bot/src/plugins/analytics.js
@@ -0,0 +1,17 @@
+import { commandUsages } from '../models/command-usages.js';
+import { enableAnalytics } from '../storage/consts.js';
+
+export async function Analytics(command, interaction) {
+ if (enableAnalytics) {
+ if (!interaction.guild) return await commandUsages.create({
+ command: command.data.name,
+ userID: interaction.user.id
+ });
+
+ return await commandUsages.create({
+ command: command.data.name,
+ userID: interaction.user.id,
+ guildID: interaction.guild.id
+ });
+ }
+}
diff --git a/bot/src/storage/consts.js b/bot/src/storage/consts.js
index b62d218..71a77ab 100644
--- a/bot/src/storage/consts.js
+++ b/bot/src/storage/consts.js
@@ -1,5 +1,6 @@
export const abEmbedColour = '#0066a6';
export const ollamaGlobal = true;
+export const enableAnalytics = true;
export const featureSuggestChannel = '427495678390960148';
export const userWhitelist = ['242775871059001344'];
diff --git a/bot/src/utils/sync.js b/bot/src/utils/sync.js
index fbf6c2e..fa3d8c9 100644
--- a/bot/src/utils/sync.js
+++ b/bot/src/utils/sync.js
@@ -1,5 +1,6 @@
import { quote, pendingQuote } from '../models/quote.js';
import { guildSettings } from '../models/guild-settings.js';
+import { commandUsages } from '../models/command-usages.js';
export function syncDB() {
quote.sync().then(() => {
@@ -13,4 +14,8 @@ export function syncDB() {
guildSettings.sync().then(() => {
console.log('[>] Guild database synced!');
});
+
+ commandUsages.sync().then(() => {
+ console.log('[>] Command usage database synced!');
+ });
}