From 4b997e5409f728e1705f6079202cef30e056a39a Mon Sep 17 00:00:00 2001 From: chris062689 Date: Sat, 31 Dec 2016 00:49:12 -0500 Subject: [PATCH] Added triggers for regular messages. --- server.js | 15 +++++++++++++++ triggers/github.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 triggers/github.js diff --git a/server.js b/server.js index ac64c96..a319ed5 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,7 @@ var app = require('./app.js'); var data = require('./data.js'); var cachedModules = []; +var cachedTriggers = []; var client = new discord.Client(); function findArray(haystack, arr) { @@ -23,6 +24,11 @@ client.on('ready', () => { cachedModules[file] = require(`./commands/${file}`); }); + // Cache all triggers. + require("fs").readdirSync('./triggers/').forEach(function(file) { + cachedTriggers.push(require(`./triggers/${file}`)); + }); + // Initalize app channels. app.logChannel = client.channels.get(config.logChannel); app.guild = app.logChannel.guild; @@ -80,6 +86,15 @@ client.on('message', message => { } else { // Not a valid command. } + } else { + // This is a normal channel message. + cachedTriggers.forEach(function(trigger) { + if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) { + if (trigger.trigger(message) == true) { + trigger.execute(message); + } + } + }); } }); diff --git a/triggers/github.js b/triggers/github.js new file mode 100644 index 0000000..5fafad4 --- /dev/null +++ b/triggers/github.js @@ -0,0 +1,16 @@ +var app = require('../app.js'); +var logger = require('../logging.js'); + +var regex = /\#\d./; + +exports.trigger = function(message) { + return regex.test(message.content); +} + +exports.execute = function(message) { + var match = regex.exec(message.content); + if (match) { + var msg = `Github Pull Request: https://github.com/citra-emu/citra/pull/${match[0].substring(1).trim()}`; + message.channel.sendMessage(msg); + } +}