Tonight I was finalizing the bot telegram foundation.
Now in the bot http://t.me/thewordgame_bot in the telegram, when it is launched, you can use the / list alexmove command to get data on the required participant (there are 90 participants in total at the moment).
Сегодня вечером я дорабатывал фундамент телеграмм бота.
Теперь в боте http://t.me/thewordgame_bot в телеграмме, когда он запущен, то можно командой /list alexmove получить данные по нужном участнику (всего в списке 90 участников на данный момент).
const TelegramBot = require('node-telegram-bot-api');
let red;
// replace the value below with the Telegram token you receive from @BotFather
const token = 'ххх:ччч';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
function test_c(qu) {
//return red;
}
// Matches "/echo [whatever]"
bot.onText(/\/list (.+)/, (msg, match) => {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the messag
// console.log(match);
// //console.log(match[1]);
const chatId = msg.chat.id;
const resp = match[1]; // the captured "whatever"
bot.sendMessage(chatId, 'Количество баллов у участника:');
bot.sendMessage(chatId, resp);
console.log(resp);
const mysql = require("mysql2");
const connection2 = mysql.createConnection({
host: "localhost",
user: "root",
database: "thewordgame",
password: "ххх"
});
let sql = `SELECT * FROM authors WHERE name='${resp}'` ;
connection2.query(sql, function(err, results) {
if(err) console.log(err);
const users = results;
red = users[0].points;
console.log(red);
console.log(red);
console.log(red);
bot.sendMessage(chatId, red);
});
connection2.end();
});
// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
const chatId = msg.chat.id;
const { id } = msg.chat;
//bot.sendMessage(chatId, msg.text);
// send a message to the chat acknowledging receipt of their message
if (msg.text === "stat1")
{
}
else if (msg.text === "help")
{
bot.sendMessage(chatId, `Подробнее в блоге, посты с пометкой The Word Game https://steemit.com/hive-171319/@alexmove/`);
}
else if (msg.text === "/start")
{
bot.sendMessage(chatId, 'Игра, в которой можно сочинять, общаться, изучать криптовалюту и получать реальное денежное вознаграждение.\n\r\n\r1. Чтобы начать игру, необходимо зарегистрироваться в STEEMIT. Если вы уже зарегистрированы, пришлите свой ник, и система покажет вам общее количество баллов. \n\r\n\r2.Прокомментируйте пользователей \r3.Напишите о себе пост по примеру\n\r\n\r4.Вы можете узнать, какое количество у вас баллов, отправив имя аккаунта - без @ c командой /list \n\r\n\rНапример /list alexmove');
}
else
{
console.log(chatId);
//bot.sendMessage(chatId, 'Пожалуйста, используйте перечисленные команды.');
}
});