Skip to content

Commit 33f3dfc

Browse files
committed
refactor(tg-bot): unify MessageHandler and Validator license key rules
1 parent 328f1a1 commit 33f3dfc

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/handlers/EventHandler.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Logger = require('../utils/Logger');
2+
const Validator = require('../utils/Validator');
23

34
class EventHandler {
45
constructor(licenseClient) {
@@ -226,8 +227,12 @@ class EventHandler {
226227
}
227228

228229
isLicenseKey(text) {
229-
// Simple license key validation
230-
return text.length === 32 && /^[A-Z0-9]+$/.test(text);
230+
try {
231+
Validator.validateLicenseKey(text);
232+
return true;
233+
} catch (_err) {
234+
return false;
235+
}
231236
}
232237

233238
async handleAdminStats(ctx) {

src/handlers/MessageHandler.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
const Logger = require('../utils/Logger');
7+
const Validator = require('../utils/Validator');
78

89
class MessageHandler {
910
constructor(bot, licenseClient, dbManager, translator) {
@@ -1031,12 +1032,12 @@ class MessageHandler {
10311032
}
10321033

10331034
isLicenseKey(text) {
1034-
// License key format: LC-XXXXXX-XXXXXX-XXXXXX (23 characters)
1035-
// Or simple alphanumeric 32 characters
1036-
if (text.length === 23 && text.startsWith('LC-')) {
1037-
return /^LC-[A-Z0-9]{6}-[A-Z0-9]{6}-[A-Z0-9]{6}$/.test(text);
1035+
try {
1036+
Validator.validateLicenseKey(text);
1037+
return true;
1038+
} catch (_err) {
1039+
return false;
10381040
}
1039-
return text.length === 32 && /^[A-Z0-9]+$/.test(text);
10401041
}
10411042
}
10421043

0 commit comments

Comments
 (0)