Commit 5ef4ca96 authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega

Splitted stringify, moar media for twitter accs

parent e817c036
......@@ -233,14 +233,26 @@ class TwitterAccount extends Account {
msg.text = msg.retweeted_status.text;
}
let allEntities = Object.assign(
{},
msg.entities || {},
msg.extended_entities || {},
(msg.retweeted_status && msg.retweeted_status.entities) || {},
(msg.retweeted_status && msg.retweeted_status.extended_entities) || {}
);
let allMedia = (allEntities.media && allEntities.media.map(i=>i.media_url_https || i.media_url )) || [];
let str = this._cleanString(msg.text, allEntities);
this.emit({
sender: msg.user.screen_name,
str: this._cleanString(msg.text, msg.entities),
str: str,
// str: msg.text,
channel: 'home',
// realtime: true,
// media: msg.media_attachments.map(i=>i.text_url || i.remote_url),
media: (msg.entities.media && msg.entities.media.map(i=>i.media_url_https || i.media_url )) || [],
media: allMedia,
timestamp: Date.parse(msg.created_at)
}, msg);
} else {
......
......@@ -3,6 +3,7 @@
import * as platforms from './platforms/index'
import * as circularBuffer from './circularBuffer'
import stringify from './stringify'
import Vorpal from 'vorpal';
import inquirer from 'inquirer';
......@@ -37,47 +38,14 @@ vorpal.log(chalk.purple('>>> User configuration file read.'));
/// TODO: split handling (and storing), stringifying, and displaying.
function handle(account, data, metadata) {
let { str, channel, realtime, timestamp } = data;
data.account = account;
data.metadata = metadata;
let id = circularBuffer.push(data);
if (timestamp === undefined) {
timestamp = Date.now();
}
// https://stackoverflow.com/questions/10645994/node-js-how-to-format-a-date-string-in-utc
let timestampString =
new Date(timestamp)
.toISOString()
.replace(/T/, ' ') // replace T with a space
.replace(/\..+/, ''); // delete the dot and everything after
// What's the badge for this platform/account??
let badge = account._opts.badge;
let sender = data.sender;
const timestampColour = conf.get('global.colours.timestamp');
const badgeColour = conf.get('global.colours.badge');
const updateColour = conf.get('global.colours.updates');
const mediaColour = conf.get('global.colours.media');
let formattedMedia = '';
if (data.media && data.media.length) {
formattedMedia = (chalk.foreground(mediaColour)(' Media: ' + data.media.join(' ')));
// for(let i=0, l=data.media.length; i<l; i++) {
// }
}
data.account = account;
let formatted = '[' + chalk.foreground(timestampColour)(timestampString) + '] ' +
id + '> ' + chalk.foreground(badgeColour)(badge + '/' + channel) +
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
' ' + chalk.foreground(updateColour)(str) +
formattedMedia;
let id = circularBuffer.push(data);
data.soclialId = id;
let formatted = stringify(conf, data);
// Printing out should NOT be synchronous with the handling.
vorpal.log(formatted);
......
import chalk from 'chalk256';
// Turns a soCLIal item into a string, prettyfied with chalk.
export default function stringify(conf, item) {
let { str, channel, realtime, timestamp, account } = item;
if (timestamp === undefined) {
timestamp = Date.now();
}
// https://stackoverflow.com/questions/10645994/node-js-how-to-format-a-date-string-in-utc
let timestampString =
new Date(timestamp)
.toISOString()
.replace(/T/, ' ') // replace T with a space
.replace(/\..+/, ''); // delete the dot and everything after
// What's the badge for this platform/account??
let badge = account._opts.badge;
let sender = item.sender;
const timestampColour = conf.get('global.colours.timestamp');
const badgeColour = conf.get('global.colours.badge');
const updateColour = conf.get('global.colours.updates');
const mediaColour = conf.get('global.colours.media');
let formattedMedia = '';
if (item.media && item.media.length) {
formattedMedia = (chalk.foreground(mediaColour)(' Media: ' + item.media.join(' ')));
// for(let i=0, l=item.media.length; i<l; i++) {
// }
}
let formatted = '[' + chalk.foreground(timestampColour)(timestampString) + '] ' +
item.soclialId + '> ' + chalk.foreground(badgeColour)(badge + '/' + channel) +
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
' ' + chalk.foreground(updateColour)(str) +
formattedMedia;
/// TODO: handle quotes (by recursive call)
/// TODO: handle echoes/boosts/RT (by recursive call)
return formatted;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment