Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //libs
- const TelegramBot = require('node-telegram-bot-api');
- const colors = require('colors');
- const mysql = require('mysql');
- ///////////////////////////////////////////////
- //var/k
- const token = '532359018:AAFDAgt2yVSy0b7YTvGTbUOt0nIzDAOdOp4';
- const bot = new TelegramBot(token, {polling: true});
- //configurazioni
- const con = mysql.createConnection({
- host: "localhost",
- user: "tg",
- password: "tgBBot",
- database: "tg_fmg_bot"
- });
- bot.on('message', (msg) => {
- const prim = {
- reply_to_message_id: msg.message_id,
- reply_markup: JSON.stringify({
- keyboard: [
- ['📃 Minigames list 📃'],
- ['💲 Points 💲']
- ]
- })
- };
- const help = {
- reply_to_message_id: msg.message_id,
- reply_markup: JSON.stringify({
- keyboard: [
- ['❓ Help ❓'],
- ]
- })
- };
- const mglist = {
- reply_to_message_id: msg.message_id,
- reply_markup: JSON.stringify({
- keyboard: [
- ['test'],
- ]
- })
- };
- const tris = {
- reply_to_message_id: msg.message_id,
- reply_markup: JSON.stringify({
- keyboard: [
- [' ❌ \n'],
- [' ⭕️ '],
- [' ⭕️ '],
- [' ❌ '],
- [' ❌ '],
- [' ⭕️ '],
- [' ⭕️ '],
- [' ⭕️ '],
- [' ❌ ']
- ]
- })
- };
- //prevenzione spam altri bot
- if (msg.from.is_bot == true) {
- return;
- }
- //log utente messaggio
- //console.log(msg.from.first_name.red + ' ' + msg.from.last_name.red + ' (' + msg.from.username.green + ') : ' + msg.text.magenta);
- console.log(msg.from.username.green + ' : ' + msg.text.magenta);
- /////////////////////////////////
- if (msg.text.toString().toLowerCase().indexOf("/start") === 0) {
- bot.sendMessage(msg.chat.id,"Minigames BOT\nType /help to become smarter\n\nBy Manuel Urbano\nNeed help? @FrAgOrDiE",help);
- var sql = "SELECT username FROM `utenti` WHERE user_uid = " + msg.from.id + ";";
- con.query(sql, function (err, result) {
- if (err) {
- throw err;
- }
- if (result.length === 1) {
- return;
- } else {
- sql = "insert into utenti (user_uid, chat_uid, username, type) values ('" + msg.from.id + "', '" + msg.chat.id + "', '@" + msg.chat.username + "', '" + msg.chat.type + "');";
- con.query(sql, function (err, dt) {
- if (err) {
- console.log("Errore:" + err);
- }
- console.log("Tabelle aggiornate");
- });
- }
- });
- }
- else if (msg.text.toString().toLowerCase().indexOf("/help") === 0 || msg.text == "❓ Help ❓") {
- bot.sendMessage(msg.chat.id,"Choose: ",prim);
- }
- else if (msg.text == "💲 Points 💲") {
- var sql = "SELECT punti FROM `utenti` WHERE user_uid = " + msg.from.id + ";";
- con.query(sql, function (err, punti) {
- if (punti == "") {
- bot.sendMessage(msg.chat.id, "Your user is not register in our database yet, type /start");
- }
- else {
- bot.sendMessage(msg.chat.id, "You got " + punti[0].punti + " points");
- }
- });
- }
- else if (msg.text == "📃 Minigames list 📃") {
- bot.sendMessage(msg.chat.id,"Choose: ",mglist);
- }
- else if (msg.text == "test") {
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the first round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a'
- },{
- text: ' ',
- callback_data: '1b'
- },{
- text: ' ',
- callback_data: '1c'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a'
- },{
- text: ' ',
- callback_data: '2b'
- },{
- text: ' ',
- callback_data: '2c'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a'
- },{
- text: ' ',
- callback_data: '3b'
- },{
- text: ' ',
- callback_data: '3c'
- }
- ]]
- }
- });
- bot.on('callback_query', function onCallbackQuery(callbackQuery) {
- const action = callbackQuery.data;
- const msg = callbackQuery.message;
- const opts = {
- chat_id: msg.chat.id,
- message_id: msg.message_id,
- };
- let text;
- switch (action) {
- case '1a':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ❌ ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '1b':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ❌ ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '1c':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ❌ ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '2a':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ❌ ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '2b':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ❌ ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '2c':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ❌ ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '3a':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ❌ ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '3b':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ❌ ',
- callback_data: '3b2'
- },{
- text: ' ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- case '3c':
- bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
- reply_markup: {
- inline_keyboard: [[
- {
- text: ' ',
- callback_data: '1a2'
- },{
- text: ' ',
- callback_data: '1b2'
- },{
- text: ' ',
- callback_data: '1c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '2a2'
- },{
- text: ' ',
- callback_data: '2b2'
- },{
- text: ' ',
- callback_data: '2c2'
- }
- ],
- [
- {
- text: ' ',
- callback_data: '3a2'
- },{
- text: ' ',
- callback_data: '3b2'
- },{
- text: ' ❌ ',
- callback_data: '3c2'
- }
- ]]
- }
- });
- break;
- }
- });
- }
- else {
- bot.sendMessage(msg.chat.id, "This command doesn't exist in my little robotic brain ^^ try typying /help");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement