Skip to content

Instantly share code, notes, and snippets.

@MetzinAround
Last active April 5, 2021 18:32
Show Gist options
  • Save MetzinAround/25b5771564aa7de183391398db52dbef to your computer and use it in GitHub Desktop.
Save MetzinAround/25b5771564aa7de183391398db52dbef to your computer and use it in GitHub Desktop.
Twit media upload error
console.log("Jump in my ride...");
const fs = require('fs')
var MIM = require('mim');
//checking if it's in develop mode for local use
if (process.env.NODE_ENV === "develop") {
require("dotenv").config();
};
// Create an Twitter object to connect to Twitter API
const Twit = require('twit');
// Pulling keys from another file
const config = require('./configN.js');
// Making a Twit object for connection to the API
const T = new Twit(config);
// Setting up a user stream
const stream = T.stream('statuses/filter', { track: '@JustBotPaid' });
// Now looking for tweet events
// See: https://dev.twitter.com/streaming/userstreams
stream.on('tweet', tweetEvent);
// Here a tweet event is triggered!
function tweetEvent(tweet) {
var id = tweet.id_str;
var text = tweet.text;
var name = tweet.user.screen_name;
let regex = /(💰💰💰)/g;
let str = text;
let partyHoppin = str.match(regex) || [];
let feelinRight = partyHoppin.length>0;
console.log(partyHoppin);
console.log(feelinRight);
if ((text.includes('@JustBotPaid') && feelinRight === true)) {
var id = tweet.id_str;
const gifPath = "./justGotPaid.gif"
// Start a reply back to the sender
const replyText = "@"+ name + "‍Check the mirror, lookin' fly!";
// Post that tweet
T.postMediaChunked({file_path: gifPath }, function (err, data, response) {
console.log(data)
});
T.post('statuses/update', { status: replyText, in_reply_to_status_id: id}, tweeted);
// Make sure it worked!
function tweeted(err, reply) {
if (err) {
console.log(err.message);
} else {
console.log('Tweeted: ' + reply.text);
}
}
} else {
console.log("Can't get paid");
}
};
//node schedule
const schedule = require("node-schedule");
const rule = new schedule.RecurrenceRule();
rule.dayOfWeek = 1;
rule.hour = 11;
rule.minute = 30;
rule.tz = "Etc/GMT+4";
function fridayNight()
{
const videoPath = "C:\\GitHub\\DivasLive\\DivasLive\\nsync.mp4";
console.log("It's Friday night and I just Got Paid!");
var b64content = fs.readFileSync(videoPath, { encoding: 'base64' });
var mediaType = MIM.getMIMEType(videoPath);
T.post('media/upload', { media_data: b64content, media_type: mediaType }, function (err, data, response)
{
if(err)
{
console.log(err);
} else
{
console.log(data);
var mediaIdStr = data.media_id_string
var params = { status: "Just got paid!", media_id: [mediaIdStr] };
T.post('statuses/update', params, function (err, data, response)
{
console.log(data);
console.log(err);
});
};
});
};
// const job1 = schedule.scheduleJob(rule, fridayNight);
// job1.on("Just Got Paid!", fridayNight);
fridayNight();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment