-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
69 lines (51 loc) · 1.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var token = '210636921:AAGruBb2_rONA7y7vScyIjwn3FyGKJL2p-8';
var Bot = require('node-telegram-bot-api');
bot = new Bot(token, {polling: true });
console.log('bot server started...');
var buffer = "";
var note = {};
var err = "";
bot.onText(/^\/start/, function (msg, match) {
bot.sendMessage(msg.chat.id, 'Hi, I’m Tag, an AI-based assistant for Telegram powered by @winthanaung.\n\n You can control me by sending these commands:\n\n /note "your note" - Create your own note.\n /please - Retrieve your saved notes.\n /clear - Clean your notes.\n\nNote:If session expired, the notes are clear automatically.').then(function() {
});
});
bot.onText(/^\/please/, function (msg, match) {
if (note[msg.chat.id] == null)
{
var error = "Oop, you haven't tag anything yet";
bot.sendMessage(msg.chat.id, error).then(function(){
});
}
else {
bot.sendMessage(msg.chat.id, note[msg.chat.id]).then(function() {
});
}
});
bot.onText(/^\/note (.+)$/, function (msg, match) {
if (note[msg.chat.id] == null ) {
note[msg.chat.id] = '\n\n' + msg.text.substring(6).replace('@tagger_bot', '');
}
else {
note[msg.chat.id] += '\n\n' + msg.text.substring(6).replace('@tagger_bot', '');
}
bot.sendMessage(msg.chat.id, note[msg.chat.id]).then(function () {
});
});
bot.onText(/^\/clear/, function (msg, match) {
var clear = match[1];
if (note[msg.chat.id] != null)
{
console.log(1);
if (note[msg.chat.id] !== "" ) {
console.log(note[msg.chat.id].length);
note[msg.chat.id] = null;
}
}
else {
console.log(2);
}
i = 0;
bot.sendMessage(msg.chat.id, 'All notes are clear from System.').then(function() {
});
});
module.exports = bot;