mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-22 04:35:39 +01:00
server: remove trigger system
This commit is contained in:
parent
0b3d67a90c
commit
0887c3b8cb
@ -17,7 +17,6 @@ interface IModuleMap {
|
||||
}
|
||||
|
||||
let cachedModules: IModuleMap = {};
|
||||
let cachedTriggers: any[] = [];
|
||||
const client = new discord.Client();
|
||||
|
||||
const mediaUsers = new Map();
|
||||
@ -173,18 +172,6 @@ client.on('message', message => {
|
||||
}
|
||||
} catch (err) { logger.error(err); }
|
||||
|
||||
} else if (message.author.bot === false) {
|
||||
// This is a normal channel message.
|
||||
cachedTriggers.forEach(function (trigger) {
|
||||
if (!trigger.roles || findArray(message.member.roles.cache.map(x => x.name), trigger.roles)) {
|
||||
if (trigger.trigger(message) === true) {
|
||||
logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
|
||||
try {
|
||||
trigger.execute(message);
|
||||
} catch (err) { logger.error(err); }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -202,9 +189,6 @@ fs.readdirSync('./commands/').forEach(function (file) {
|
||||
}
|
||||
});
|
||||
|
||||
// Cache all triggers.
|
||||
cachedTriggers = [];
|
||||
|
||||
data.readWarnings();
|
||||
data.readBans();
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
const request = require('request');
|
||||
|
||||
const regex = /[^<\\]#(\d+)/ig;
|
||||
|
||||
exports.trigger = function (message) {
|
||||
return new RegExp(regex).test(message.content);
|
||||
};
|
||||
|
||||
exports.execute = function (message) {
|
||||
let matcher = new RegExp(regex);
|
||||
let match = matcher.exec(message.content);
|
||||
let matched = [];
|
||||
let threshold = process.env.GITHUB_OLD_THRESHOLD || 2000;
|
||||
let repo = process.env.GITHUB_REPOSITORY || "citra-emu/citra";
|
||||
|
||||
while (match != null) {
|
||||
if (matched.indexOf(match[1]) === -1) {
|
||||
matched.push(match[1]);
|
||||
} else {
|
||||
match = matcher.exec(message.content);
|
||||
continue;
|
||||
}
|
||||
|
||||
// We do not want to automatically match old issues / PRs.
|
||||
// This usually happens when someone messes up pinging another person or
|
||||
// in general conversation.
|
||||
// ex: You're #1!
|
||||
if (match[1] < threshold) { return; }
|
||||
|
||||
// Map domain path to type
|
||||
let map = {'pull': 'Pull Request', 'issues': 'Issue'};
|
||||
|
||||
let url = `https://github.com/${repo}/pull/${match[1]}`;
|
||||
request(url, function (error, response, body) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
// Set path to type of comment (issues/pull)
|
||||
let path = response.request.uri.pathname.split('/')[3];
|
||||
|
||||
message.channel.send(`Github ${map[path]}: ${url}`);
|
||||
}
|
||||
});
|
||||
|
||||
match = matcher.exec(message.content);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user