-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (51 loc) · 1.77 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
const express = require("express");
const path = require("path");
const TelegramBot = require("node-telegram-bot-api");
const TOKEN = "1322170563:AAHXpoY8tascFs1WKSGc_rOOMwNqh4Y5Wlo";
const server = express();
const bot = new TelegramBot(TOKEN, {
polling: true
});
const port = process.env.PORT || 5000;
const gameName = "youtubeGame";
const queries = {};
server.use(express.static(path.join(__dirname, 'YoutubeTestGame')));
bot.onText(/help/, (msg) => bot.sendMessage(msg.from.id, "This bot implements a T-Rex jumping game. Say /game if you want to play."));
bot.onText(/start|game/, (msg) => bot.sendGame(msg.from.id, gameName));
bot.on("callback_query", function (query) {
if (query.game_short_name !== gameName) {
bot.answerCallbackQuery(query.id, "Sorry, '" + query.game_short_name + "' is not available.");
} else {
queries[query.id] = query;
let gameurl = "https://maxizhukov.github.io/telegram_game_front/";
bot.answerCallbackQuery({
callback_query_id: query.id,
url: gameurl
});
}
});
bot.on("inline_query", function (iq) {
bot.answerInlineQuery(iq.id, [{
type: "game",
id: "0",
game_short_name: gameName
}]);
});
server.get("/highscore/:score", function (req, res, next) {
if (!Object.hasOwnProperty.call(queries, req.query.id)) return next();
let query = queries[req.query.id];
let options;
if (query.message) {
options = {
chat_id: query.message.chat.id,
message_id: query.message.message_id
};
} else {
options = {
inline_message_id: query.inline_message_id
};
}
bot.setGameScore(query.from.id, parseInt(req.params.score), options,
function (err, result) {});
});
server.listen(port);