Guest User

Untitled

a guest
May 23rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. const login = require('facebook-chat-api');
  2.  
  3. const peshkata = 'GROUP ID HERE';
  4. let email = 'FB USERNAME HERE';
  5. let password = 'FB PASSWORD HERE';
  6.  
  7. login({ email, password }, (err, api) => {
  8. if (err) return console.error(err);
  9.  
  10. // Function which adds a user to the group.
  11. let reAdd = (user, threadId, time) => {
  12. return api.addUserToGroup(user, threadId, (err) => {
  13. if (err) {
  14. // If the request errored try again in an increment from now to a second.
  15. setTimeout(() => reAdd(user, threadId, time + 1000), time + 1000);
  16. return console.error(err);
  17. }
  18. });
  19. };
  20.  
  21. // Listen to events and not only messages. This is to capture leave events.
  22. api.setOptions({ listenEvents: true });
  23.  
  24. // Set listen callback.
  25. api.listen((err, message) => {
  26. // Check for errors.
  27. if (err) return console.error(err);
  28.  
  29. // Check for Secret Peshka.
  30. if (message.threadID !== peshkata) return;
  31.  
  32. // Check for leave event.
  33. if (message.type === 'event' && message.logMessageType === 'log:unsubscribe') {
  34. // Send message.
  35. api.sendMessage('Ne.', message.threadID);
  36.  
  37. // Check if we have the id of the person who left - type safety.
  38. if (message.logMessageData && message.logMessageData.leftParticipantFbId) {
  39. // Queue a re-add.
  40. setTimeout(() => reAdd(message.logMessageData.leftParticipantFbId, message.threadID, 1000), 1000);
  41. return;
  42. }
  43.  
  44. // If we don't have the id of the person who left - this case is impossible.
  45. return api.sendMessage('wtf', message.threadID);
  46. }
  47. });
  48. });
Add Comment
Please, Sign In to add comment