mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-22 15:25:46 +01:00
Added triggers for regular messages.
This commit is contained in:
parent
2dbe3421af
commit
4b997e5409
15
server.js
15
server.js
@ -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
16
triggers/github.js
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user