Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.69 KB | None | 0 0
  1. //libs
  2. const TelegramBot = require('node-telegram-bot-api');
  3. const colors = require('colors');
  4. const mysql = require('mysql');
  5. ///////////////////////////////////////////////
  6.  
  7. //var/k
  8. const token = '532359018:AAFDAgt2yVSy0b7YTvGTbUOt0nIzDAOdOp4';
  9. const bot = new TelegramBot(token, {polling: true});
  10.  
  11. //configurazioni
  12. const con = mysql.createConnection({
  13. host: "localhost",
  14. user: "tg",
  15. password: "tgBBot",
  16. database: "tg_fmg_bot"
  17. });
  18.  
  19.  
  20.  
  21.  
  22.  
  23. bot.on('message', (msg) => {
  24.  
  25. const prim = {
  26. reply_to_message_id: msg.message_id,
  27. reply_markup: JSON.stringify({
  28. keyboard: [
  29. ['📃 Minigames list 📃'],
  30. ['💲 Points 💲']
  31. ]
  32. })
  33. };
  34.  
  35. const help = {
  36. reply_to_message_id: msg.message_id,
  37. reply_markup: JSON.stringify({
  38. keyboard: [
  39. ['❓ Help ❓'],
  40. ]
  41. })
  42. };
  43.  
  44. const mglist = {
  45. reply_to_message_id: msg.message_id,
  46. reply_markup: JSON.stringify({
  47. keyboard: [
  48. ['test'],
  49. ]
  50. })
  51. };
  52.  
  53. const tris = {
  54. reply_to_message_id: msg.message_id,
  55. reply_markup: JSON.stringify({
  56. keyboard: [
  57. [' ❌ \n'],
  58. [' ⭕️ '],
  59. [' ⭕️ '],
  60. [' ❌ '],
  61. [' ❌ '],
  62. [' ⭕️ '],
  63. [' ⭕️ '],
  64. [' ⭕️ '],
  65. [' ❌ ']
  66. ]
  67. })
  68. };
  69.  
  70.  
  71.  
  72. //prevenzione spam altri bot
  73. if (msg.from.is_bot == true) {
  74. return;
  75. }
  76. //log utente messaggio
  77. //console.log(msg.from.first_name.red + ' ' + msg.from.last_name.red + ' (' + msg.from.username.green + ') : ' + msg.text.magenta);
  78. console.log(msg.from.username.green + ' : ' + msg.text.magenta);
  79. /////////////////////////////////
  80.  
  81. if (msg.text.toString().toLowerCase().indexOf("/start") === 0) {
  82. bot.sendMessage(msg.chat.id,"Minigames BOT\nType /help to become smarter\n\nBy Manuel Urbano\nNeed help? @FrAgOrDiE",help);
  83.  
  84. var sql = "SELECT username FROM `utenti` WHERE user_uid = " + msg.from.id + ";";
  85. con.query(sql, function (err, result) {
  86. if (err) {
  87. throw err;
  88. }
  89. if (result.length === 1) {
  90. return;
  91. } else {
  92. sql = "insert into utenti (user_uid, chat_uid, username, type) values ('" + msg.from.id + "', '" + msg.chat.id + "', '@" + msg.chat.username + "', '" + msg.chat.type + "');";
  93. con.query(sql, function (err, dt) {
  94. if (err) {
  95. console.log("Errore:" + err);
  96. }
  97.  
  98. console.log("Tabelle aggiornate");
  99. });
  100. }
  101.  
  102. });
  103. }
  104. else if (msg.text.toString().toLowerCase().indexOf("/help") === 0 || msg.text == "❓ Help ❓") {
  105. bot.sendMessage(msg.chat.id,"Choose: ",prim);
  106. }
  107.  
  108. else if (msg.text == "💲 Points 💲") {
  109. var sql = "SELECT punti FROM `utenti` WHERE user_uid = " + msg.from.id + ";";
  110. con.query(sql, function (err, punti) {
  111. if (punti == "") {
  112. bot.sendMessage(msg.chat.id, "Your user is not register in our database yet, type /start");
  113. }
  114. else {
  115. bot.sendMessage(msg.chat.id, "You got " + punti[0].punti + " points");
  116. }
  117. });
  118. }
  119. else if (msg.text == "📃 Minigames list 📃") {
  120. bot.sendMessage(msg.chat.id,"Choose: ",mglist);
  121. }
  122. else if (msg.text == "test") {
  123. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the first round!', {
  124. reply_markup: {
  125. inline_keyboard: [[
  126. {
  127. text: ' ',
  128. callback_data: '1a'
  129. },{
  130. text: ' ',
  131. callback_data: '1b'
  132. },{
  133. text: ' ',
  134. callback_data: '1c'
  135. }
  136. ],
  137. [
  138. {
  139. text: ' ',
  140. callback_data: '2a'
  141. },{
  142. text: ' ',
  143. callback_data: '2b'
  144. },{
  145. text: ' ',
  146. callback_data: '2c'
  147. }
  148. ],
  149. [
  150. {
  151. text: ' ',
  152. callback_data: '3a'
  153. },{
  154. text: ' ',
  155. callback_data: '3b'
  156. },{
  157. text: ' ',
  158. callback_data: '3c'
  159. }
  160. ]]
  161. }
  162. });
  163.  
  164.  
  165. bot.on('callback_query', function onCallbackQuery(callbackQuery) {
  166. const action = callbackQuery.data;
  167. const msg = callbackQuery.message;
  168. const opts = {
  169. chat_id: msg.chat.id,
  170. message_id: msg.message_id,
  171. };
  172. let text;
  173.  
  174. switch (action) {
  175. case '1a':
  176. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  177. reply_markup: {
  178. inline_keyboard: [[
  179. {
  180. text: ' ❌ ',
  181. callback_data: '1a2'
  182. },{
  183. text: ' ',
  184. callback_data: '1b2'
  185. },{
  186. text: ' ',
  187. callback_data: '1c2'
  188. }
  189. ],
  190. [
  191. {
  192. text: ' ',
  193. callback_data: '2a2'
  194. },{
  195. text: ' ',
  196. callback_data: '2b2'
  197. },{
  198. text: ' ',
  199. callback_data: '2c2'
  200. }
  201. ],
  202. [
  203. {
  204. text: ' ',
  205. callback_data: '3a2'
  206. },{
  207. text: ' ',
  208. callback_data: '3b2'
  209. },{
  210. text: ' ',
  211. callback_data: '3c2'
  212. }
  213. ]]
  214. }
  215. });
  216. break;
  217. case '1b':
  218. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  219. reply_markup: {
  220. inline_keyboard: [[
  221. {
  222. text: ' ',
  223. callback_data: '1a2'
  224. },{
  225. text: ' ❌ ',
  226. callback_data: '1b2'
  227. },{
  228. text: ' ',
  229. callback_data: '1c2'
  230. }
  231. ],
  232. [
  233. {
  234. text: ' ',
  235. callback_data: '2a2'
  236. },{
  237. text: ' ',
  238. callback_data: '2b2'
  239. },{
  240. text: ' ',
  241. callback_data: '2c2'
  242. }
  243. ],
  244. [
  245. {
  246. text: ' ',
  247. callback_data: '3a2'
  248. },{
  249. text: ' ',
  250. callback_data: '3b2'
  251. },{
  252. text: ' ',
  253. callback_data: '3c2'
  254. }
  255. ]]
  256. }
  257. });
  258. break;
  259. case '1c':
  260. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  261. reply_markup: {
  262. inline_keyboard: [[
  263. {
  264. text: ' ',
  265. callback_data: '1a2'
  266. },{
  267. text: ' ',
  268. callback_data: '1b2'
  269. },{
  270. text: ' ❌ ',
  271. callback_data: '1c2'
  272. }
  273. ],
  274. [
  275. {
  276. text: ' ',
  277. callback_data: '2a2'
  278. },{
  279. text: ' ',
  280. callback_data: '2b2'
  281. },{
  282. text: ' ',
  283. callback_data: '2c2'
  284. }
  285. ],
  286. [
  287. {
  288. text: ' ',
  289. callback_data: '3a2'
  290. },{
  291. text: ' ',
  292. callback_data: '3b2'
  293. },{
  294. text: ' ',
  295. callback_data: '3c2'
  296. }
  297. ]]
  298. }
  299. });
  300. break;
  301. case '2a':
  302. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  303. reply_markup: {
  304. inline_keyboard: [[
  305. {
  306. text: ' ',
  307. callback_data: '1a2'
  308. },{
  309. text: ' ',
  310. callback_data: '1b2'
  311. },{
  312. text: ' ',
  313. callback_data: '1c2'
  314. }
  315. ],
  316. [
  317. {
  318. text: ' ❌ ',
  319. callback_data: '2a2'
  320. },{
  321. text: ' ',
  322. callback_data: '2b2'
  323. },{
  324. text: ' ',
  325. callback_data: '2c2'
  326. }
  327. ],
  328. [
  329. {
  330. text: ' ',
  331. callback_data: '3a2'
  332. },{
  333. text: ' ',
  334. callback_data: '3b2'
  335. },{
  336. text: ' ',
  337. callback_data: '3c2'
  338. }
  339. ]]
  340. }
  341. });
  342. break;
  343. case '2b':
  344. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  345. reply_markup: {
  346. inline_keyboard: [[
  347. {
  348. text: ' ',
  349. callback_data: '1a2'
  350. },{
  351. text: ' ',
  352. callback_data: '1b2'
  353. },{
  354. text: ' ',
  355. callback_data: '1c2'
  356. }
  357. ],
  358. [
  359. {
  360. text: ' ',
  361. callback_data: '2a2'
  362. },{
  363. text: ' ❌ ',
  364. callback_data: '2b2'
  365. },{
  366. text: ' ',
  367. callback_data: '2c2'
  368. }
  369. ],
  370. [
  371. {
  372. text: ' ',
  373. callback_data: '3a2'
  374. },{
  375. text: ' ',
  376. callback_data: '3b2'
  377. },{
  378. text: ' ',
  379. callback_data: '3c2'
  380. }
  381. ]]
  382. }
  383. });
  384. break;
  385. case '2c':
  386. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  387. reply_markup: {
  388. inline_keyboard: [[
  389. {
  390. text: ' ',
  391. callback_data: '1a2'
  392. },{
  393. text: ' ',
  394. callback_data: '1b2'
  395. },{
  396. text: ' ',
  397. callback_data: '1c2'
  398. }
  399. ],
  400. [
  401. {
  402. text: ' ',
  403. callback_data: '2a2'
  404. },{
  405. text: ' ',
  406. callback_data: '2b2'
  407. },{
  408. text: ' ❌ ',
  409. callback_data: '2c2'
  410. }
  411. ],
  412. [
  413. {
  414. text: ' ',
  415. callback_data: '3a2'
  416. },{
  417. text: ' ',
  418. callback_data: '3b2'
  419. },{
  420. text: ' ',
  421. callback_data: '3c2'
  422. }
  423. ]]
  424. }
  425. });
  426. break;
  427. case '3a':
  428. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  429. reply_markup: {
  430. inline_keyboard: [[
  431. {
  432. text: ' ',
  433. callback_data: '1a2'
  434. },{
  435. text: ' ',
  436. callback_data: '1b2'
  437. },{
  438. text: ' ',
  439. callback_data: '1c2'
  440. }
  441. ],
  442. [
  443. {
  444. text: ' ',
  445. callback_data: '2a2'
  446. },{
  447. text: ' ',
  448. callback_data: '2b2'
  449. },{
  450. text: ' ',
  451. callback_data: '2c2'
  452. }
  453. ],
  454. [
  455. {
  456. text: ' ❌ ',
  457. callback_data: '3a2'
  458. },{
  459. text: ' ',
  460. callback_data: '3b2'
  461. },{
  462. text: ' ',
  463. callback_data: '3c2'
  464. }
  465. ]]
  466. }
  467. });
  468. break;
  469. case '3b':
  470. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  471. reply_markup: {
  472. inline_keyboard: [[
  473. {
  474. text: ' ',
  475. callback_data: '1a2'
  476. },{
  477. text: ' ',
  478. callback_data: '1b2'
  479. },{
  480. text: ' ',
  481. callback_data: '1c2'
  482. }
  483. ],
  484. [
  485. {
  486. text: ' ',
  487. callback_data: '2a2'
  488. },{
  489. text: ' ',
  490. callback_data: '2b2'
  491. },{
  492. text: ' ',
  493. callback_data: '2c2'
  494. }
  495. ],
  496. [
  497. {
  498. text: ' ',
  499. callback_data: '3a2'
  500. },{
  501. text: ' ❌ ',
  502. callback_data: '3b2'
  503. },{
  504. text: ' ',
  505. callback_data: '3c2'
  506. }
  507. ]]
  508. }
  509. });
  510. break;
  511. case '3c':
  512. bot.sendMessage(msg.chat.id,'Let\'s go\nStart the second round!', {
  513. reply_markup: {
  514. inline_keyboard: [[
  515. {
  516. text: ' ',
  517. callback_data: '1a2'
  518. },{
  519. text: ' ',
  520. callback_data: '1b2'
  521. },{
  522. text: ' ',
  523. callback_data: '1c2'
  524. }
  525. ],
  526. [
  527. {
  528. text: ' ',
  529. callback_data: '2a2'
  530. },{
  531. text: ' ',
  532. callback_data: '2b2'
  533. },{
  534. text: ' ',
  535. callback_data: '2c2'
  536. }
  537. ],
  538. [
  539. {
  540. text: ' ',
  541. callback_data: '3a2'
  542. },{
  543. text: ' ',
  544. callback_data: '3b2'
  545. },{
  546. text: ' ❌ ',
  547. callback_data: '3c2'
  548. }
  549. ]]
  550. }
  551. });
  552. break;
  553. }
  554. });
  555. }
  556.  
  557. else {
  558. bot.sendMessage(msg.chat.id, "This command doesn't exist in my little robotic brain ^^ try typying /help");
  559. }
  560.  
  561. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement