Commit 09a61d5d authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega

Debug logging of original messages, misc prettifying

parent 97300f42
......@@ -63,8 +63,8 @@ export default class Account {
// filtering/transforming by plugins). Needs some normalized data about the
// update, but can include optional metadata as given from the platform.
// This is meant to be called only from subclasses.
emit(data) {
this._callback(this, data);
emit(data, metadata) {
this._callback(this, data, metadata);
return this;
}
......
// import stringify from 'json-stringify-safe';
let lastId = 0;
let fs = require('fs');
if (fs.accessSync('debug/')) {
fs.mkdir('debug/');
}
const maxId = 25 * 25 * 10;
const dictLetters = "abcdefghijkmnopqrstuvwxyz";
......@@ -27,5 +34,9 @@ export function push(data) {
let str = idToString(lastId++ % maxId);
buffer[str] = data;
// fs.writeFile('debug/' + str + '.json', JSON.stringify(data, ' '));
// console.log(data);
fs.writeFile('debug/' + str + '.json', JSON.stringify(data.metadata, null, ' '));
return str;
}
......@@ -150,7 +150,7 @@ class MastodonAccount extends Account {
}
_cleanString(str) {
return striptags( he.decode( str.replace('</p><p>', ' // ') ) );
return striptags( he.decode( str.replace(/<\/p><p>/g, ' // ') ) );
}
// Given a stream descriptor, return a function that handles messages from the stream
......
......@@ -46,7 +46,7 @@ class TwitterAccount extends Account {
// Hackishly listen to the user's main stream
this._stream = this._tw.stream('user', {
replies: "all", // Should explicitly listen to the "replies" channel
// replies: "all", // Should explicitly listen to the "replies" channel
// track: "foo,bar" // Should use this for listening to search terms channels
stall_warnings: true
}, (stream)=>{
......@@ -199,7 +199,10 @@ class TwitterAccount extends Account {
}
// return striptags( he.decode( str.replace('</p><p>', ' // ') ) );
return str.replace('\n', ' // ');
return str.
replace(/\n/g, ' // ').
replace(/&gt;/g, ">").
replace(/&lt;/g, "<");
}
// Given a stream descriptor, return a function that handles messages from the stream
......@@ -226,6 +229,10 @@ class TwitterAccount extends Account {
// console.log('tweet is truncated: ', msg.truncated);
// console.log(msg.entities.urls);
if (msg.retweeted_status) {
msg.text = msg.retweeted_status.text;
}
this.emit({
sender: msg.user.screen_name,
str: this._cleanString(msg.text, msg.entities),
......@@ -245,10 +252,14 @@ class TwitterAccount extends Account {
// this._vorpal.log('Spoiler: ', msg.spoiler_text);
// }
//
if (msg.retweeted_status) {
this._vorpal.log('FIXME: This is a RT/echo of another status (truncated: ', msg.truncated);
// this._normalizeAndEmitUpdate(channel, msg.reblog);
}
// if (msg.retweeted_status) {
// this._vorpal.log('FIXME: This is a RT/echo of another status (truncated: ', msg.truncated, ')');
// // this._normalizeAndEmitUpdate(channel, msg.reblog);
// }
// if (msg.quoted_status) {
// this._vorpal.log('FIXME: This is a quote of another status');
// // this._normalizeAndEmitUpdate(channel, msg.reblog);
// }
}
......
......@@ -23,7 +23,8 @@ const conf = new Configstore('soclial', {
timestamp: 'limegreen',
badge: 'pink',
system: 'purple',
updates: 'gray'
updates: 'gray',
media: 'cyan'
}
},
accounts: {
......@@ -33,11 +34,13 @@ const conf = new Configstore('soclial', {
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) {
......@@ -58,20 +61,26 @@ function handle(account, data, metadata) {
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');
vorpal.log(
'[' + chalk.foreground(timestampColour)(timestampString) + '] ' +
id + '> ' +
chalk.foreground(badgeColour)(badge + '/' + channel) +
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
' ' + chalk.foreground(updateColour)(str)
);
let formattedMedia = '';
if (data.media) {
for(let i=0, l=data.media.length; i<l; i++) {
vorpal.log(chalk.blue('Media:'), data.media[i]);
}
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++) {
// }
}
let formatted = '[' + chalk.foreground(timestampColour)(timestampString) + '] ' +
id + '> ' + chalk.foreground(badgeColour)(badge + '/' + channel) +
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
' ' + chalk.foreground(updateColour)(str) +
formattedMedia;
// Printing out should NOT be synchronous with the handling.
vorpal.log(formatted);
}
......
......@@ -915,7 +915,7 @@ json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1:
dependencies:
jsonify "~0.0.0"
json-stringify-safe@~5.0.1:
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
......
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