diff --git a/src/client.js b/src/client.js index b6316dff..35f2c60a 100644 --- a/src/client.js +++ b/src/client.js @@ -374,7 +374,7 @@ Client.prototype.inputLine = function(data) { if (typeof plugin.input === "function" && (connected || plugin.allowDisconnected)) { connected = true; plugin.input( - new PublicClient(client), + new PublicClient(client, plugin.packageInfo), {network: target.network, chan: target.chan}, cmd, args diff --git a/src/plugins/inputs/index.js b/src/plugins/inputs/index.js index 6ea9d8cc..7bae9e62 100644 --- a/src/plugins/inputs/index.js +++ b/src/plugins/inputs/index.js @@ -51,7 +51,10 @@ const getCommands = () => .concat(passThroughCommands) .sort(); -const addPluginCommand = (command, func) => pluginCommands.set(command, func); +const addPluginCommand = (packageInfo, command, func) => { + func.packageInfo = packageInfo; + pluginCommands.set(command, func); +}; module.exports = { addPluginCommand, diff --git a/src/plugins/packages/index.js b/src/plugins/packages/index.js index 55825744..5a238b85 100644 --- a/src/plugins/packages/index.js +++ b/src/plugins/packages/index.js @@ -27,16 +27,16 @@ module.exports = { outdated, }; -const packageApis = function(packageName) { +const packageApis = function(packageInfo) { return { Stylesheets: { - addFile: addStylesheet.bind(this, packageName), + addFile: addStylesheet.bind(this, packageInfo.packageName), }, PublicFiles: { - add: addFile.bind(this, packageName), + add: addFile.bind(this, packageInfo.packageName), }, Commands: { - add: inputs.addPluginCommand, + add: inputs.addPluginCommand.bind(this, packageInfo), runAsUser: (command, targetId, client) => client.inputLine({target: targetId, text: command}), }, @@ -98,6 +98,7 @@ function loadPackages() { } packageInfo = packageInfo.thelounge; + packageInfo.packageName = packageName; packageMap.set(packageName, packageFile); @@ -112,7 +113,7 @@ function loadPackages() { } if (packageFile.onServerStart) { - packageFile.onServerStart(packageApis(packageName)); + packageFile.onServerStart(packageApis(packageInfo)); } log.info(`Package ${colors.bold(packageName)} loaded`); diff --git a/src/plugins/packages/publicClient.js b/src/plugins/packages/publicClient.js index 7754f6ea..f6507971 100644 --- a/src/plugins/packages/publicClient.js +++ b/src/plugins/packages/publicClient.js @@ -1,8 +1,9 @@ const Msg = require("../../models/msg"); module.exports = class PublicClient { - constructor(client) { + constructor(client, packageInfo) { this.client = client; + this.packageInfo = packageInfo; } /** @@ -45,16 +46,15 @@ module.exports = class PublicClient { * * @param {String} text the message to send * @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( this.client, new Msg({ type: Msg.Type.PLUGIN, text: text, from: { - nick: identifier, + nick: this.packageInfo.name || this.packageInfo.packageName, }, }) );