Skip to content

Commit

Permalink
Merge pull request #81 from Blvckleg/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sanriodev authored Apr 5, 2024
2 parents 0c96407 + 7acaf2f commit e26a712
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/modules/command/command.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CacheType,
CommandInteraction,
Interaction,
SlashCommandBuilder,
} from 'discord.js';

Expand Down
7 changes: 5 additions & 2 deletions src/modules/command/command.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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 {}
7 changes: 5 additions & 2 deletions src/modules/command/command.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,7 +25,8 @@ export class CommandService {
goldModule: GoldCommand,
someoneOnceSaidModule: SomeoneOnceSaidCommand,
getRandomQuoteModule: GetRandomQuote,
pollModule: PollCommand
pollModule: PollCommand,
versionModule: VersionCommand
) {
const commands: ACommand[] = [
//pingpongModule,
Expand All @@ -36,7 +38,8 @@ export class CommandService {
goldModule,
someoneOnceSaidModule,
getRandomQuoteModule,
pollModule
pollModule,
versionModule
];
commands.forEach((command) => {
if (command.data.name && command.execute) {
Expand Down
28 changes: 28 additions & 0 deletions src/modules/command/commands/version.ts
Original file line number Diff line number Diff line change
@@ -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');
});
}
}
10 changes: 10 additions & 0 deletions src/modules/version/module/version.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
17 changes: 17 additions & 0 deletions src/modules/version/service/version.service.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit e26a712

Please sign in to comment.