thelounge-plugin-ntfy 1.6.2 → 1.6.4

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/index.js CHANGED
@@ -252,39 +252,42 @@ const ntfyCommand = {
252
252
  }
253
253
 
254
254
  case "test": {
255
- const { NtfyClient } = await import("ntfy");
255
+ try {
256
+ const { NtfyClient } = await import("ntfy");
256
257
 
257
- const [userConfig, errors] = loadUserConfig(client.client.name);
258
+ const [userConfig, errors] = loadUserConfig(client.client.name);
258
259
 
259
- if (errors.length > 0) {
260
- say("Cannot test ntfy due to invalid configuration:");
261
- for (const error of errors) {
262
- say(`- ${error.instancePath} ${error.message}`);
260
+ if (errors.length > 0) {
261
+ say("Cannot test ntfy due to invalid configuration:");
262
+ for (const error of errors) {
263
+ say(`- ${error.instancePath} ${error.message}`);
264
+ }
265
+ return;
263
266
  }
264
- return;
265
- }
266
267
 
267
- let ntfyAuth;
268
+ let ntfyAuth;
268
269
 
269
- if (userConfig.ntfy.token) {
270
- ntfyAuth = userConfig.ntfy.token;
271
- } else if (userConfig.ntfy.username && userConfig.ntfy.password) {
272
- ntfyAuth = {
273
- username: userConfig.ntfy.username,
274
- password: userConfig.ntfy.password,
275
- };
276
- }
270
+ if (userConfig.ntfy.token) {
271
+ ntfyAuth = {
272
+ username: "",
273
+ password: userConfig.ntfy.token,
274
+ };
275
+ } else if (userConfig.ntfy.username && userConfig.ntfy.password) {
276
+ ntfyAuth = {
277
+ username: userConfig.ntfy.username,
278
+ password: userConfig.ntfy.password,
279
+ };
280
+ }
277
281
 
278
- const ntfyClient = new NtfyClient({
279
- server: userConfig.ntfy.server,
280
- topic: userConfig.ntfy.topic,
281
- priority: userConfig.ntfy.priority,
282
- tags: ["speech_balloon"],
283
- authorization: ntfyAuth,
284
- });
282
+ const ntfyClient = new NtfyClient({
283
+ server: userConfig.ntfy.server,
284
+ topic: userConfig.ntfy.topic,
285
+ priority: userConfig.ntfy.priority,
286
+ tags: ["speech_balloon"],
287
+ authorization: ntfyAuth,
288
+ });
285
289
 
286
- try {
287
- ntfyClient.publish({
290
+ await ntfyClient.publish({
288
291
  title: `${network.name} #afakechannel: ntfy`,
289
292
  message: `Hello, ${client.client.name}!`,
290
293
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thelounge-plugin-ntfy",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "A plugin for The Lounge that sends push notifications via ntfy when highlighted",
5
5
  "keywords": [
6
6
  "thelounge",
package/src/handler.js CHANGED
@@ -19,13 +19,18 @@ function createHandler(client, network) {
19
19
 
20
20
  const isPM = data.target === network.nick;
21
21
 
22
- const channel = isPM
23
- ? network.channels.find((chan) => chan.name === data.nick)
24
- : network.channels.find((chan) => chan.name === data.target);
22
+ try {
23
+ const channel = isPM
24
+ ? network.channels.find((chan) => chan.name === data.nick)
25
+ : network.channels.find((chan) => chan.name === data.target);
25
26
 
26
- if (channel.muted) {
27
- // Ignore messages in muted channels
28
- return;
27
+ if (channel && channel.muted) {
28
+ // Ignore messages in muted channels
29
+ return;
30
+ }
31
+ } catch (e) {
32
+ PluginLogger.error("Failed to determine channel mute status", e);
33
+ PluginLogger.debug(`Data: ${JSON.stringify(data)}`);
29
34
  }
30
35
 
31
36
  const highlightRegex = new RegExp(network.highlightRegex, "i");
@@ -98,7 +103,7 @@ function createHandler(client, network) {
98
103
  authorization: ntfyAuth,
99
104
  });
100
105
 
101
- ntfyClient.publish({
106
+ await ntfyClient.publish({
102
107
  title: isPM
103
108
  ? `${network.name}: ${data.nick}`
104
109
  : `${network.name} ${data.target}: ${data.nick}`,
@@ -1,17 +0,0 @@
1
- services:
2
- thelounge:
3
- image: ghcr.io/thelounge/thelounge:latest
4
- container_name: thelounge
5
- network_mode: bridge
6
- ports:
7
- - 9000:9000
8
- restart: unless-stopped
9
- volumes:
10
- - $PWD/tl:/var/opt/thelounge
11
- - $PWD/src:/var/opt/thelounge/packages/thelounge-plugin-ntfy/src
12
- - $PWD/index.js:/var/opt/thelounge/packages/thelounge-plugin-ntfy/index.js
13
- - $PWD/package.json:/var/opt/thelounge/packages/thelounge-plugin-ntfy/package.json
14
- - $PWD/package-lock.json:/var/opt/thelounge/packages/thelounge-plugin-ntfy/package-lock.json
15
-
16
- # Installation: su node -c "thelounge install file:/var/opt/thelounge/packages/thelounge-plugin-ntfy"
17
- # Removal: su node -c "thelounge uninstall thelounge-plugin-ntfy"
package/misc/api.txt DELETED
@@ -1,53 +0,0 @@
1
- https://thelounge.chat/docs/api
2
-
3
- api
4
- Commands
5
- add(commandText: string, command: Command)
6
- Config
7
- getConfig()
8
- getPersistentStorageDir()
9
- Logger
10
- error(...args)
11
- warn(...args)
12
- info(...args)
13
- debug(...args)
14
- Stylesheets
15
- addFile(filename: String)
16
-
17
- command
18
- input(client: Client, target: Target, command: String, args: String[])
19
- allowDisconnected: bool
20
-
21
- target
22
- network: String
23
- chan: String
24
-
25
- client
26
- runAsUser(command: String, targetId: String)
27
- createChannel(attributes: Attributes)
28
- sendToBrowser(event: String, data: Object)
29
- getChannel(channelId: Number)
30
- sendMessage(text: String, chan: Chan)
31
-
32
- attributes
33
- id: Number
34
- messages: Msg[]
35
- name: string
36
- key: String
37
- topic: String
38
- type: Chan.Type
39
- state: Chan.State
40
- firstUnread: Number
41
- unread: Number
42
- highlight: Number
43
- users: String -> User Map
44
-
45
- Chan.Type
46
- CHANNEL
47
- LOBBY
48
- QUERY
49
- SPECIAL
50
-
51
- Chan.State
52
- PARTED
53
- JOINED