Skip to content

Commit 555d068

Browse files
committed
fix: resolve loadingMsg undefined error in revoke command
- Define loadingMsg outside try block for catch block access - Add safety check before using loadingMsg in error handler - Update CHANGELOG with v1.0.1 release notes
1 parent 1ca9562 commit 555d068

2 files changed

Lines changed: 149 additions & 130 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Unused dependencies: `moment`, `lodash`
2121
- Unused bot wrapper files: `DiscordBot.js`, `TelegramBot.js`
2222

23+
## [1.0.1] - 2026-02-22
24+
25+
### Fixed
26+
27+
- Fixed ESLint configuration module error by renaming `eslint.config.js` to `eslint.config.mjs`
28+
- Fixed all lint errors: unreachable code, undefined variables, duplicate cases, unnecessary try/catch
29+
- Fixed `loadingMsg` undefined errors in multiple command files (info, update, validate, errors, licenses, revoke)
30+
- Fixed duplicate case labels in MessageHandler.js
31+
- Fixed duplicate function definition `handleCreateCallback`
32+
- Fixed `hasOwnProperty` usage to use `Object.prototype.hasOwnProperty.call()`
33+
- Fixed duplicate else-if condition in licenses.js
34+
- Updated test script to use `--passWithNoTests` flag
35+
36+
### Changed
37+
38+
- CI/CD workflow now passes all checks (lint, test, build)
39+
- ESLint configuration now properly recognized as ES module
40+
2341
## [1.0.0] - 2026-02-21
2442

2543
### Added
@@ -52,5 +70,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5270

5371
---
5472

55-
[Unreleased]: https://github.com/licensechain/telegram-bot/compare/v1.0.0...HEAD
73+
[Unreleased]: https://github.com/licensechain/telegram-bot/compare/v1.0.1...HEAD
74+
[1.0.1]: https://github.com/licensechain/telegram-bot/compare/v1.0.0...v1.0.1
5675
[1.0.0]: https://github.com/licensechain/telegram-bot/releases/tag/v1.0.0

