jorisvddonk / node-red-contrib-discord

Node-red nodes that allow you to interact with Discord.
15 stars 19 forks source link

Multiple answers for a simple request #7

Closed Aim23 closed 6 years ago

Aim23 commented 6 years ago

This phenomenon is a bit hard to describe:

I'm getting multiple answers for a simple request. Those multiple answers increase after I changed something in my flow and hit deploy afterwards. Those multiple answers only occur during trigger in discord via a switch node after the discord node. If I use a trigger node inside my flow, the flow is working flawlessly.

I'm not quite sure, but I guess there is some problem inside the discordMessage node code. If I connect a debug node directly to the discordMessage node, I see sometimes messages appear more than once.

Any suggestions?

My flow I'm working with right now:

!dwd-node: [{"id":"6060d81e.09a288","type":"link out","z":"de2450a2.68a07","name":"dwd","links":["dcb48cd6.69231"],"x":875,"y":660,"wires":[]},{"id":"791148e7.c2e028","type":"template","z":"de2450a2.68a07","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{#payload}}\n```Warnung für {{regionName}} im Zeitraum von - bis: {{headline}}\nBeschreibung: {{description}}```\n{{/payload}}","output":"str","x":770,"y":660,"wires":[["6060d81e.09a288"]]},{"id":"b8475e7f.c487d","type":"function","z":"de2450a2.68a07","name":"","func":"if (!msg.payload.warnings[\"102000000\"]) {\n return {payload : \"nothing to see here\"};\n} else {\n return { payload : msg.payload.warnings[\"102000000\"] };\n}\n \n//return msg.payload.warnings[\"102000000\"];\n//","outputs":1,"noerr":0,"x":670,"y":600,"wires":[["791148e7.c2e028"]]},{"id":"47d14bec.382154","type":"json","z":"de2450a2.68a07","name":"","pretty":true,"x":570,"y":660,"wires":[["b8475e7f.c487d"]]},{"id":"e87aad08.e2f8","type":"function","z":"de2450a2.68a07","name":"","func":"function extract_json(json, start, end) {\n var str = json.replace(start, \"\");\n str = str.replace(end, \"\");\n\t\n\treturn str;\n}\n\nvar json = msg.payload;\nvar start = \"warnWetter.loadWarnings(\";\nvar end = \");\";\n\nvar newMsg = extract_json(json, start, end);\n\nreturn { payload : newMsg };","outputs":1,"noerr":0,"x":470,"y":600,"wires":[["47d14bec.382154"]]},{"id":"c97ccb9f.8f9358","type":"http request","z":"de2450a2.68a07","name":"DWD warnings.json","method":"GET","ret":"txt","url":"https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json","tls":"","x":310,"y":660,"wires":[["e87aad08.e2f8"]]},{"id":"58a964f0.76842c","type":"inject","z":"de2450a2.68a07","name":"DWD warnings","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":720,"wires":[["c97ccb9f.8f9358"]]},{"id":"17a24c85.301943","type":"switch","z":"de2450a2.68a07","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"!dwd","vt":"str"}],"checkall":"false","outputs":1,"x":170,"y":600,"wires":[["c97ccb9f.8f9358"]]},{"id":"bb8c710b.3b247","type":"discordMessage","z":"de2450a2.68a07","name":"","token":"","x":60,"y":660,"wires":[["17a24c85.301943"]]}] [{"id":"fce22f1b.14c36","type":"discordSendMessage","z":"de2450a2.68a07","name":"","channel":"","token":"","x":1020,"y":720,"wires":[]},{"id":"dcb48cd6.69231","type":"link in","z":"de2450a2.68a07","name":"","links":["6060d81e.09a288","b5d1c811.107438","ebe97886.157648","6197d5d4.5601ac"],"x":915,"y":720,"wires":[["fce22f1b.14c36"]]}]

jorisvddonk commented 6 years ago

I've definitely seen this behavior before, myself, as well. I suspect that there's a race condition in lib/discordBotManager.js, which manages Discord clients, and is used directly by the DiscordMessage node.

As a workaround, until I can get this fixed, I suggest restarting node-red, deploying the entire flow once and - when making changes - only deploy the nodes that changed, rather than the entire flow. This issue should then no longer occur.

Aim23 commented 6 years ago

Deploying only changed nodes after restarting node-red is working quite well now. After stress testing, this issue hasn't shown up again. Looking forward for your fix on that 👍