-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from BingusBoingus-Developer-Team/dev
Dev
- Loading branch information
Showing
16 changed files
with
155 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CommandInteraction } from 'discord.js'; | ||
|
||
// Role decorator factory | ||
export function Role(requiredRole: CommandAccessLevel) { | ||
return function ( | ||
target, | ||
propertyKey: string, | ||
descriptor: PropertyDescriptor, | ||
) { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = async function (...args) { | ||
const interaction: CommandInteraction = args[0]; | ||
const roles = interaction.guild.roles.cache; | ||
if ( | ||
!roles.has(requiredRole) && | ||
requiredRole !== CommandAccessLevel.member | ||
) { | ||
await interaction.reply({ | ||
content: 'You do not have the required role to execute this command.', | ||
ephemeral: true, | ||
}); | ||
return false; | ||
} | ||
return originalMethod.apply(this, args); | ||
}; | ||
}; | ||
} | ||
|
||
export enum CommandAccessLevel { | ||
Developer = '1265375756637180027', | ||
vip = '484479705148293120', | ||
member = '484479403817173002', | ||
} |
76 changes: 39 additions & 37 deletions
76
src/modules/command/commands/activate-birthday-shoutout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import { | ||
CacheType, | ||
CommandInteraction, | ||
SlashCommandBuilder, | ||
} from 'discord.js'; | ||
import { ACommand } from '../command.abstract'; | ||
import { Inject } from '@nestjs/common'; | ||
import { CacheType, CommandInteraction, SlashCommandBuilder } from 'discord.js'; | ||
import { ACommand } from '../command.abstract'; | ||
import { Inject } from '@nestjs/common'; | ||
import { BirthdayEntryService } from '../../models/birthday/service/birthday-entry.service'; | ||
import { CreateOrUpdateBirthdayEntryDto } from '../../models/birthday/dto/create-or-update-birthday-entry.dto'; | ||
|
||
export default class ActivateBirthdayEntryShoutoutCommand extends ACommand { | ||
constructor( | ||
@Inject(BirthdayEntryService) | ||
private readonly birthdayEntryService: BirthdayEntryService, | ||
) { | ||
super(); | ||
} | ||
data = new SlashCommandBuilder() | ||
.setName('activate-birthday-shoutout') | ||
.setDescription( | ||
'Use this if you want Bingus to shout you out on your birthday (default)!', | ||
); | ||
|
||
async execute(arg: CommandInteraction<CacheType>): Promise<boolean> { | ||
await arg.deferReply(); | ||
const instance: CreateOrUpdateBirthdayEntryDto ={ | ||
username: arg.user.username, | ||
secName: arg.user.displayName, | ||
active: true | ||
}; | ||
const inactive = | ||
await this.birthdayEntryService.updateBirthdayEntry(instance); | ||
if (!inactive) { | ||
await arg.editReply({ content: 'I don\'t know your birthday yet! 🎉'}); | ||
} else { | ||
await arg.editReply({ content: 'You will now receive a birthday shoutout from Bingus! 🎉'}); | ||
} | ||
return true; | ||
import { | ||
CommandAccessLevel, | ||
Role, | ||
} from '../../../common/decoratos/role.decorator'; | ||
|
||
export default class ActivateBirthdayEntryShoutoutCommand extends ACommand { | ||
constructor( | ||
@Inject(BirthdayEntryService) | ||
private readonly birthdayEntryService: BirthdayEntryService, | ||
) { | ||
super(); | ||
} | ||
data = new SlashCommandBuilder() | ||
.setName('activate-birthday-shoutout') | ||
.setDescription( | ||
'Use this if you want Bingus to shout you out on your birthday (default)!', | ||
); | ||
|
||
@Role(CommandAccessLevel.member) | ||
async execute(arg: CommandInteraction<CacheType>): Promise<boolean> { | ||
await arg.deferReply(); | ||
const instance: CreateOrUpdateBirthdayEntryDto = { | ||
username: arg.user.username, | ||
secName: arg.user.displayName, | ||
active: true, | ||
}; | ||
const inactive = | ||
await this.birthdayEntryService.updateBirthdayEntry(instance); | ||
if (!inactive) { | ||
await arg.editReply({ content: "I don't know your birthday yet! 🎉" }); | ||
} else { | ||
await arg.editReply({ | ||
content: 'You will now receive a birthday shoutout from Bingus! 🎉', | ||
}); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters