mirror of
https://github.com/thelounge/thelounge
synced 2024-11-27 06:20:26 +00:00
Load input plugins at startup and call them directly when a command is received
This commit is contained in:
parent
f81235900b
commit
93a393f10d
15 changed files with 44 additions and 71 deletions
|
@ -48,7 +48,14 @@ var inputs = [
|
|||
"quit",
|
||||
"raw",
|
||||
"topic",
|
||||
];
|
||||
].reduce(function(plugins, name) {
|
||||
var path = "./plugins/inputs/" + name;
|
||||
var plugin = require(path);
|
||||
plugin.commands.forEach(function(command) {
|
||||
plugins[command] = plugin.input;
|
||||
});
|
||||
return plugins;
|
||||
}, {});
|
||||
|
||||
function Client(manager, name, config) {
|
||||
_.merge(this, {
|
||||
|
@ -281,22 +288,9 @@ Client.prototype.input = function(data) {
|
|||
var args = text.split(" ");
|
||||
var cmd = args.shift().toLowerCase();
|
||||
|
||||
var result = inputs.some(function(plugin) {
|
||||
try {
|
||||
var path = "./plugins/inputs/" + plugin;
|
||||
var fn = require(path);
|
||||
return fn.apply(client, [
|
||||
target.network,
|
||||
target.chan,
|
||||
cmd,
|
||||
args
|
||||
]);
|
||||
} catch (e) {
|
||||
console.log(path + ": " + e);
|
||||
}
|
||||
});
|
||||
|
||||
if (result !== true) {
|
||||
if (cmd in inputs) {
|
||||
inputs[cmd].apply(client, [target.network, target.chan, cmd, args]);
|
||||
} else {
|
||||
target.network.irc.write(text);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "slap" && cmd !== "me") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["slap", "me"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var irc = network.irc;
|
||||
|
||||
switch (cmd) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "connect" && cmd !== "server") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["connect", "server"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var client = this;
|
||||
client.connect({
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "invite") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["invite"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var irc = network.irc;
|
||||
|
||||
if (args.length === 2) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "join") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["join"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.join(args[0], args[1]);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "kick") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["kick"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.kick(chan.name, args[0]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "mode" && cmd !== "op" && cmd !== "voice" && cmd !== "deop" && cmd !== "devoice") {
|
||||
return;
|
||||
} else if (args.length === 0) {
|
||||
exports.commands = ["mode", "op", "voice", "deop", "devoice"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
var _ = require("lodash");
|
||||
|
||||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "say" && cmd !== "msg") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["msg", "say"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length === 0 || args[0] === "") {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "nick") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["nick"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.nick(args[0]);
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
var _ = require("lodash");
|
||||
var Msg = require("../../models/msg");
|
||||
|
||||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "notice" || !args[1]) {
|
||||
exports.commands = ["notice"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (!args[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
var _ = require("lodash");
|
||||
|
||||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "part" && cmd !== "leave" && cmd !== "close") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["close", "leave", "part"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (chan.type !== "query") {
|
||||
var irc = network.irc;
|
||||
if (args.length === 0) {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
var _ = require("lodash");
|
||||
|
||||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "quit" && cmd !== "disconnect") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["quit", "disconnect"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var client = this;
|
||||
var irc = network.irc;
|
||||
var quitMessage = args[0] ? args.join(" ") : "";
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "raw" && cmd !== "send" && cmd !== "quote") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["raw", "send", "quote"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.write(args.join(" "));
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "topic") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["topic"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var msg = "TOPIC";
|
||||
msg += " " + chan.name;
|
||||
msg += args[0] ? (" :" + args.join(" ")) : "";
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module.exports = function(network, chan, cmd, args) {
|
||||
if (cmd !== "whois" && cmd !== "query") {
|
||||
return;
|
||||
}
|
||||
exports.commands = ["query", "whois"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.whois(args[0]);
|
||||
|
|
Loading…
Reference in a new issue