Skip to content

Commit

Permalink
/verify regex check
Browse files Browse the repository at this point in the history
  • Loading branch information
Seefaaa committed Sep 15, 2024
1 parent 8608343 commit fc18ad3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/commands/api/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SlashCommandBuilder,
} from 'discord.js';

import { verifyRegex } from '../../constants';
import type { Command } from '../../types';
import { post } from '../../utils';

Expand Down Expand Up @@ -36,6 +37,15 @@ export class VerifyCommand implements Command {
ephemeral: true,
});
} else if (statusCode === 404) {
if (!verifyRegex.test(code)) {
interaction.reply({
content:
'Kod şekille uyuşmuyor, lütfen kodu şekle uygun girin.\nÖrneğin: `/verify 123-456`',
ephemeral: true,
});
return;
}

interaction.reply({ content: 'Kod geçersiz.', ephemeral: true });
} else if (statusCode === 409) {
const conflict = ckey as any as string;
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const verifyRegex = /^\d{3}-\d{3}$/;
3 changes: 2 additions & 1 deletion src/events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Events, type Message } from 'discord.js';

import { verifyRegex } from '../constants';
import type { Event } from '../types';

const GUILD_ID = Bun.env.GUILD_ID;
Expand All @@ -9,7 +10,7 @@ export class MessageCreateEvent implements Event {
public async execute(message: Message) {
if (message.guildId === GUILD_ID) {
const [command, token] = message.content.split(' ');
if (command === '/verify' && /^\d{3}-\d{3}$/.test(token)) {
if (command === '/verify' && verifyRegex.test(token)) {
try {
await message.reply(
'Hesabını doğrulamak için /verify yazdıkdan sonra çıkan komutu kullanman gerek, ayrıca doğrulama kodunu bir başkası ile paylaşmamalısın.'
Expand Down

0 comments on commit fc18ad3

Please sign in to comment.