Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 68d5d73

Browse files
committed
Brush code (use 4 spaces)
1 parent 40b694a commit 68d5d73

19 files changed

+1279
-1310
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ Import `telebot` module and create a new bot object:
3838
const TeleBot = require('telebot');
3939

4040
const bot = new TeleBot({
41-
token: 'TELEGRAM_BOT_TOKEN', // Required. Telegram Bot API token.
42-
polling: { // Optional. Use polling.
43-
interval: 1000, // Optional. How often check updates (in ms).
44-
timeout: 0, // Optional. Update polling timeout (0 - short polling).
45-
limit: 100, // Optional. Limits the number of updates to be retrieved.
46-
retryTimeout: 5000, // Optional. Reconnecting timeout (in ms).
47-
allowedUpdates: [], // Optional. List the types of updates you want your bot to receive. Specify an empty list to receive all updates.
48-
proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used (supports Basic Auth).
49-
},
50-
webhook: { // Optional. Use webhook instead of polling.
51-
key: '__YOUR_KEY__.pem', // Optional. Private key for server.
52-
cert: '__YOUR_CERT__.pem', // Optional. Public key.
53-
url: 'https://....', // HTTPS url to send updates to.
54-
host: '0.0.0.0', // Webhook server host.
55-
port: 443 // Server port.
56-
},
57-
usePlugins: ['shortReply'], // Optional. Use build-in plugins from /plugins folder.
58-
plugins: { // Optional. Plugin configuration.
59-
// myPluginName: {
60-
// data: 'my custom value'
61-
// }
41+
token: 'TELEGRAM_BOT_TOKEN', // Required. Telegram Bot API token.
42+
polling: { // Optional. Use polling.
43+
interval: 1000, // Optional. How often check updates (in ms).
44+
timeout: 0, // Optional. Update polling timeout (0 - short polling).
45+
limit: 100, // Optional. Limits the number of updates to be retrieved.
46+
retryTimeout: 5000, // Optional. Reconnecting timeout (in ms).
47+
allowedUpdates: [], // Optional. List the types of updates you want your bot to receive. Specify an empty list to receive all updates.
48+
proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used (supports Basic Auth).
49+
},
50+
webhook: { // Optional. Use webhook instead of polling.
51+
key: '__YOUR_KEY__.pem', // Optional. Private key for server.
52+
cert: '__YOUR_CERT__.pem', // Optional. Public key.
53+
url: 'https://....', // HTTPS url to send updates to.
54+
host: '0.0.0.0', // Webhook server host.
55+
port: 443 // Server port.
56+
},
57+
usePlugins: ['shortReply'], // Optional. Use build-in plugins from /plugins folder.
58+
pluginConfig: { // Optional. Plugin configuration.
59+
// myPluginName: {
60+
// data: 'my custom value'
61+
// }
6262
}
6363
});
6464
```

examples/KittyBot.js

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
11
/*
22
KittyBot
33
Shows random Kitty pictures and gifs.
4-
See this code in action, by visiting @KittyBot on Telegram!
54
*/
65

76
const TeleBot = require('../');
8-
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
7+
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
98

109
// Great API for this bot
1110
const API = 'https://thecatapi.com/api/images/get?format=src&type=';
1211

1312
// Command keyboard
1413
const markup = bot.keyboard([
15-
['/kitty', '/kittygif']
16-
], { resize: true, once: false });
14+
['/kitty', '/kittygif']
15+
], {resize: true, once: false});
1716

1817
// Log every text message
19-
bot.on('text', function(msg) {
20-
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
18+
bot.on('text', function (msg) {
19+
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
2120
});
2221

2322
// On command "start" or "help"
24-
bot.on(['/start', '/help'], function(msg) {
23+
bot.on(['/start', '/help'], function (msg) {
2524

26-
return bot.sendMessage(msg.chat.id,
27-
'😺 Use commands: /kitty, /kittygif and /about', { markup }
28-
);
25+
return bot.sendMessage(msg.chat.id,
26+
'😺 Use commands: /kitty, /kittygif and /about', {markup}
27+
);
2928

3029
});
3130

3231
// On command "about"
33-
bot.on('/about', function(msg) {
32+
bot.on('/about', function (msg) {
3433

35-
let text = '😽 This bot is powered by TeleBot library ' +
36-
'https://github.com/kosmodrey/telebot Go check the source code!';
34+
let text = '😽 This bot is powered by TeleBot library ' +
35+
'https://github.com/kosmodrey/telebot Go check the source code!';
3736

38-
return bot.sendMessage(msg.chat.id, text);
37+
return bot.sendMessage(msg.chat.id, text);
3938

4039
});
4140

4241
// On command "kitty" or "kittygif"
43-
bot.on(['/kitty', '/kittygif'], function(msg) {
44-
45-
let promise;
46-
let id = msg.chat.id;
47-
let cmd = msg.text.split(' ')[0];
48-
49-
// Photo or gif?
50-
if (cmd == '/kitty') {
51-
promise = bot.sendPhoto(id, API + 'jpg', { fileName: 'kitty.jpg' });
52-
} else {
53-
promise = bot.sendDocument(id, API + 'gif', { fileName: 'kitty.gif' });
54-
}
55-
56-
// Send "uploading photo" action
57-
bot.sendAction(id, 'upload_photo');
58-
59-
return promise.catch(error => {
60-
console.log('[error]', error);
61-
// Send an error
62-
bot.sendMessage(id, `😿 An error ${ error } occurred, try again.`);
63-
});
42+
bot.on(['/kitty', '/kittygif'], function (msg) {
43+
44+
let promise;
45+
let id = msg.chat.id;
46+
let cmd = msg.text.split(' ')[0];
47+
48+
// Photo or gif?
49+
if (cmd == '/kitty') {
50+
promise = bot.sendPhoto(id, API + 'jpg', {fileName: 'kitty.jpg'});
51+
} else {
52+
promise = bot.sendDocument(id, API + 'gif', {fileName: 'kitty.gif'});
53+
}
54+
55+
// Send "uploading photo" action
56+
bot.sendAction(id, 'upload_photo');
57+
58+
return promise.catch(error => {
59+
console.log('[error]', error);
60+
// Send an error
61+
bot.sendMessage(id, `😿 An error ${ error } occurred, try again.`);
62+
});
6463

6564
});
6665

examples/edit-caption.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
'use strict';
2-
31
const TeleBot = require('../');
4-
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
2+
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
53

64
var lastMessage;
7-
var photoUrl = 'https://telegram.org/img/tl_card_destruct.gif'
5+
var photoUrl = 'https://telegram.org/img/tl_card_destruct.gif';
86

97
bot.on('/start', msg => {
108

11-
// Send image with caption
12-
return bot.sendPhoto(
13-
msg.from.id, photoUrl, { caption: 'This is a default caption.' }
14-
).then(re => {
15-
// Get message id and chat
16-
lastMessage = [msg.from.id, re.result.message_id];
17-
bot.sendMessage(msg.from.id, 'Now set a new caption using /edit <caption>');
18-
});
9+
// Send image with caption
10+
return bot.sendPhoto(
11+
msg.from.id, photoUrl, {caption: 'This is a default caption.'}
12+
).then(re => {
13+
// Get message id and chat
14+
lastMessage = [msg.from.id, re.result.message_id];
15+
bot.sendMessage(msg.from.id, 'Now set a new caption using /edit <caption>');
16+
});
1917

2018
});
2119

2220
bot.on('/edit', msg => {
2321

24-
if (!lastMessage)
25-
return bot.sendMessage(msg.from.id, 'Type /start and then /edit <caption>');
22+
if (!lastMessage)
23+
return bot.sendMessage(msg.from.id, 'Type /start and then /edit <caption>');
2624

27-
let [chatId, messageId] = lastMessage;
28-
let caption = msg.text.replace('/edit ', '');
25+
let [chatId, messageId] = lastMessage;
26+
let caption = msg.text.replace('/edit ', '');
2927

30-
if (caption == '/edit') caption = 'No caption.';
28+
if (caption == '/edit') caption = 'No caption.';
3129

32-
// Change caption
33-
return bot.editCaption({ chatId, messageId }, caption).then(x => {
34-
bot.sendMessage(msg.from.id, `Caption changed to: ${ caption }`);
35-
});
30+
// Change caption
31+
return bot.editCaption({chatId, messageId}, caption).then(() => {
32+
bot.sendMessage(msg.from.id, `Caption changed to: ${ caption }`);
33+
});
3634

3735
});
3836

examples/edit-markup.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
1-
'use strict';
2-
31
const TeleBot = require('../');
4-
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
2+
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
53

64
var lastMessage;
75

86
bot.on('/start', msg => {
97

10-
const markup = updateKeyboard('apples');
8+
const markup = updateKeyboard('apples');
119

12-
return bot.sendMessage(
13-
msg.from.id, 'This is a editMarkup example. So, apples or oranges?', { markup }
14-
).then(re => {
15-
// Start updating message
16-
lastMessage = [msg.from.id, re.result.message_id];
17-
});
10+
return bot.sendMessage(
11+
msg.from.id, 'This is a editMarkup example. So, apples or oranges?', {markup}
12+
).then(re => {
13+
// Start updating message
14+
lastMessage = [msg.from.id, re.result.message_id];
15+
});
1816

1917
});
2018

2119
// On button callback
2220
bot.on('callbackQuery', msg => {
2321

24-
// Send confirm
25-
bot.answerCallback(msg.id);
22+
// Send confirm
23+
bot.answerCallback(msg.id);
2624

27-
if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
25+
if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
2826

29-
const data = msg.data;
30-
const [chatId, messageId] = lastMessage;
31-
const markup = updateKeyboard(msg.data);
27+
const data = msg.data;
28+
const [chatId, messageId] = lastMessage;
29+
const markup = updateKeyboard(data);
3230

33-
// Edit message markup
34-
return bot.editMarkup({ chatId, messageId }, { markup });
31+
// Edit message markup
32+
return bot.editMarkup({chatId, messageId}, {markup});
3533

3634
});
3735

3836
bot.start();
3937

4038
// Returns keyboard markup
4139
function updateKeyboard(fruit) {
42-
43-
let apples = 'apples';
44-
let oranges = 'oranges';
45-
46-
if (fruit == 'apples') {
47-
apples = `==> ${ apples } <==`;
48-
} else {
49-
oranges = `==> ${ oranges } <==`;
50-
}
51-
52-
return bot.inlineKeyboard([
53-
[
54-
bot.inlineButton(apples, { callback: 'apples' }),
55-
bot.inlineButton(oranges, { callback: 'oranges' })
56-
]
57-
]);
40+
41+
let apples = 'apples';
42+
let oranges = 'oranges';
43+
44+
if (fruit == 'apples') {
45+
apples = `==> ${ apples } <==`;
46+
} else {
47+
oranges = `==> ${ oranges } <==`;
48+
}
49+
50+
return bot.inlineKeyboard([
51+
[
52+
bot.inlineButton(apples, {callback: 'apples'}),
53+
bot.inlineButton(oranges, {callback: 'oranges'})
54+
]
55+
]);
5856

5957
}

examples/edit-text.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
'use strict';
2-
31
const TeleBot = require('../');
4-
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
2+
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
53

64
bot.on('/time', msg => {
75

8-
return bot.sendMessage(msg.from.id, 'Getting time...').then(re => {
9-
// Start updating message
10-
updateTime(msg.from.id, re.result.message_id);
11-
});
6+
return bot.sendMessage(msg.from.id, 'Getting time...').then(re => {
7+
// Start updating message
8+
updateTime(msg.from.id, re.result.message_id);
9+
});
1210

1311
});
1412

1513
function updateTime(chatId, messageId) {
1614

17-
// Update every second
18-
setInterval(x => {
19-
bot.editText(
20-
{ chatId, messageId }, `<b>Current time:</b> ${ time() }`,
21-
{ parse: 'html' }
22-
).catch(error => console.log('Error:', error));
23-
}, 1000);
15+
// Update every second
16+
setInterval(x => {
17+
bot.editText(
18+
{chatId, messageId}, `<b>Current time:</b> ${ time() }`,
19+
{parse: 'html'}
20+
).catch(error => console.log('Error:', error));
21+
}, 1000);
2422

2523
}
2624

2725
bot.start();
2826

2927
// Get current time
3028
function time() {
31-
return new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
29+
return new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
3230
}

examples/hello-world.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
31
const TeleBot = require('../');
4-
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
2+
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
53

64
// On every text message
75
bot.on('text', msg => {
8-
let id = msg.from.id;
9-
let text = msg.text;
10-
return bot.sendMessage(id, `You said: ${ text }`);
6+
let id = msg.from.id;
7+
let text = msg.text;
8+
return bot.sendMessage(id, `You said: ${ text }`);
119
});
1210

1311
bot.connect();

0 commit comments

Comments
 (0)