Skip to content

Commit fa4b5e6

Browse files
committed
refactor: "Refactored webhook setup and updated bot messages JSON"
1 parent 7d6489e commit fa4b5e6

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/bot/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ export class CopBot {
4949

5050
if (isProduction) {
5151
try {
52-
const result = await this._bot.api.deleteWebhook();
53-
if (result) {
54-
await this._bot.api.getUpdates({ offset: -1 });
55-
}
52+
await this._bot.api.deleteWebhook();
5653
const app = express();
5754
app.use(express.json());
5855
app.post(webhookPath, async (req, res) => {
@@ -81,10 +78,16 @@ export class CopBot {
8178
const port = process.env.PORT || 3000;
8279
app.listen(port, async () => {
8380
logger.info(`Webhook server running on port ${port}`);
84-
await this._bot.api.setWebhook(webhookURL);
85-
const webhookInfo = await this._bot.api.getWebhookInfo();
81+
let webhookInfo = await this._bot.api.getWebhookInfo();
8682
console.log(`Webhook Info: `, webhookInfo);
87-
logger.info(`Webhook set: ${webhookInfo.url}`);
83+
logger.info(`Current Webhook: ${webhookInfo.url}`);
84+
if (!webhookInfo.url) {
85+
logger.info('Setting webhook...');
86+
await this._bot.api.setWebhook(webhookURL);
87+
webhookInfo = await this._bot.api.getWebhookInfo();
88+
console.log(`Updated Webhook Info: `, webhookInfo);
89+
logger.info(`Webhook set: ${webhookInfo.url}`);
90+
}
8891
});
8992
await startBot(mode);
9093
} catch (err: any) {
@@ -94,8 +97,6 @@ export class CopBot {
9497
} else {
9598
try {
9699
await this._bot.api.deleteWebhook();
97-
98-
this._bot.api.getUpdates({ offset: -1 });
99100
await startBot(mode);
100101
} catch (err: any) {
101102
console.error('Error during long-polling mode:', err);

src/utils/jsons/botMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"gorup": "Hello! What can I do?"
2626
},
2727
"commands": {
28-
"private": "Hello! Here's the full list of commands you can use in a private chat with the bot:\n\n### General Commands\n- **/start**: Start interacting with the bot.\n- **/help**: Get help and see the list of available commands.\n- **/commands**: List all commands of the bot.\n- **/date**: Get the current date and time.\n- **/joke**: Get a random joke.\n- **/viewsupportcontact**: View support contact details.\n- **/botinfo**: Get information about the bot.\n\n### Group Management Commands\n- **/rules**: View the group rules.\n- **/codetime**: Says a random word sarcastically or offensively to you or people in the group.\n- **/future**: Get insights about the future.\n- **/groupinfo**: View information about the group.\n- **/report**: Report an issue or a user.\n- **/cancel**: Cancel the current report.\n- **/link**: Generate or view group links.\n- **/adminlist**: View the list of group admins.\n- **/grant**: Grant admin privileges to a user.\n- **/revoke**: Revoke admin privileges from a user.\n- **/pin**: Pin a message in the group.\n- **/unpin**: Unpin the pinned message.\n- **/purge**: Delete a range of messages.\n- **/welcome**: Returns the current group welcome message.\n\n### Moderation Commands\n- **/approved**: Approve a user for special privileges.\n- **/disapproved**: Remove approval for a user.\n- **/approvedlist**: View the list of approved users.\n- **/ban**: Ban a user from the group.\n- **/unban**: Unban a previously banned user.\n- **/warn**: Issue a warning to a user.\n- **/rmwarn**: Remove a warning from a user.\n- **/warns**: Check warnings for a user.\n- **/warnslist**: View the list of all warnings.\n- **/mute**: Mute a user in the group.\n- **/unmute**: Unmute a previously muted user.\n\n### Blacklist Commands\n- **/blacklist**: Add a word or phrase to the blacklist.\n- **/abl**: Add multiple words to the blacklist.\n- **/rmbl**: Remove a word or phrase from the blacklist.\n- **/clrbl**: Clear the blacklist.\n\n### Shahin and Aran-Specific Commands\n- **/shahin**: Trigger Shahin-specific functionality.\n- **/aran**: Trigger Aran-specific functionality.\n\nFeel free to use any of the above commands, and let me know if you need any further assistance!",
28+
"private": "Hello! Here's the full list of commands:\n\nGeneral Commands\n- **/start**: Start interacting with the bot.\n- **/help**: Get help and see the list of available commands.\n- **/commands**: List all commands of the bot.\n- **/date**: Get the current date and time.\n- **/joke**: Get a random joke.\n- **/viewsupportcontact**: View support contact details.\n- **/botinfo**: Get information about the bot.\n\nGroup Management Commands\n- **/rules**: View the group rules.\n- **/codetime**: Says a random word sarcastically or offensively to you or people in the group.\n- **/future**: Get insights about the future.\n- **/groupinfo**: View information about the group.\n- **/report**: Report an issue or a user.\n- **/cancel**: Cancel the current report.\n- **/link**: Generate or view group links.\n- **/adminlist**: View the list of group admins.\n- **/grant**: Grant admin privileges to a user.\n- **/revoke**: Revoke admin privileges from a user.\n- **/pin**: Pin a message in the group.\n- **/unpin**: Unpin the pinned message.\n- **/purge**: Delete a range of messages.\n- **/welcome**: Returns the current group welcome message.\n\nModeration Commands\n- **/approved**: Approve a user for special privileges.\n- **/disapproved**: Remove approval for a user.\n- **/approvedlist**: View the list of approved users.\n- **/ban**: Ban a user from the group.\n- **/unban**: Unban a previously banned user.\n- **/warn**: Issue a warning to a user.\n- **/rmwarn**: Remove a warning from a user.\n- **/warns**: Check warnings for a user.\n- **/warnslist**: View the list of all warnings.\n- **/mute**: Mute a user in the group.\n- **/unmute**: Unmute a previously muted user.\n\nBlacklist Commands\n- **/blacklist**: Add a word or phrase to the blacklist.\n- **/abl**: Add multiple words to the blacklist.\n- **/rmbl**: Remove a word or phrase from the blacklist.\n- **/clrbl**: Clear the blacklist.\n\nShahin and Aran-Specific Commands\n- **/shahin**: Trigger Shahin-specific functionality.\n- **/aran**: Trigger Aran-specific functionality.\n\nFeel free to use any of the above commands, and let me know if you need any further assistance!",
2929
"public": "This command is only available in private chats. Please use it there."
3030
}
3131
}

0 commit comments

Comments
 (0)