-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
49 lines (41 loc) · 1.01 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const TelegramBot = require('node-telegram-bot-api');
const Agent = require('socks5-https-client/lib/Agent');
const gulp = require('gulp');
const streamToPromise = require('gulp-stream-to-promise');
const through = require('through2');
const socksHost = process.env.PROXY_SOCKS5_HOST || 'localhost';
const socksPort = parseInt(process.env.PROXY_SOCKS5_PORT || '9050', 10);
const bot = new TelegramBot(process.env.TELEGRAM_TOKEN, {
polling: {
autoStart: false,
},
request: process.env.PROXY_ENABLE && {
agentClass: Agent,
agentOptions: {
socksHost,
socksPort,
},
},
});
async function main() {
await bot.startPolling();
await streamToPromise(
gulp
.src('./dist/*.tdesktop-theme')
.pipe(through.obj(
(file, encoding, cb) => bot
.sendDocument('@BreezeDark', file.path, {
caption: file.relative.split('.')[0],
})
.then(() => cb(), err => cb(err))
))
);
await bot.stopPolling();
}
main().then(
() => process.exit(0),
err => {
console.error(err);
process.exit(1);
},
);