feature/98-timeout-command-2 (#306)
Some checks failed
continuous-integration/drone/push Build is failing

- Prevent user from trying to time out a bot
- Update time length input to ignore commas

#98

Co-authored-by: Ethan Lane <ethan@vylpes.com>
Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/306
This commit is contained in:
Vylpes 2023-06-30 17:33:04 +01:00
parent eb774aa280
commit 400b4de304
5 changed files with 50 additions and 2 deletions

View file

@ -49,6 +49,11 @@ export default class Timeout extends Command {
return;
}
if (targetUser.user.bot) {
await interaction.reply('Cannot timeout bots.');
return;
}
// General Variables
const targetMember = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : null;

View file

@ -35,4 +35,8 @@ export default class StringTools {
return result;
}
public static ReplaceAll(str: string, find: string, replace: string) {
return str.replace(new RegExp(find, 'g'), replace);
}
}

View file

@ -1,8 +1,10 @@
import StringTools from "./StringTools";
export default class TimeLengthInput {
public readonly value: string;
constructor(input: string) {
this.value = input;
this.value = StringTools.ReplaceAll(input, ',', '');
}
public GetDays(): number {

View file

@ -35,4 +35,4 @@ const client = new CoreClient([
registry.RegisterCommands();
registry.RegisterEvents();
client.start();
client.start();

View file

@ -360,6 +360,43 @@ describe('execute', () => {
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN targetUser is a bot, EXPECT error', async () => {
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
bot: true,
} as User,
member: {} as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m',
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
const command = new Timeout();
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Cannot timeout bots.');
});
test('GIVEN targetMember IS NOT manageable by the bot, EXPECT insufficient permissions error', async () => {
const command = new Timeout();