-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibot.js
47 lines (33 loc) · 1.15 KB
/
ibot.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
const TeleBot = require('.');
const bot = new TeleBot('');
// On every text message
bot.on('text', msg => {
// discard old message, usefull when the bot start and catch old messages
if (Math.floor(Date.now() / 1000) > msg.date + 120) {
console.log("discarded message (too old) "+msg.text);
return;
}
console.log(msg);
var re = new RegExp("^.url (.*)","i");
var result = msg.text.match(re);
if (result) {
var capture = require('screenshotlayer')('');
capture(result[1], '/tmp/webpage', { width: 2048 }).then(function () {
return msg.reply.photo('/tmp/webpage');
});
}
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('ibot.db.small')
});
lineReader.on('line', function (line,reply) {
var item = line.split(' ');
var re = new RegExp(item[0],"i");
if (msg.text.match(re)) {
reply = item.slice(1).join(' ');
reply = reply.replace(/N~/g, msg.from.username || msg.from.first_name);
reply = reply.replace(/\|/g, "\n");
return bot.sendMessage(msg.chat.id, `${ reply }`);
};
});
});
bot.connect();