forked from angrykoala/koalagochi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (88 loc) · 2.72 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use strict";
let TelegramBot = require('node-telegram-bot-api');
let key = process.env.BOT_TOKEN || require('./key.json').key;
let bot = new TelegramBot(key, {
polling: true
});
let pokeCount = {};
bot.onText(/\/start/, function(msg) {
console.log("on text");
let chatId = msg.chat.id;
let opts = {
reply_markup: JSON.stringify({
keyboard: [
['Poke']
],
resize_keyboard: true
})
};
console.log(JSON.stringify(opts));
bot.sendMessage(chatId, "*Sleepy koala is asleep*", opts);
});
bot.onText(/Poke/i, function(msg) {
let chatId = msg.chat.id;
if (!pokeCount[chatId]) pokeCount[chatId] = 0;
pokeCount[chatId]++;
let response = "";
switch (pokeCount[chatId]) {
case 1:
bot.sendMessage(chatId, "Koala is still asleep");
break;
case 2:
bot.sendMessage(chatId, "Stop poking the koala!");
break;
case 3:
bot.sendMessage(chatId, "You are just evil");
break;
case 4:
let opts = {
reply_markup: {
one_time_keyboard: true,
resize_keyboard: true,
keyboard: [
['Feed']
]
}
};
bot.sendMessage(chatId, "Great, you awake the poor koala, you monster", opts);
let photo = __dirname + '/angry_koala.jpg'
bot.sendPhoto(chatId, photo, {
caption: "Angry Koala is Angry!!"
});
break;
default:
bot.sendMessage(chatId, "You really should stop poking koalas");
}
});
bot.onText(/feed/i, function(msg) {
let chatId = msg.chat.id;
pokeCount[chatId] = 0;
let opts = {
caption: "Koala happy, Koala sleepy",
reply_markup: JSON.stringify({
keyboard: [
['Poke']
],
resize_keyboard: true
})
};
let photo = __dirname + '/sleepy_koala.jpg'
bot.sendPhoto(chatId, photo, opts);
});
bot.on('message', function(msg) {
let chatId = msg.chat.id;
console.log(chatId + ": " + JSON.stringify(msg));
});
//FILE EXAMPLE
/*if(typeof(msg.document) !== 'undefined'){
let fileId = msg.document.file_id;
let mimeType = msg.document.mime_type;
if(utils.matchesTorrent(mimeType)){
bot.downloadFile(fileId, "tmp");
bot.sendMessage(chatId, "Just received "+msg.document.file_name+". Should I start downloading it?");
} else {
bot.sendMessage(chatId, "File: \""+msg.document.file_name+"\" is not a torrent file or a magnet link.");
}
} else {
bot.sendMessage(chatId, "Waiting for a torrent or a magnet link.");
}*/