aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-05-25 17:05:24 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-05-25 17:05:24 -0400
commit59ea06a2f010ad7503e4f7b7a1894485d37a416e (patch)
tree78a20be7fb7aad6e77b906a641e7755ec4baee55
parent994de0471e7032e8c1fc7d7621ecae880746a3f1 (diff)
downloadtanzanite-59ea06a2f010ad7503e4f7b7a1894485d37a416e.tar.gz
tanzanite-59ea06a2f010ad7503e4f7b7a1894485d37a416e.tar.bz2
tanzanite-59ea06a2f010ad7503e4f7b7a1894485d37a416e.zip
feat: add slash command usage
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts11
-rw-r--r--src/lib/models/shared/Stat.ts18
-rw-r--r--src/listeners/commands/slashStarted.ts23
-rw-r--r--src/tasks/updateStats.ts8
4 files changed, 54 insertions, 6 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 5ccc283..4df751d 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -125,7 +125,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
/**
* Stats for the client.
*/
- public stats: BushStats = { cpu: undefined, commandsUsed: 0n };
+ public stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n };
/**
* The configuration for the client.
@@ -482,7 +482,9 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
await this.highlightManager.syncCache();
await UpdateCacheTask.init(this);
void this.console.success('startup', `Successfully created <<cache>>.`, false);
- this.stats.commandsUsed = await UpdateStatsTask.init();
+ const stats = await UpdateStatsTask.init();
+ this.stats.commandsUsed = stats.commandsUsed;
+ this.stats.slashCommandsUsed = stats.slashCommandsUsed;
await this.login(this.token!);
} catch (e) {
await this.console.error('start', util.inspect(e, { colors: true, depth: 1 }), false);
@@ -539,6 +541,11 @@ export interface BushStats {
* The total number of times any command has been used.
*/
commandsUsed: bigint;
+
+ /**
+ * The total number of times any slash command has been used.
+ */
+ slashCommandsUsed: bigint;
}
export interface Emitters {
diff --git a/src/lib/models/shared/Stat.ts b/src/lib/models/shared/Stat.ts
index d138620..8e2e0b3 100644
--- a/src/lib/models/shared/Stat.ts
+++ b/src/lib/models/shared/Stat.ts
@@ -7,11 +7,13 @@ type Environment = 'production' | 'development' | 'beta';
export interface StatModel {
environment: Environment;
commandsUsed: bigint;
+ slashCommandsUsed: bigint;
}
export interface StatModelCreationAttributes {
environment: Environment;
commandsUsed?: bigint;
+ slashCommandsUsed?: bigint;
}
/**
@@ -29,6 +31,11 @@ export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> impl
public declare commandsUsed: bigint;
/**
+ * The number of slash commands used
+ */
+ public declare slashCommandsUsed: bigint;
+
+ /**
* Initializes the model.
* @param sequelize The sequelize instance.
*/
@@ -46,6 +53,17 @@ export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> impl
},
allowNull: false,
defaultValue: `${0n}`
+ },
+ slashCommandsUsed: {
+ type: DataTypes.TEXT,
+ get: function (): bigint {
+ return BigInt(this.getDataValue('slashCommandsUsed'));
+ },
+ set: function (val: bigint) {
+ return this.setDataValue('slashCommandsUsed', <any>`${val}`);
+ },
+ allowNull: false,
+ defaultValue: `${0n}`
}
},
{ sequelize }
diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts
index 0084dc6..3e945a9 100644
--- a/src/listeners/commands/slashStarted.ts
+++ b/src/listeners/commands/slashStarted.ts
@@ -1,4 +1,5 @@
import { BushListener, type BushCommandHandlerEvents } from '#lib';
+import { Severity } from '@sentry/types';
import { ChannelType } from 'discord.js';
export default class SlashStartedListener extends BushListener {
@@ -11,7 +12,25 @@ export default class SlashStartedListener extends BushListener {
}
public override async exec(...[message, command]: BushCommandHandlerEvents['slashStarted']) {
- return void client.logger.info(
+ client.sentry.addBreadcrumb({
+ message: `[slashStarted] The ${command.id} was started by ${message.author.tag}.`,
+ level: Severity.Info,
+ timestamp: Date.now(),
+ data: {
+ 'command.name': command?.id,
+ 'message.id': message.id,
+ 'message.type': message.util.isSlash ? 'slash' : 'normal',
+ 'message.parsed.content': message.util.parsed?.content,
+ 'channel.id': (message.channel?.isDMBased() ? message.channel.recipient?.id : message.channel?.id) ?? '¯\\_(ツ)_/¯',
+ 'channel.name':
+ (message.channel?.isDMBased() ? message.channel.recipient?.tag : (<any>message.channel)?.name) ?? '¯\\_(ツ)_/¯',
+ 'guild.id': message.guild?.id ?? '¯\\_(ツ)_/¯',
+ 'guild.name': message.guild?.name ?? '¯\\_(ツ)_/¯',
+ 'environment': client.config.environment
+ }
+ });
+
+ void client.logger.info(
'slashStarted',
`The <<${command.id}>> command was used by <<${message.author.tag}>> in ${
message.channel
@@ -22,5 +41,7 @@ export default class SlashStartedListener extends BushListener {
}.`,
true
);
+
+ client.stats.commandsUsed = client.stats.commandsUsed + 1n;
}
}
diff --git a/src/tasks/updateStats.ts b/src/tasks/updateStats.ts
index 15ebe96..f27841f 100644
--- a/src/tasks/updateStats.ts
+++ b/src/tasks/updateStats.ts
@@ -12,11 +12,13 @@ export default class UpdateStatsTask extends BushTask {
const row =
(await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }));
row.commandsUsed = client.stats.commandsUsed;
+ row.slashCommandsUsed = client.stats.slashCommandsUsed;
await row.save();
}
- public static async init(): Promise<bigint> {
- return ((await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment })))
- .commandsUsed;
+ public static async init(): Promise<{ commandsUsed: bigint; slashCommandsUsed: bigint }> {
+ const temp =
+ (await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }));
+ return { commandsUsed: temp.commandsUsed, slashCommandsUsed: temp.slashCommandsUsed };
}
}