Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Add Kodi notifications
Browse files Browse the repository at this point in the history
Allow sending of start-up and trade advice to Kodi and derivatives#
  • Loading branch information
billymcintosh authored and askmike committed Jan 13, 2018
1 parent 21961aa commit 085af56
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ var plugins = [
async: false,
modes: ['realtime']
},
{
name: 'Kodi',
description: 'Sends advice to Kodi.',
slug: 'kodi',
async: false,
modes: ['realtime']
},
{
name: 'Twitter',
description: 'Sends trades to twitter.',
Expand Down
68 changes: 68 additions & 0 deletions plugins/kodi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Created by billymcintosh on 24/12/17.
*/

var _ = require('lodash');
var request = require('request');
var log = require('../core/log.js');
var util = require('../core/util.js');
var config = util.getConfig();
var kodiConfig = config.kodi;

var Kodi = function(done) {
_.bindAll(this);

this.exchange = config.watch.exchange.charAt().toUpperCase() + config.watch.exchange.slice(1)

this.price = 'N/A';
this.done = done;
this.setup();
};

Kodi.prototype.setup = function(done) {
var setupKodi = function (err, result) {
if(kodiConfig.sendMessageOnStart) {
var currency = config.watch.currency;
var asset = config.watch.asset;
var title = "Gekko Started";
var message = `Watching ${this.exchange} - ${currency}/${asset}`;
this.mail(title, message);
} else {
log.debug('Skipping Send message on startup')
}
}
setupKodi.call(this)
};

Kodi.prototype.processCandle = function(candle, done) {
this.price = candle.close;

done();
};

Kodi.prototype.processAdvice = function(advice) {
var title = `Gekko: Going ${advice.recommendation} @ ${this.price}`
var message = `${this.exchange} ${config.watch.currency}/${config.watch.asset}`;
this.mail(title, message);
};

Kodi.prototype.mail = function(title, message, done) {
var options = {
body: `{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"${title}","message":"${message}"},"id":1}`,
headers: {
'Content-Type': 'application/json'
},
method: 'POST',
url: kodiConfig.host
}

request(options, (error, response, body) => {
if (!error) {
log.info('Kodi message sent')
} else {
log.debug(`Kodi ${error}`)
}
})
}

module.exports = Kodi;
8 changes: 8 additions & 0 deletions sample-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ config.pushbullet = {
tag: '[GEKKO]'
};

config.kodi = {
// if you have a username & pass, add it like below
// http://user:pass@ip-or-hostname:8080/jsonrpc
host: 'http://ip-or-hostname:8080/jsonrpc',
enabled: false,
sendMessageOnStart: true,
}

config.ircbot = {
enabled: false,
emitUpdates: false,
Expand Down

0 comments on commit 085af56

Please sign in to comment.