Skip to content

Commit

Permalink
feat: new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sanriodev committed Feb 16, 2024
1 parent 335a691 commit e055f19
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/modules/command/command.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
} from 'discord.js';

export abstract class ACommand {
data: SlashCommandBuilder;
data:
| SlashCommandBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;

public abstract execute(
arg: Interaction<CacheType> | CommandInteraction<CacheType>,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/command/command.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CoinflipCommand } from './commands/coinflip';
import { GoldCommand } from './commands/gold';
import SomeoneOnceSaidCommand from './commands/someone-once-said';
import { SomeoneOnceSaidModule } from '../someone-once-said/modules/someone-once-said.module';
import GetRandomQuote from './commands/get-a-quote';

@Module({
providers: [
Expand All @@ -21,6 +22,7 @@ import { SomeoneOnceSaidModule } from '../someone-once-said/modules/someone-once
CoinflipCommand,
GoldCommand,
SomeoneOnceSaidCommand,
GetRandomQuote,
],
imports: [SomeoneOnceSaidModule],
exports: [CommandService],
Expand Down
3 changes: 3 additions & 0 deletions src/modules/command/command.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BugReport } from './commands/bug';
import { CoinflipCommand } from './commands/coinflip';
import { GoldCommand } from './commands/gold';
import SomeoneOnceSaidCommand from './commands/someone-once-said';
import GetRandomQuote from './commands/get-a-quote';

@Injectable()
export class CommandService {
Expand All @@ -21,6 +22,7 @@ export class CommandService {
coinflipModule: CoinflipCommand,
goldModule: GoldCommand,
someoneOnceSaidModule: SomeoneOnceSaidCommand,
getRandomQuoteModule: GetRandomQuote,
) {
const commands: ACommand[] = [
//pingpongModule,
Expand All @@ -31,6 +33,7 @@ export class CommandService {
coinflipModule,
goldModule,
someoneOnceSaidModule,
getRandomQuoteModule,
];
commands.forEach((command) => {
if (command.data.name && command.execute) {
Expand Down
36 changes: 36 additions & 0 deletions src/modules/command/commands/get-a-quote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
CacheType,
CommandInteraction,
EmbedBuilder,
SlashCommandBuilder,
} from 'discord.js';
import { ACommand } from '../command.abstract';
import { SomeoneOnceSaidService } from '../../someone-once-said/services/someone-once-said.service';
import { Inject } from '@nestjs/common';

export default class GetRandomQuote extends ACommand {
constructor(
@Inject(SomeoneOnceSaidService)
private readonly someoneonceSaidService: SomeoneOnceSaidService,
) {
super();
}
data = new SlashCommandBuilder()
.setName('randomquote')
.setDescription('get a random quote of a user');

async execute(arg: CommandInteraction<CacheType>): Promise<boolean> {
const someoneOnceSaid = await this.someoneonceSaidService.getRandomQuote();
if (!someoneOnceSaid) return;
const quoteEmbed = new EmbedBuilder()
.setTitle(
`${someoneOnceSaid.secName ?? someoneOnceSaid.username} once said 🤓`,
)
.setDescription(someoneOnceSaid.phrase)
.setFooter({
text: someoneOnceSaid?.secName ?? someoneOnceSaid.username,
})
.setTimestamp(someoneOnceSaid.createdAt);
arg.reply({ embeds: [quoteEmbed] });
}
}
7 changes: 5 additions & 2 deletions src/modules/command/commands/someone-once-said.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export default class SomeoneOnceSaidCommand extends ACommand {
super();
}
data = new SlashCommandBuilder()
.setName('Quote')
.setDescription('Make it a quote');
.setName('quote')
.setDescription('Make it a quote')
.addStringOption((option) =>
option.setName('phrase').setDescription('What was said'),
);

async execute(arg: CommandInteraction<CacheType>): Promise<boolean> {
let phrase = arg.options.get('phrase');
Expand Down

0 comments on commit e055f19

Please sign in to comment.