Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. const TelegramBot = require('node-telegram-bot-api');
  2.  
  3. // replace the value below with the Telegram token you receive from @BotFather
  4. const token = '514631367:AAEWL06i_C8lxRobeGt-SY4_AGRLqyFcVmM';
  5.  
  6. // Create a bot that uses 'polling' to fetch new updates
  7. const bot = new TelegramBot(token, {polling: true});
  8.  
  9. let notes=[]
  10.  
  11. bot.onText(/напомни (.+) в (.+)/, function (msg, match) {
  12. var userId = msg.from.id;
  13. var text = match[1];
  14. var time = match[2];
  15.  
  16. notes.push( { 'uid':userId, 'time':time, 'text':text } );
  17.  
  18. bot.sendMessage(userId, 'Отлично! Я обязательно напомню :)');
  19. });
  20.  
  21. function CheckTest(){
  22. console.log(notes.length)
  23. for (var i = 0; i < notes.length; i++){
  24. var curDate = new Date().getHours() + ':' + new Date().getMinutes();
  25. if ( notes[i]['time'] == curDate ) {
  26. bot.sendMessage(notes[i]['uid'], 'Напоминаю, что вы должны: '+ notes[i]['text'] + ' сейчас.');
  27. notes.splice(i,1);
  28. }
  29. }
  30. setTimeout(CheckTest, 3000);
  31. }
  32. CheckTest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement