Added triggers for regular messages.

This commit is contained in:
chris062689 2016-12-31 00:49:12 -05:00
parent 2dbe3421af
commit 4b997e5409
2 changed files with 31 additions and 0 deletions

View file

@ -8,6 +8,7 @@ var app = require('./app.js');
var data = require('./data.js'); var data = require('./data.js');
var cachedModules = []; var cachedModules = [];
var cachedTriggers = [];
var client = new discord.Client(); var client = new discord.Client();
function findArray(haystack, arr) { function findArray(haystack, arr) {
@ -23,6 +24,11 @@ client.on('ready', () => {
cachedModules[file] = require(`./commands/${file}`); cachedModules[file] = require(`./commands/${file}`);
}); });
// Cache all triggers.
require("fs").readdirSync('./triggers/').forEach(function(file) {
cachedTriggers.push(require(`./triggers/${file}`));
});
// Initalize app channels. // Initalize app channels.
app.logChannel = client.channels.get(config.logChannel); app.logChannel = client.channels.get(config.logChannel);
app.guild = app.logChannel.guild; app.guild = app.logChannel.guild;
@ -80,6 +86,15 @@ client.on('message', message => {
} else { } else {
// Not a valid command. // 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);
}
}
});
} }
}); });

16
triggers/github.js Normal file
View file

@ -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);
}
}