Skip to content

Commit

Permalink
improve twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobiah committed Jun 4, 2020
1 parent 2eaace6 commit 5f8c589
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ trackableEvents.events.push(...trackableEvents.rss);
const tTemp = [];
twitter.types.forEach((type) => {
twitter.accounts.forEach((account) => {
const id = `twitter.${type}.${account}`;
const id = `twitter.${account}.${type}`;
if (!trackableEvents[`twitter.${type}`]) {
trackableEvents[`twitter.${type}`] = [];
}
Expand Down
4 changes: 3 additions & 1 deletion src/embeds/RSSEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const BaseEmbed = require('./BaseEmbed.js');

const { chunkify, markdinate } = require('../CommonFunctions');

const escapeReserved = (str) => str.replace(/(\(\)\?\+\.)/ig, '\\$1')

/**
* Generates daily deal embeds
*/
Expand All @@ -17,7 +19,7 @@ class RSSEmbed extends BaseEmbed {
super();
// clean up description, falling back to an empty string
let strippedDesc = markdinate((feedItem.description || '\u200B')
.replace(new RegExp(`<strong>${feedItem.title}</strong>`.replace(/(\(\)\+)/g, '\\$1'), 'gm'), ''));
.replace(new RegExp(`<strong>${escapeReserved(feedItem.title)}</strong>`.replace(/(\(\)\+)/g, '\\$1'), 'gm'), ''));
const firstLine = strippedDesc.split('\n')[0].replace(/\*\*/g, '');

if (feedItem.title.includes(firstLine)) {
Expand Down
36 changes: 18 additions & 18 deletions src/embeds/TweetEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ class TweetEmbed extends BaseEmbed {
constructor(bot, tweet) {
super();
this.color = 33972;
this.description = `${tweet.full_text}`;
this.timestamp = `${tweet.created_at}`;
this.url = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`;
this.description = tweet.text;
this.timestamp = new Date(tweet.createdAt);
this.url = tweet.url;

if (tweet.entities.media != null) {
if (tweet.mediaUrl) {
this.image = {
url: `${tweet.entities.media[0].media_url}`,
url: `${tweet.mediaUrl}`,
};
}

if (tweet.in_reply_to_status_id != null) {
this.title = `${tweet.user.name} replied to a Tweet`;
} else if (tweet.quoted_status_id != null && tweet.quoted_status) {
this.title = `${tweet.user.name} retweeted a Tweet from ${tweet.quoted_status.user.name} (@${tweet.quoted_status.user.screen_name})`;
if (tweet.isReply) {
this.title = `${tweet.author.name} replied to a Tweet`;
} else if (tweet.quote) {
this.title = `${tweet.author.name} retweeted a Tweet from ${tweet.quote.author.name} (@${tweet.quote.author.handle})`;
this.fields.push({
name: `${tweet.quoted_status.user.name}`,
value: `${tweet.quoted_status.full_text}`,
name: `${tweet.quote.author.name}`,
value: tweet.quote.text,
});
} else if (tweet.retweeted_status) {
this.title = `${tweet.user.name} retweeted a Tweet from ${tweet.retweeted_status.user.name} (@${tweet.retweeted_status.user.screen_name})`;
this.description = `${tweet.retweeted_status.full_text}`;
} else if (tweet.retweet) {
this.title = `${tweet.user.name} retweeted a Tweet from ${tweet.retweet.author.name} (@${tweet.retweet.author.handle})`;
this.description = `${tweet.retweet.text}`;
} else {
this.title = `${tweet.user.name} Tweeted`;
}

this.footer = {
text: `From @${tweet.user.screen_name}`,
text: `From @${tweet.author.handle}`,
icon_url: 'https://i.imgur.com/CwIRKhh.png',
};

this.author = {
name: `${tweet.user.screen_name}`,
icon_url: `${tweet.user.profile_image_url.replace('_normal.jpg', '.jpg')}`,
url: `https://twitter.com/${tweet.user.screen_name}`,
name: tweet.author.handle,
icon_url: tweet.author.avatar,
url: tweet.author.url,
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/notifications/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function buildNotifiableData(newData, platform, notified) {
streams: newData.news.filter(n => n.stream && !notified.includes(n.id)),
syndicateM: newData.syndicateMissions.filter(m => !notified.includes(m.id)),
tweets: newData.twitter
? newData.twitter.filter(t => t && !notified.includes(t.id))
? newData.twitter.filter(t => t && !notified.includes(t.uniqueId))
: [],
updates: newData.news.filter(n => (n.update || !updtReg.test(n.message))
&& !n.stream && !notified.includes(n.id)),
Expand Down Expand Up @@ -282,7 +282,7 @@ class Notifier {
rawData.arbitration && rawData.arbitration.enemy
? `arbitration:${new Date(rawData.arbitration.expiry).getTime()}`
: 'arbitration:0',
...rawData.twitter.map(t => t.id),
...rawData.twitter.map(t => t.uniqueId),
...(rawData.nightwave.active ? rawData.nightwave.activeChallenges.map(c => c.id) : []),
);

Expand Down Expand Up @@ -516,7 +516,7 @@ class Notifier {

async sendTweets(newTweets, platform) {
await Promise.all(newTweets.map(t => this.broadcaster
.broadcast(new embeds.Tweet({ logger }, t.tweets[0]), platform, t.id)));
.broadcast(new embeds.Tweet({ logger }, t), platform, t.id)));
}

async sendUpdates(newNews, platform) {
Expand Down

0 comments on commit 5f8c589

Please sign in to comment.