Pass package info around so it can be used as identifier

This commit is contained in:
MiniDigger 2019-10-22 20:03:54 +02:00
parent 8f7bee8dd3
commit dbec8330ce
4 changed files with 15 additions and 11 deletions

View file

@ -374,7 +374,7 @@ Client.prototype.inputLine = function(data) {
if (typeof plugin.input === "function" && (connected || plugin.allowDisconnected)) { if (typeof plugin.input === "function" && (connected || plugin.allowDisconnected)) {
connected = true; connected = true;
plugin.input( plugin.input(
new PublicClient(client), new PublicClient(client, plugin.packageInfo),
{network: target.network, chan: target.chan}, {network: target.network, chan: target.chan},
cmd, cmd,
args args

View file

@ -51,7 +51,10 @@ const getCommands = () =>
.concat(passThroughCommands) .concat(passThroughCommands)
.sort(); .sort();
const addPluginCommand = (command, func) => pluginCommands.set(command, func); const addPluginCommand = (packageInfo, command, func) => {
func.packageInfo = packageInfo;
pluginCommands.set(command, func);
};
module.exports = { module.exports = {
addPluginCommand, addPluginCommand,

View file

@ -27,16 +27,16 @@ module.exports = {
outdated, outdated,
}; };
const packageApis = function(packageName) { const packageApis = function(packageInfo) {
return { return {
Stylesheets: { Stylesheets: {
addFile: addStylesheet.bind(this, packageName), addFile: addStylesheet.bind(this, packageInfo.packageName),
}, },
PublicFiles: { PublicFiles: {
add: addFile.bind(this, packageName), add: addFile.bind(this, packageInfo.packageName),
}, },
Commands: { Commands: {
add: inputs.addPluginCommand, add: inputs.addPluginCommand.bind(this, packageInfo),
runAsUser: (command, targetId, client) => runAsUser: (command, targetId, client) =>
client.inputLine({target: targetId, text: command}), client.inputLine({target: targetId, text: command}),
}, },
@ -98,6 +98,7 @@ function loadPackages() {
} }
packageInfo = packageInfo.thelounge; packageInfo = packageInfo.thelounge;
packageInfo.packageName = packageName;
packageMap.set(packageName, packageFile); packageMap.set(packageName, packageFile);
@ -112,7 +113,7 @@ function loadPackages() {
} }
if (packageFile.onServerStart) { if (packageFile.onServerStart) {
packageFile.onServerStart(packageApis(packageName)); packageFile.onServerStart(packageApis(packageInfo));
} }
log.info(`Package ${colors.bold(packageName)} loaded`); log.info(`Package ${colors.bold(packageName)} loaded`);

View file

@ -1,8 +1,9 @@
const Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = class PublicClient { module.exports = class PublicClient {
constructor(client) { constructor(client, packageInfo) {
this.client = client; this.client = client;
this.packageInfo = packageInfo;
} }
/** /**
@ -45,16 +46,15 @@ module.exports = class PublicClient {
* *
* @param {String} text the message to send * @param {String} text the message to send
* @param {Chan} chan the channel to send the message to * @param {Chan} chan the channel to send the message to
* @param {String} identifier the identifier/name of the packages that is sending this message
*/ */
sendMessage(text, chan, identifier) { sendMessage(text, chan) {
chan.pushMessage( chan.pushMessage(
this.client, this.client,
new Msg({ new Msg({
type: Msg.Type.PLUGIN, type: Msg.Type.PLUGIN,
text: text, text: text,
from: { from: {
nick: identifier, nick: this.packageInfo.name || this.packageInfo.packageName,
}, },
}) })
); );