Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Masto = require('mastodon')
- var M = new Masto({
- access_token: 'b785072f8caa9b2937d0cd9ee145824801a2d1229a750fd386d65b724b9e7bcb',
- timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
- api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/
- })
- var T = new Masto({
- access_token: 'e31420e330650fa1145269b376d6036085468a136fc3a8753b0d47c0aa29febe',
- timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
- api_url: 'https://mastodon.technology/api/v1/', // optional, defaults to https://mastodon.social/api/v1/
- })
- console.log("~~ Connected to mastodon ~~");
- var Twitter = require('twitter');
- var client = new Twitter({
- consumer_key: 'cwXPM2dIDX2SDPd3doQ27GvoD',
- consumer_secret: '4Mm2yKi8ljfJBkhWR1OiPzgQ7YwZ9fxkiNKHQnlfmmC4Ju7xTd',
- access_token_key: "2751577358-OlOktweLkCwSOFvBCpuMxXkL34WmoSP0yhmdMlk",
- access_token_secret: "IavEhre3NwnliiTznwXQK94PMKggPlY6yoEGNDoZeIcHS"
- });
- console.log("~~ Connected to Twitter ~~")
- var fs = require('fs');
- var posted = JSON.parse(fs.readFileSync('posted.json', 'utf8')) as string[];
- console.log("{Loaded " + posted.length + " collected tweets}");
- setInterval(madecollection, 1000 * 60);
- function madecollection() {
- var sources = ["unity3d", "madewithunity"];
- var rand = Math.floor(Math.random() * sources.length);
- collecttweets(sources[rand]);
- }
- function collecttweets(source: string) {
- console.log("[" + new Date().toString() + "] Checked tweets");
- client.get('statuses/user_timeline', {
- screen_name: source,
- exclude_replies: "true",
- include_rts: "false",
- count: 50
- }, (error: boolean, tweets: any[], response: any) => {
- if (!error) {
- processtweets(tweets);
- }
- else {
- console.log(error);
- }
- });
- }
- function processtweets(tweets: any[]) {
- for (var i = 0; i < tweets.length; i++) {
- let tweet = tweets[i];
- if (posted.lastIndexOf(tweet.id) == -1 && tweet.text.indexOf("RT") == -1 && !tweet.text.startsWith("@")) {
- M.post('statuses', {
- status: tweet.text
- });
- T.post('statuses', {
- status: tweet.text,
- visibility: "unlisted"
- });
- posted.push(tweet.id);
- console.log("[" + new Date().toString() + "] Posted tweet: " + tweet.text);
- var json = JSON.stringify(posted);
- fs.writeFileSync("posted.json", json);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement