diff --git a/src/modules/command/command.abstract.ts b/src/modules/command/command.abstract.ts index b5ee918..b62202b 100644 --- a/src/modules/command/command.abstract.ts +++ b/src/modules/command/command.abstract.ts @@ -1,7 +1,6 @@ import { CacheType, CommandInteraction, - Interaction, SlashCommandBuilder, } from 'discord.js'; diff --git a/src/modules/command/command.module.ts b/src/modules/command/command.module.ts index 884ac59..76d1c66 100644 --- a/src/modules/command/command.module.ts +++ b/src/modules/command/command.module.ts @@ -12,6 +12,8 @@ import { SomeoneOnceSaidModule } from '../someone-once-said/module/someone-once- import GetRandomQuote from './commands/get-a-quote'; import { PollCommand } from './commands/poll'; import { PollModule } from '../poll/module/poll.module'; +import { VersionModule } from '../version/module/version.module'; +import { VersionCommand } from './commands/version'; @Module({ providers: [ @@ -25,9 +27,10 @@ import { PollModule } from '../poll/module/poll.module'; GoldCommand, SomeoneOnceSaidCommand, GetRandomQuote, - PollCommand + PollCommand, + VersionCommand ], - imports: [SomeoneOnceSaidModule, PollModule], + imports: [SomeoneOnceSaidModule, PollModule, VersionModule], exports: [CommandService], }) export class CommandModule {} diff --git a/src/modules/command/command.service.ts b/src/modules/command/command.service.ts index 8c6863a..8a59048 100644 --- a/src/modules/command/command.service.ts +++ b/src/modules/command/command.service.ts @@ -9,6 +9,7 @@ import { GoldCommand } from './commands/gold'; import SomeoneOnceSaidCommand from './commands/someone-once-said'; import GetRandomQuote from './commands/get-a-quote'; import { PollCommand } from './commands/poll'; +import { VersionCommand } from './commands/version'; @Injectable() export class CommandService { @@ -24,7 +25,8 @@ export class CommandService { goldModule: GoldCommand, someoneOnceSaidModule: SomeoneOnceSaidCommand, getRandomQuoteModule: GetRandomQuote, - pollModule: PollCommand + pollModule: PollCommand, + versionModule: VersionCommand ) { const commands: ACommand[] = [ //pingpongModule, @@ -36,7 +38,8 @@ export class CommandService { goldModule, someoneOnceSaidModule, getRandomQuoteModule, - pollModule + pollModule, + versionModule ]; commands.forEach((command) => { if (command.data.name && command.execute) { diff --git a/src/modules/command/commands/version.ts b/src/modules/command/commands/version.ts new file mode 100644 index 0000000..7c77372 --- /dev/null +++ b/src/modules/command/commands/version.ts @@ -0,0 +1,28 @@ +import { Inject, Injectable } from '@nestjs/common'; +import { SlashCommandBuilder } from 'discord.js'; +import { ACommand } from '../command.abstract'; +import { VersionService } from '../../version/service/version.service'; + +@Injectable() +export class VersionCommand extends ACommand { + constructor( + @Inject(VersionService) private readonly versionService: VersionService, + ) { + super(); + } + data = new SlashCommandBuilder() + .setName('version') + .setDescription( + 'show the version of the currently running bingus instance', + ); + + async execute(interaction) { + const version = await this.versionService.getVersion(); + return this.run(async () => { + if (version && version.length > 0) { + return await interaction.reply(`The current version is: ${version}`); + } + return await interaction.reply('Failed to get version'); + }); + } +} diff --git a/src/modules/version/module/version.module.ts b/src/modules/version/module/version.module.ts new file mode 100644 index 0000000..82123d7 --- /dev/null +++ b/src/modules/version/module/version.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { VersionService } from '../service/version.service'; + +@Module({ + imports: [], + controllers: [], + providers: [VersionService], + exports: [VersionService], +}) +export class VersionModule {} diff --git a/src/modules/version/service/version.service.ts b/src/modules/version/service/version.service.ts new file mode 100644 index 0000000..400e173 --- /dev/null +++ b/src/modules/version/service/version.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import * as fs from 'fs'; + +@Injectable() +export class VersionService { + private version: string; + + constructor() { + // Read package.json synchronously + const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + this.version = packageJson.version; + } + + getVersion(): string { + return this.version; + } +}