Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Masto = require('mastodon')
  2.  
  3. var M = new Masto({
  4.     access_token: 'b785072f8caa9b2937d0cd9ee145824801a2d1229a750fd386d65b724b9e7bcb',
  5.     timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
  6.     api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/
  7. })
  8.  
  9. var T = new Masto({
  10.     access_token: 'e31420e330650fa1145269b376d6036085468a136fc3a8753b0d47c0aa29febe',
  11.     timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
  12.     api_url: 'https://mastodon.technology/api/v1/', // optional, defaults to https://mastodon.social/api/v1/
  13. })
  14.  
  15. console.log("~~ Connected to mastodon ~~");
  16.  
  17. var Twitter = require('twitter');
  18.  
  19. var client = new Twitter({
  20.     consumer_key: 'cwXPM2dIDX2SDPd3doQ27GvoD',
  21.     consumer_secret: '4Mm2yKi8ljfJBkhWR1OiPzgQ7YwZ9fxkiNKHQnlfmmC4Ju7xTd',
  22.     access_token_key: "2751577358-OlOktweLkCwSOFvBCpuMxXkL34WmoSP0yhmdMlk",
  23.     access_token_secret: "IavEhre3NwnliiTznwXQK94PMKggPlY6yoEGNDoZeIcHS"
  24. });
  25.  
  26. console.log("~~ Connected to Twitter ~~")
  27.  
  28. var fs = require('fs');
  29. var posted = JSON.parse(fs.readFileSync('posted.json', 'utf8')) as string[];
  30.  
  31. console.log("{Loaded " + posted.length + " collected tweets}");
  32.  
  33. setInterval(madecollection, 1000 * 60);
  34.  
  35. function madecollection() {
  36.     var sources = ["unity3d", "madewithunity"];
  37.     var rand = Math.floor(Math.random() * sources.length);
  38.     collecttweets(sources[rand]);
  39. }
  40.  
  41. function collecttweets(source: string) {
  42.     console.log("[" + new Date().toString() + "] Checked tweets");
  43.  
  44.     client.get('statuses/user_timeline', {
  45.         screen_name: source,
  46.         exclude_replies: "true",
  47.         include_rts: "false",
  48.         count: 50
  49.     }, (error: boolean, tweets: any[], response: any) => {
  50.         if (!error) {
  51.             processtweets(tweets);
  52.         }
  53.         else {
  54.             console.log(error);
  55.         }
  56.     });
  57. }
  58.  
  59. function processtweets(tweets: any[]) {
  60.     for (var i = 0; i < tweets.length; i++) {
  61.         let tweet = tweets[i];
  62.  
  63.         if (posted.lastIndexOf(tweet.id) == -1 && tweet.text.indexOf("RT") == -1 && !tweet.text.startsWith("@")) {
  64.             M.post('statuses', {
  65.                 status: tweet.text
  66.             });
  67.             T.post('statuses', {
  68.                 status: tweet.text,
  69.                 visibility: "unlisted"
  70.             });
  71.             posted.push(tweet.id);
  72.             console.log("[" + new Date().toString() + "] Posted tweet: " + tweet.text);
  73.  
  74.             var json = JSON.stringify(posted);
  75.             fs.writeFileSync("posted.json", json);
  76.             break;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement