Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
drkno committed Jul 21, 2017
0 parents commit 0cc5748
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.json
node_modules
70 changes: 70 additions & 0 deletions freedar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const reddit = require('concierge/reddit');

class FreedarModule {
notify(title, url) {
const apis = this.platform.getIntegrationApis();
for (let int in this.config.listeners) {
const api = apis[int];
for (let thread of this.config.listeners[int]) {
LOG.debug(`Notifying "${int}:${thread}" about a free game.`);
api.sendMessage(title, thread);
api.sendUrl(url, thread);
}
}
}

async checkForGames() {
LOG.debug('Checking for free games.');
const results = await reddit('gamedeals', 200);
const searchTerms = [/[^0-9]100%/i, /free($|[^a-z])/i];
const ignoreTerms = [/\[PSN\]/i, /XBOX/i, /playstation/i, /free (weekend|play|shipping)/i, /[a-z](-)?free/i, /rent/i];
for (let result of results) {
LOG.silly(`Checking title "${result.data.title}".`);
const includeCheck = searchTerms.some(s => s.test(result.data.title));
const excludeCheck = ignoreTerms.some(s => s.test(result.data.title));
if (includeCheck && !excludeCheck) {
if (this.config.notified[result.data.id]) {
LOG.silly('Title already matched.');
}
else {
LOG.silly('Title was a match!');
this.notify(result.data.title, result.data.url);
this.config.notified[result.data.id] = true;
}
}
}
this.timer = setTimeout(this.checkForGames.bind(this), this.config.checkFrequency);
}

load() {
const defaultConfig = {
notified: {},
listeners: {},
checkFrequency: 3600000
};
for (let key in defaultConfig) {
if (!this.config[key]) {
this.config[key] = defaultConfig[key];
}
}
this.checkForGames();
}

unload() {
clearTimeout(this.timer);
}

run(api, event) {
ensure(this.config.listeners, event.event_source, []);
if (!this.config.listeners[event.event_source].includes(event.thread_id)) {
this.config.listeners[event.event_source].push(event.thread_id);
api.sendMessage('Listening for free games.', event.thread_id);
}
else {
this.config.listeners[event.event_source].splice(this.config.listeners[event.event_source].indexOf(event.thread_id), 1);
api.sendMessage('No longer listening for free games.', event.thread_id);
}
}
}

module.exports = new FreedarModule();
9 changes: 9 additions & 0 deletions kassy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "freedar",
"version": "1.0.0",
"startup": "freedar.js",
"command": "freedar",
"help": [
["{{commandPrefix}}freedar", "Subscribe/unsubscribe to free game notifications."]
]
}

0 comments on commit 0cc5748

Please sign in to comment.