thelounge-plugin-ntfy 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/index.js +66 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ This plugin introduces the `/ntfy` command, subcommands are:
|
|
|
18
18
|
|
|
19
19
|
- `/ntfy start`: Start the ntfy listener for the network
|
|
20
20
|
- `/ntfy stop`: Stop the ntfy listener for the network
|
|
21
|
+
- `/ntfy status`: Show the ntfy listener status for this network
|
|
22
|
+
- `/ntfy test`: Send a test notification
|
|
21
23
|
- `/ntfy config`: Config commands
|
|
22
24
|
- `/ntfy config set <setting_key> <setting_value>`: Set a configuration setting
|
|
23
25
|
- `/ntfy config remove <setting_key>`: Set a configuration setting to null
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const {
|
|
|
12
12
|
const globalActiveListeners = new Map();
|
|
13
13
|
|
|
14
14
|
const ntfyCommand = {
|
|
15
|
-
input: (client, target, command, args) => {
|
|
15
|
+
input: async (client, target, command, args) => {
|
|
16
16
|
const say = (message) => {
|
|
17
17
|
client.sendMessage(message, target.chan);
|
|
18
18
|
};
|
|
@@ -21,6 +21,10 @@ const ntfyCommand = {
|
|
|
21
21
|
say(`${command} command help:`);
|
|
22
22
|
say(`/${command} start - Start the ntfy listener for this network`);
|
|
23
23
|
say(`/${command} stop - Stop the ntfy listener for this network`);
|
|
24
|
+
say(
|
|
25
|
+
`/${command} status - Show the ntfy listener status for this network`
|
|
26
|
+
);
|
|
27
|
+
say(`/${command} test - Send a test notification`);
|
|
24
28
|
say(
|
|
25
29
|
`/${command} config set <setting_key> <setting_value> - Set a configuration setting`
|
|
26
30
|
);
|
|
@@ -105,6 +109,67 @@ const ntfyCommand = {
|
|
|
105
109
|
break;
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
case "status": {
|
|
113
|
+
const userListeners = globalActiveListeners.get(client.client.name);
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
userListeners &&
|
|
117
|
+
typeof userListeners.has === "function" &&
|
|
118
|
+
userListeners.has(network.uuid)
|
|
119
|
+
) {
|
|
120
|
+
say("ntfy listener is running for this network");
|
|
121
|
+
} else {
|
|
122
|
+
say("ntfy listener is not running for this network");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case "test": {
|
|
129
|
+
const { NtfyClient, MessagePriority } = await import("ntfy");
|
|
130
|
+
|
|
131
|
+
const [userConfig, errors] = loadUserConfig(client.client.name);
|
|
132
|
+
|
|
133
|
+
if (errors.length > 0) {
|
|
134
|
+
say("Cannot test ntfy due to invalid configuration:");
|
|
135
|
+
for (const error of errors) {
|
|
136
|
+
say(`- ${error.instancePath} ${error.message}`);
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let ntfyAuth;
|
|
142
|
+
|
|
143
|
+
if (userConfig.ntfy.token) {
|
|
144
|
+
ntfyAuth = userConfig.ntfy.token;
|
|
145
|
+
} else if (userConfig.ntfy.username && userConfig.ntfy.password) {
|
|
146
|
+
ntfyAuth = {
|
|
147
|
+
username: userConfig.ntfy.username,
|
|
148
|
+
password: userConfig.ntfy.password,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const ntfyClient = new NtfyClient({
|
|
153
|
+
server: userConfig.ntfy.server,
|
|
154
|
+
topic: userConfig.ntfy.topic,
|
|
155
|
+
priority: MessagePriority.HIGH,
|
|
156
|
+
tags: ["speech_balloon"],
|
|
157
|
+
authorization: ntfyAuth,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
ntfyClient.publish({
|
|
162
|
+
title: `${network.name} #afakechannel: ntfy`,
|
|
163
|
+
message: `Hello, ${client.client.name}!`,
|
|
164
|
+
});
|
|
165
|
+
say(`Sent to ${userConfig.ntfy.server}/${userConfig.ntfy.topic}`);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
say(`Failed to send test notification: ${error.message}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
|
|
108
173
|
case "config": {
|
|
109
174
|
const subsubcommand = subcommand.slice(1);
|
|
110
175
|
|