First app iteration
This commit is contained in:
parent
772bb21628
commit
af611366b7
2 changed files with 58 additions and 0 deletions
|
@ -1,2 +1,4 @@
|
|||
# scooterquotebot
|
||||
|
||||
npm install
|
||||
Create .TOKEN with your access token, and npm start.
|
56
app.js
Normal file
56
app.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
var Mastodon = require('mastodon');
|
||||
var Schedule = require('node-schedule');
|
||||
var fs = require('fs');
|
||||
var https = require('https');
|
||||
var m;
|
||||
var ts;
|
||||
|
||||
fs.readFile('.TOKEN', 'utf-8', function(err,data){
|
||||
if (err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
m = new Mastodon({ access_token : data, api_url: 'https://botsin.space/api/v1/' });
|
||||
|
||||
console.log('Tooting Scooter quutes!');
|
||||
ts = Schedule.scheduleJob('1 8 * * 0,3', doQuote);
|
||||
ts = Schedule.scheduleJob('6 13 * * 2,5', doQuote);
|
||||
ts = Schedule.scheduleJob('19 18 * * 1,4', doQuote);
|
||||
ts = Schedule.scheduleJob('31 20 * * 6', doQuote);
|
||||
});
|
||||
|
||||
function doQuote() {
|
||||
https.get('https://howmuchisthe.fish/json/random', (res) => {
|
||||
var dat = '';
|
||||
|
||||
res.setEncoding('utf8');
|
||||
|
||||
res.on('data', (d) => {
|
||||
dat += d;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
try {
|
||||
var js = JSON.parse(dat);
|
||||
tootQuote( js );
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}).on('error', (e) => {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
|
||||
function tootQuote(obj) {
|
||||
if ( obj &&
|
||||
obj.quote &&
|
||||
obj.quote.text )
|
||||
{
|
||||
console.log( 'Tooting: ' + obj.quote.text );
|
||||
var cw = obj.quote.text;
|
||||
var message = "from '" + obj.quote.track + "' on the album '" + obj.quote.album + "'\n" + obj.quote.track_master;
|
||||
m.post('statuses', { status: message, spoiler_text: cw, visibility: 'public' });
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue