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

Bit of cleanup, new README

parent 98c1e77b
`soCLIal` is a NodeJS social networking client with a command-line interface.
It's social, and it's CLI. So, soCLIal.
As of now, soCLIal is buggy, and feature-incomplete. But it allows you to sign into a
`mastodon.social` account and display your home timeline.
### Quickstart
* `git clone` this repo
* Run either `npm install` or `yarn` to fetch dependencies
* If you use NodeJS < v7, run either `npm run-script build` or `yarn build`, then `nodejs dist/soclial.js`
* If you use NodeJS >= v7 (with support for ES2015 and other goodies), run `nodejs src/soclial.js`
Once soCLIal is up and running:
* Type `help` for a list of commands
* Type `accounts add` to add an account using an interactive prompt
......@@ -75,6 +75,7 @@ class MastodonAccount extends Account {
// vorpal.log(chalk.red.bold(err));
// });
/* A update msg looks like:
{ event: 'update',
data:
......@@ -115,7 +116,6 @@ class MastodonAccount extends Account {
*/
});
......@@ -123,28 +123,12 @@ class MastodonAccount extends Account {
}
listen(channel) {
/*
let delay = Number(channel) * 1000;
if (channel === 'day') { delay = 1000 * 3600 * 24; }
if (channel === 'hour') { delay = 1000 * 3600; }
if (channel === 'quarter') { delay = 1000 * 60 * 15; }
if (channel === 'minute') { delay = 1000 * 60; }
if (channel === 'second') { delay = 1000; }
if (delay <= 0) { return; }
let now = Date.now();
let msSinceLastTick = now % delay;
/*
this._timers[ channel ] = setTimeout(()=>{
this.emit({str: 'Tick.', channel: channel, realtime: true});
this._timers[ channel ] = setInterval(()=>{
this.emit({str: 'Tick.', channel: channel, realtime: true});
}, delay);
}, delay - msSinceLastTick);
return this;*/
*/
}
......@@ -158,11 +142,10 @@ class MastodonAccount extends Account {
}
listChannels() {
// return ['day', 'hour', 'quarter', 'minute'];
// return ['home', 'notifications', 'public'];
}
getLastUpdateTimestamp() {
// The clock runs updates real-time, so
// return Date.now();
}
......@@ -173,8 +156,11 @@ class MastodonAccount extends Account {
// Given a stream descriptor, return a function that handles messages from the stream
_getOnStreamMessage(stream) {
return (msg)=>{
// this._vorpal.log(chalk.green(msg));
if (msg.event === 'update') {
this._normalizeAndEmitUpdate(stream, msg.data);
} else if (msg.event === 'notification') {
this._normalizeAndEmitNotification(stream, msg.data);
} else {
this._vorpal.log(chalk.green(msg));
}
......
import Clock from './platforms/clock';
import Vorpal from 'vorpal';
import Configstore from 'configstore';
import chalk from 'chalk256';
// create a Configstore instance with an unique ID e.g.
// Package name and optionally some default values
const conf = new Configstore('soclial', {foo: 'bar', global: {}});
const vorpal = Vorpal();
function handle(str, channel = '', realtime = undefined, timestamp = undefined) {
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
vorpal.log( '[' + chalk.foreground("limegreen")(timestampString) + '] ' + chalk.red(channel) + ': ' + chalk.gray(str) );
}
let myClock = new Clock(handle);
myClock.listen('minute');
myClock.listen(10);
// Command: foo
vorpal
.command('foo', 'Outputs "bar".')
.action(function(args, callback) {
this.log('bar');
callback();
});
// Command: config
vorpal
.command('config [key] [value]', 'Sets a configuration value, or outputs the current configuration values when no configuration key is specified.')
.action(function(args, callback) {
if (args.key === undefined) {
this.log( chalk.purple('>>> Listing current configuration:'));
for (let i in conf.global) {
this.log( chalk.cyan(i) + ': ' + chalk.cyan(conf.global[i]))
}
} else if (args.value) {
this.log(
chalk.purple('>>> Setting configuration value ') +
chalk.cyan(args.key) +
chalk.purple(': ') +
chalk.cyan(conf.global[args.key]) +
chalk.purple(' → ') +
chalk.cyan(conf.global[args.key] = args.value)
);
} else {
this.log(
chalk.purple('>>> Deleting configuration value ') +
chalk.cyan(args.key);
);
}
callback();
});
// Init main loop.
vorpal
.delimiter('soCLIal> ')
.show();
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