Advertisement
mistakirill

Untitled

Oct 4th, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var TelegramBot = require('node-telegram-bot-api');
  2. var exec = require('child_process').exec;
  3. var BOT_TOKEN = '.';
  4. var bot = new TelegramBot(BOT_TOKEN, {polling: true});
  5.  
  6. var photoQueue = [];
  7.  
  8. bot.onText(/\/photo/, function (msg) {
  9. console.log('photo');
  10. photoQueue.push(msg);
  11. takeAndSendPhoto(photoQueue[photoQueue.length - 1]);
  12. });
  13.  
  14. function takeAndSendPhoto(msg) {
  15. bot.sendChatAction(msg.chat.id, 'upload_photo').then(function() {
  16. console.log('take photo');
  17. exec('raspistill -o /home/pi/pi-camera-bot/photos/myphoto%04d.jpg -t 30000 -tl 2000', function photoTaken() {
  18. bot.sendPhoto(msg.chat.id, '/home/pi/pi-camera-bot/photos/myphoto%04d.jpg', {caption: new Date().toLocaleString()}).then(function nextPhoto() {
  19. photoQueue.pop();
  20. if (photoQueue.length > 0) {
  21. takeAndSendPhoto(photoQueue[photoQueue.length - 1]);
  22. }
  23. });
  24. })});
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement