Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ipcMain.on('surfbird:send:tweet', function (e, tweet) {
var tweetLength = twittxt.getTweetLength(tweet.text)
if (tweetLength > 140 && tweet.media.length > 0) {
e.sender.send('surfbird:hook:nosup:tweet')
}
else if (tweetLength > 140) {
var tweetid = tweet.id
var tweets = []
// split the tweet into chunks
var chunks = tweet.text.split(' ').filter(function (it) {
return it.length > 0
})
// calculate mentions
var mentionsLength = 0
var mentions = [] // NOTE: Not using twitter-text function because we only want leading tweets.
while (chunks.length) {
require(__dirname + '/plugins/filter/' + file);
});
filters = require(__dirname + '/plugins/filters.js').filters;
filters.forEach(function(filter) {
text = filter.execute(text);
});
if (TwitterText.getTweetLength(text) <= 140) {
T.post('statuses/update', { status: text }, function(error, data, response) {
if (error) {
console.log('Posting tweet error: ' + error);
}
});
}
else {
channel = rtm.dataStore.getChannelById(message.channel);
web.chat.postMessage(channel.id, "The tweet was too long! Character count: " + TwitterText.getTweetLength(message.text), function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Message sent: ', res);
}
});
channel = null;
} // If message longer than 140 character
});
} // Message type.
} else if (isCashtagEntity(e)) {
console.log("cashtag: ", e.cashtag);
} else {
console.error("Unreachable");
}
console.log(`indices: (${e.indices[0]}, ${e.indices[1]})`);
}
let result: string;
result = twitter.autoLink(text);
result = twitter.autoLinkUsernamesOrLists(text);
result = twitter.autoLinkHashtags(text);
result = twitter.autoLinkCashtags(text);
result = twitter.autoLinkUrlsCustom(text, {targetBlank: true, suppressNoFollow: true});
const len: number = twitter.getTweetLength(text);
const linked: string = twitter.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", {
urlEntities: [
{
url: "http://t.co/0JG5Mcq",
display_url: "blog.twitter.com/2011/05/twitte…",
expanded_url: "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
indices: [
30,
48
]
}
]});
const usernames: string[] = twitter.extractMentions("Mentioning @twitter and @jack");
fs.readdir(__dirname + '/plugins/filter', function (error, files) {
text = message.text;
files.forEach(function (file) {
require(__dirname + '/plugins/filter/' + file);
});
filters = require(__dirname + '/plugins/filters.js').filters;
filters.forEach(function(filter) {
text = filter.execute(text);
});
if (TwitterText.getTweetLength(text) <= 140) {
T.post('statuses/update', { status: text }, function(error, data, response) {
if (error) {
console.log('Posting tweet error: ' + error);
}
});
}
else {
channel = rtm.dataStore.getChannelById(message.channel);
web.chat.postMessage(channel.id, "The tweet was too long! Character count: " + TwitterText.getTweetLength(message.text), function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Message sent: ', res);
}
});
channel = null;
function tweetLength (options, callback) {
var l = require('twitter-text').getTweetLength(options.message);
if (callback) {
callback(null, l);
}
else {
return l;
}
};
characterCount (e) {
var remain = 140 - (twitter.getTweetLength($('.js-compose-tweet').val()) % 140)
var chains = Math.floor(twitter.getTweetLength($('.js-compose-tweet').val()) / 140)
if ($('.js-compose-tweet').val().length > 0) {
$('.js-compose-tweet-btn').attr('disabled', false)
} else {
$('.js-compose-tweet-btn').attr('disabled', true)
}
$('.js-remaining-character-count').text(remain).css('marginLeft', (chains > 0 ? 0 : '10px'))
if(chains > 0) {
$('.js-chained-tweets').text('(' + chains.toString() + ')').css('display', 'inline')
} else {
$('.js-chained-tweets').css('display', 'none')
}
},
sendMessage (e) {
.map(({ tweet }) => this.maxCharacter - getTweetLength(tweet));
}
charactersLeft: function() {
if (this.newTweet.length == 0) return 140
return 140 - twttr.getTweetLength(this.newTweet)
},
isTooLong: function() {
updateExplicitCount: function(status, withMedia) {
this.explicit_count = twitter.getTweetLength(status) + (withMedia ? 24 : 0);
},
characterCount (e) {
var remain = 140 - (twitter.getTweetLength($('.js-compose-tweet').val()) % 140)
var chains = Math.floor(twitter.getTweetLength($('.js-compose-tweet').val()) / 140)
if ($('.js-compose-tweet').val().length > 0) {
$('.js-compose-tweet-btn').attr('disabled', false)
} else {
$('.js-compose-tweet-btn').attr('disabled', true)
}
$('.js-remaining-character-count').text(remain).css('marginLeft', (chains > 0 ? 0 : '10px'))
if(chains > 0) {
$('.js-chained-tweets').text('(' + chains.toString() + ')').css('display', 'inline')
} else {
$('.js-chained-tweets').css('display', 'none')
}
},
sendMessage (e) {