Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
var cnt = 0;
module.exports = new Tp.ChannelClass({
Name: 'TestChannel',
Extends: Tp.PollingTrigger,
interval: 5000,
_init: function() {
this.parent();
cnt++;
console.log('Created Test channel #' + cnt);
},
_onTick: function() {
this.emitEvent([42 + Math.floor(Math.random() * 42)]);
},
_doOpen: function() {
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2017 Silei Xu
//
// See LICENSE for details
const Tp = require('thingpedia');
const URL = 'https://colby.stanford.edu/main/api/bikes/';
module.exports = new Tp.ChannelClass({
Name: 'SearchBikePosts',
_init: function _init(engine, device) {
this.parent();
this._device = device;
this.url = URL;
},
formatEvent: function formatEvent(event, filters) {
// event[0]: filters except price, event[1]: price, event[2]: post_id, event[3]: title
if (event[0] === 400)
return ['Sorry, I don\'t understand.'];
if (event[0] === 404)
return ['Sorry, I couldn\'t find any bike meets your requirements'];
return [
'%s for $%s'.format(event[3], event[1]),
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Andrew Lim
// Xiangyu Yue
//
// See LICENSE for details
const Tp = require('thingpedia');
const POLL_INTERVAL = 60 * 1000; // 1m
// milestones is different from the other triggers because there is no webhook or events API for it
module.exports = new Tp.ChannelClass({
Name: 'GithubMilestonePoller',
Extends: Tp.HttpPollingTrigger,
RequiredCapabilities: ['channel-state'],
interval: POLL_INTERVAL,
_init(engine, state, device, params) {
this.parent(engine, state, device, params);
this._state = state;
this._params = params.slice(0, 1);
this._repoName = this._params[0];
if (!this._repoName)
throw new TypeError("Missing required parameter");
if (this._repoName.indexOf('/') < 0)
this._repoName = device.userName + '/' + this._repoName;
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Shloka Desai
// Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
module.exports = new Tp.ChannelClass({
Name: 'GenericRSSPollingTrigger',
Extends: Tp.RSSPollingTrigger,
RequiredCapabilities: ['channel-state'],
interval: 3 * 3600 * 1000, // 3 hours
_init: function(engine, state, device) {
this.parent(engine, state, device);
this.url = this.device.url;
},
formatEvent(event) {
var title = event[0];
var link = event[1];
return [{
type: 'rdl',
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna
// 2016 Riad S. Wahby - modified to select based on tournament rather than team
//
// See LICENSE for details
const Tp = require('thingpedia');
const deepEqual = require('deep-equal');
const API_KEY = '66m6g836ezfad66s6g7edg79';
const SCHEDULE_URL = 'https://api.sportradar.us/soccer-t2/na/matches/schedule.xml?api_key=' + API_KEY;
const BOXSCORE_URL = 'https://api.sportradar.us/soccer-t2/na/matches/%s/boxscore.xml?api_key=' + API_KEY;
const POLL_INTERVAL = 24 * 3600 * 1000; // 1day
module.exports = new Tp.ChannelClass({
Name: 'SportRadarNATourneySoccerChannel',
Extends: Tp.HttpPollingTrigger,
RequiredCapabilities: ['channel-state'],
interval: POLL_INTERVAL,
_init: function(engine, state, device, params) {
this.parent(engine, state, device);
this.state = state;
this._params = params.slice(0, 1);
this._observedTourney = params[0];
if (!this._observedTourney)
throw new TypeError("Missing required parameter");
this._observedTourneyLC = this._params[0].toLowerCase();
this.filterString = this._params.join('-');
this.url = SCHEDULE_URL;
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Riad S. Wahby
// based on us.sportradar device by Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
const API_KEY = 'qgzkq4q83c3uxxdz4mzhjw5p';
const SCHEDULE_URL = 'https://api.sportradar.us/ncaafb-t1/%d/REG/schedule.json?api_key=' + API_KEY;
const BOXSCORE_URL = 'https://api.sportradar.us/ncaafb-t1/%d/REG/%d/%s/boxscore.json?api_key=' + API_KEY;
module.exports = new Tp.ChannelClass({
Name: 'SportRadarNCAAFBChannel',
RequiredCapabilities: ['channel-state'],
_init: function(engine, state, device, params) {
this.parent(engine, device);
this.state = state;
this._params = params.slice(0, 1);
this._observedTeam = params[0];
if (!this._observedTeam)
throw new TypeError("Missing required parameter");
this.filterString = this._params.join('-');
this._lastStatus = null;
this._scheduledTime = null;
this._awayName = "";
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Vivek Jain
// James Hong
// Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
const TT = require('thingtalk');
const languages = require('./languages.json');
module.exports = new Tp.ChannelClass({
Name: 'YandexDetectLanguageChannel',
_init: function(engine, device, params) {
this.parent();
this._device = device;
this._apiKey = device.apiKey;
},
formatEvent(event) {
var text = event[0];
var lang = event[1];
return ["Detected as %s".format(lang.display || lang)];
},
invokeQuery: function(filters) {
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016 Jacob Baldwin
// Giovanni Campagna
//
// See LICENSE for details
"use strict";
const Tp = require('thingpedia');
const TUMBLR_POSTS_URL = 'https://api.tumblr.com/v2/blog/%s/posts/photo?api_key=%s&filter=text';
const POLL_INTERVAL = 30*60000; // 30 minutes
module.exports = new Tp.ChannelClass({
Name: 'TumblrNewPhotos',
Extends: Tp.HttpPollingTrigger,
RequiredCapabilities: ['channel-state'],
interval: POLL_INTERVAL,
_init: function(engine, state, device, params) {
this.parent(engine, state, device);
this.state = state;
this._params = params;
this.filterString = this._params[0];
this._observedBlog = this._params[0];
if (!this._observedBlog)
throw new TypeError('Missing parameter');
if (this._observedBlog.indexOf('.') < 0)
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna
//
// See LICENSE for details
const Q = require('q');
const Tp = require('thingpedia');
const NFL_API_KEY = 'e8jqhrn3pw2ebddn5bbpctyg';
const NFL_URL = 'https://api.sportradar.us/nfl-t1/%d/%s/%d/%s/%s/summary.json?api_key=e8jqhrn3pw2ebddn5bbpctyg';
const POLL_INTERVAL = 3600 * 1000; // 1h
module.exports = new Tp.ChannelClass({
Name: 'SportRadarNflChannel',
Extends: Tp.HttpPollingTrigger,
interval: POLL_INTERVAL,
_init: function(engine, device, params) {
this.parent();
this._params = params.slice(0, 5);
this.url = String.prototype.format.apply(NFL_URL, this._params);
this.filterString = this._params.join('-');
},
_onResponse: function(response) {
if (!response)
return;
var parsed = JSON.parse(response);
this._inner.sendEvent([this._app.uniqueId, event]);
},
_doOpen: function() {
return this.engine.channels.getNamedPipe('thingengine-app-input', 'w')
.then(function(ch) {
this._inner = ch;
}.bind(this));
},
_doClose: function() {
return this._inner.close();
},
});
const AppNotifyChannel = new Tp.ChannelClass({
Name: 'AppNotifyChannel',
_init: function(engine, app) {
this.parent();
this.engine = engine;
this._app = null;
this._inner = null;
this._listener = this._onEvent.bind(this);
},
_onEvent: function(data) {
var app = data[0];
var event = data[1];
if (app === this._app.uniqueId)
this.emitEvent(event);