src/commands/revoke.js

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
/**
2-
* Revoke License Command (Admin only)
3-
*/
4-
5-
const Validator = require('../utils/Validator');
6-
const PermissionManager = require('../utils/PermissionManager');
7-
8-
module.exports = {
9-
name: 'revoke',
10-
description: 'Revoke a license (Admin only)',
11-
12-
async execute(msg, bot, licenseClient, dbManager) {
13-
const chatId = msg.chat.id;
14-
const userId = msg.from.id;
15-
const args = msg.text.split(' ').slice(1);
16-
17-
const permissionManager = new PermissionManager();
18-
try {
19-
permissionManager.requirePermission(userId, 'admin');
20-
} catch (err) {
21-
await bot.sendMessage(chatId, '❌ ' + (err.message || 'Access denied. Administrators only.'), { parse_mode: 'Markdown' });
22-
return;
23-
}
24-
25-
if (args.length === 0) {
26-
await bot.sendMessage(chatId,
27-
'❌ *Usage:* `/revoke <license_key>`\n\n' +
28-
'Example: `/revoke LC-ABC123-DEF456-GHI789`\n\n' +
29-
'⚠️ *Warning:* This will permanently revoke the license.',
30-
{ parse_mode: 'Markdown' }
31-
);
32-
return;
33-
}
34-
35-
let licenseKey;
36-
try {
37-
licenseKey = Validator.validateLicenseKey(args[0]);
38-
} catch (err) {
39-
await bot.sendMessage(chatId, '❌ ' + Validator.sanitizeForDisplay(err.message), { parse_mode: 'HTML' });
40-
return;
41-
}
42-
43-
// Show loading message (defined outside try to be accessible in catch)
44-
let loadingMsg;
45-
try {
46-
loadingMsg = await bot.sendMessage(chatId, '🔄 Revoking license...');
47-
48-
// First, validate the license exists
49-
const validationResult = await licenseClient.validateLicense(licenseKey);
50-
51-
if (!validationResult.valid && validationResult.reason !== 'License has expired') {
52-
await bot.editMessageText(
53-
`❌ *License Not Found*\n\n` +
54-
`License key \`${licenseKey}\` was not found.\n` +
55-
`Reason: ${validationResult.reason || 'License key not found'}`,
56-
{
57-
chat_id: chatId,
58-
message_id: loadingMsg.message_id,
59-
parse_mode: 'Markdown'
60-
}
61-
);
62-
return;
63-
}
64-
65-
// API supports finding licenses by licenseKey, so we can use the key directly
66-
const licenseId = licenseKey;
67-
68-
try {
69-
const result = await licenseClient.revokeLicense(licenseId);
70-
71-
let message = `✅ *License Revoked*\n\n` +
72-
`*License Key:* \`${licenseKey}\`\n` +
73-
`*Status:* Revoked\n` +
74-
`*Action:* License has been permanently revoked.\n\n` +
75-
`⚠️ This license can no longer be used for validation.`;
76-
77-
await bot.editMessageText(message, {
78-
chat_id: chatId,
79-
message_id: loadingMsg.message_id,
80-
parse_mode: 'Markdown'
81-
});
82-
} catch (revokeError) {
83-
// If API revoke fails, try updating status to REVOKED
84-
console.warn('Direct revoke failed, trying status update:', revokeError.message);
85-
86-
try {
87-
const updateResult = await licenseClient.updateLicense(licenseId, {
88-
status: 'REVOKED'
89-
});
90-
91-
let message = `✅ *License Revoked*\n\n` +
92-
`*License Key:* \`${licenseKey}\`\n` +
93-
`*Status:* Revoked\n` +
94-
`*Action:* License status has been updated to REVOKED.\n\n` +
95-
`⚠️ This license can no longer be used for validation.`;
96-
97-
await bot.editMessageText(message, {
98-
chat_id: chatId,
99-
message_id: loadingMsg.message_id,
100-
parse_mode: 'Markdown'
101-
});
102-
} catch (updateError) {
103-
throw new Error(`Failed to revoke license: ${updateError.message}`);
104-
}
105-
}
106-
107-
} catch (error) {
108-
console.error('Error revoking license:', error);
109-
110-
const errorMessage = `❌ *Revocation Failed*\n\n` +
111-
`An error occurred while revoking the license:\n` +
112-
`\`${error.message}\`\n\n` +
113-
`Please check the license key and try again.`;
114-
115-
// Check if loadingMsg exists before trying to edit it
116-
if (loadingMsg && loadingMsg.message_id) {
117-
await bot.editMessageText(errorMessage, {
118-
chat_id: chatId,
119-
message_id: loadingMsg.message_id,
120-
parse_mode: 'Markdown'
121-
}).catch(() => {
122-
bot.sendMessage(chatId, errorMessage, { parse_mode: 'Markdown' });
123-
});
124-
} else {
125-
await bot.sendMessage(chatId, errorMessage, { parse_mode: 'Markdown' });
126-
}
127-
}
128-
}
129-
};
1+
/**
2+
* Revoke License Command (Admin only)
3+
*/
4+
5+
const Validator = require('../utils/Validator');
6+
const PermissionManager = require('../utils/PermissionManager');
7+
8+
module.exports = {
9+
name: 'revoke',
10+
description: 'Revoke a license (Admin only)',
11+
12+
async execute(msg, bot, licenseClient, dbManager) {
13+
const chatId = msg.chat.id;
14+
const userId = msg.from.id;
15+
const args = msg.text.split(' ').slice(1);
16+
17+
const permissionManager = new PermissionManager();
18+
try {
19+
permissionManager.requirePermission(userId, 'admin');
20+
} catch (err) {
21+
await bot.sendMessage(chatId, '❌ ' + (err.message || 'Access denied. Administrators only.'), { parse_mode: 'Markdown' });
22+
return;
23+
}
24+
25+
if (args.length === 0) {
26+
await bot.sendMessage(chatId,
27+
'❌ *Usage:* `/revoke <license_key>`\n\n' +
28+
'Example: `/revoke LC-ABC123-DEF456-GHI789`\n\n' +
29+
'⚠️ *Warning:* This will permanently revoke the license.',
30+
{ parse_mode: 'Markdown' }
31+
);
32+
return;
33+
}
34+
35+
let licenseKey;
36+
try {
37+
licenseKey = Validator.validateLicenseKey(args[0]);
38+
} catch (err) {
39+
await bot.sendMessage(chatId, '❌ ' + Validator.sanitizeForDisplay(err.message), { parse_mode: 'HTML' });
40+
return;
41+
}
42+
43+
// Show loading message (defined outside try to be accessible in catch)
44+
let loadingMsg;
45+
try {
46+
loadingMsg = await bot.sendMessage(chatId, '🔄 Revoking license...');
47+
48+
// First, validate the license exists
49+
const validationResult = await licenseClient.validateLicense(licenseKey);
50+
51+
if (!validationResult.valid && validationResult.reason !== 'License has expired') {
52+
await bot.editMessageText(
53+
`❌ *License Not Found*\n\n` +
54+
`License key \`${licenseKey}\` was not found.\n` +
55+
`Reason: ${validationResult.reason || 'License key not found'}`,
56+
{
57+
chat_id: chatId,
58+
message_id: loadingMsg.message_id,
59+
parse_mode: 'Markdown'
60+
}
61+
);
62+
return;
63+
}
64+
65+
// API supports finding licenses by licenseKey, so we can use the key directly
66+
const licenseId = licenseKey;
67+
68+
try {
69+
const result = await licenseClient.revokeLicense(licenseId);
70+
71+
let message = `✅ *License Revoked*\n\n` +
72+
`*License Key:* \`${licenseKey}\`\n` +
73+
`*Status:* Revoked\n` +
74+
`*Action:* License has been permanently revoked.\n\n` +
75+
`⚠️ This license can no longer be used for validation.`;
76+
77+
await bot.editMessageText(message, {
78+
chat_id: chatId,
79+
message_id: loadingMsg.message_id,
80+
parse_mode: 'Markdown'
81+
});
82+
} catch (revokeError) {
83+
// If API revoke fails, try updating status to REVOKED
84+
console.warn('Direct revoke failed, trying status update:', revokeError.message);
85+
86+
try {
87+
const updateResult = await licenseClient.updateLicense(licenseId, {
88+
status: 'REVOKED'
89+
});
90+
91+
let message = `✅ *License Revoked*\n\n` +
92+
`*License Key:* \`${licenseKey}\`\n` +
93+
`*Status:* Revoked\n` +
94+
`*Action:* License status has been updated to REVOKED.\n\n` +
95+
`⚠️ This license can no longer be used for validation.`;
96+
97+
await bot.editMessageText(message, {
98+
chat_id: chatId,
99+
message_id: loadingMsg.message_id,
100+
parse_mode: 'Markdown'
101+
});
102+
} catch (updateError) {
103+
throw new Error(`Failed to revoke license: ${updateError.message}`);
104+
}
105+
}
106+
107+
} catch (error) {
108+
console.error('Error revoking license:', error);
109+
110+
const errorMessage = `❌ *Revocation Failed*\n\n` +
111+
`An error occurred while revoking the license:\n` +
112+
`\`${error.message}\`\n\n` +
113+
`Please check the license key and try again.`;
114+
115+
// Check if loadingMsg exists before trying to edit it
116+
if (loadingMsg && loadingMsg.message_id) {
117+
await bot.editMessageText(errorMessage, {
118+
chat_id: chatId,
119+
message_id: loadingMsg.message_id,
120+
parse_mode: 'Markdown'
121+
}).catch(() => {
122+
bot.sendMessage(chatId, errorMessage, { parse_mode: 'Markdown' });
123+
});
124+
} else {
125+
await bot.sendMessage(chatId, errorMessage, { parse_mode: 'Markdown' });
126+
}
127+
}
128+
}
129+
};

0 commit comments

Comments
 (0)