Merge pull request #3471 from MiniDigger/feature/plugin-messages

Add message type for plugins
This commit is contained in:
Pavel Djundik 2019-11-01 16:41:41 +02:00 committed by GitHub
commit 959ec5b598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 9 deletions

View File

@ -40,6 +40,13 @@
<span class="only-copy">&gt; </span> <span class="only-copy">&gt; </span>
</template> </template>
</span> </span>
<span v-else-if="message.type === 'plugin'" class="from">
<template v-if="message.from && message.from.nick">
<span class="only-copy">[</span>
{{ message.from.nick }}
<span class="only-copy">] </span>
</template>
</span>
<span v-else class="from"> <span v-else class="from">
<template v-if="message.from && message.from.nick"> <template v-if="message.from && message.from.nick">
<span class="only-copy">-</span> <span class="only-copy">-</span>

View File

@ -264,6 +264,7 @@ kbd {
#chat .whois .from::before, #chat .whois .from::before,
#chat .nick .from::before, #chat .nick .from::before,
#chat .action .from::before, #chat .action .from::before,
#chat .plugin .from::before,
#chat .raw .from::before, #chat .raw .from::before,
#chat .toggle-button::after, #chat .toggle-button::after,
#chat .toggle-content .more-caret::before, #chat .toggle-content .more-caret::before,
@ -426,6 +427,13 @@ kbd {
content: "\f005"; /* http://fontawesome.io/icon/star/ */ content: "\f005"; /* http://fontawesome.io/icon/star/ */
} }
#chat .plugin .from::before {
content: "\f1e6"; /* http://fontawesome.io/icon/plug/ */
transform: rotate(45deg);
display: inline-block;
padding: 1px;
}
#chat .toggle-button { #chat .toggle-button {
display: inline-block; display: inline-block;
transition: opacity 0.2s, transform 0.2s; transition: opacity 0.2s, transform 0.2s;

View File

@ -388,7 +388,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

@ -48,7 +48,8 @@ class Msg {
this.type !== Msg.Type.TOPIC_SET_BY && this.type !== Msg.Type.TOPIC_SET_BY &&
this.type !== Msg.Type.MODE_CHANNEL && this.type !== Msg.Type.MODE_CHANNEL &&
this.type !== Msg.Type.RAW && this.type !== Msg.Type.RAW &&
this.type !== Msg.Type.WHOIS this.type !== Msg.Type.WHOIS &&
this.type !== Msg.Type.PLUGIN
); );
} }
} }
@ -77,6 +78,7 @@ Msg.Type = {
TOPIC_SET_BY: "topic_set_by", TOPIC_SET_BY: "topic_set_by",
WHOIS: "whois", WHOIS: "whois",
RAW: "raw", RAW: "raw",
PLUGIN: "plugin",
}; };
module.exports = Msg; module.exports = Msg;

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,6 +1,9 @@
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;
} }
/** /**
@ -37,4 +40,23 @@ module.exports = class PublicClient {
getChannel(chanId) { getChannel(chanId) {
return this.client.find(chanId); return this.client.find(chanId);
} }
/**
* Sends a message to this client, displayed in the given channel.
*
* @param {String} text the message to send
* @param {Chan} chan the channel to send the message to
*/
sendMessage(text, chan) {
chan.pushMessage(
this.client,
new Msg({
type: Msg.Type.PLUGIN,
text: text,
from: {
nick: this.packageInfo.name || this.packageInfo.packageName,
},
})
);
}
}; };