From 54f51557e34534a101cf08bdb13429a056338276 Mon Sep 17 00:00:00 2001 From: Moe <github@m03.ca> Date: Fri, 25 Aug 2023 06:45:36 -0700 Subject: [PATCH] discord notifications more verbose --- definitions/glyphs.js | 84 ++++++++++++++++++++++++++++++++ languages/en_CA.json | 1 + libs/events/utils.js | 21 ++++++++ libs/notifications/discordBot.js | 22 +++++---- 4 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 definitions/glyphs.js diff --git a/definitions/glyphs.js b/definitions/glyphs.js new file mode 100644 index 00000000..1a3db023 --- /dev/null +++ b/definitions/glyphs.js @@ -0,0 +1,84 @@ +module.exports = { + "person": "ð ââïļ", + "bicycle": "ðē", + "car": "ð", + "motorcycle": "ð", + "airplane": "âïļ", + "bus": "ð", + "train": "ð", + "truck": "ð", + "boat": "âĩ", + "traffic light": "ðĶ", + "fire hydrant": "ð", + "stop sign": "ð", + "parking meter": "ð ŋïļ", + "bench": "ðŠ", + "bird": "ðĶ", + "cat": "ð", + "dog": "ð", + "horse": "ð", + "sheep": "ð", + "cow": "ð", + "elephant": "ð", + "bear": "ðŧ", + "zebra": "ðĶ", + "giraffe": "ðĶ", + "backpack": "ð", + "umbrella": "âïļ", + "handbag": "ð", + "tie": "ð", + "suitcase": "ð§ģ", + "frisbee": "ðĨ", + "skis": "ðŋ", + "snowboard": "ð", + "sports ball": "â―", + "kite": "ðŠ", + "skateboard": "ðđ", + "surfboard": "ð", + "tennis racket": "ðū", + "bottle": "ðž", + "wine glass": "ð·", + "cup": "â", + "fork": "ðī", + "knife": "ðŠ", + "spoon": "ðĨ", + "bowl": "ðē", + "banana": "ð", + "apple": "ð", + "sandwich": "ðĨŠ", + "orange": "ð", + "broccoli": "ðĨĶ", + "carrot": "ðĨ", + "hot dog": "ð", + "pizza": "ð", + "donut": "ðĐ", + "cake": "ð°", + "chair": "ðŠ", + "couch": "ð", + "potted plant": "ðŠī", + "bed": "ð", + "toilet": "ð―", + "tv": "ðš", + "laptop": "ðŧ", + "mouse": "ðą", + "remote": "ðą", + "keyboard": "âĻïļ", + "cell phone": "ðą", + "microwave": "ð", + "toaster": "ð", + "refrigerator": "ð―", + "book": "ð", + "clock": "â°", + "vase": "ðš", + "scissors": "âïļ", + "teddy bear": "ð§ļ", + "hair drier": "ðĻ", + "toothbrush": "ðŠĨ", + "baseball bat": "ð", + "baseball glove": "ðĨ ", + "dining table": "ð―", + "oven": "ðĨ", + "sink": "ð°", + "Clock Format": "âē", + "_default": "ðââïļ" +} diff --git a/languages/en_CA.json b/languages/en_CA.json index feb16dfd..f4b4e075 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -1552,6 +1552,7 @@ "MQTT Outbound": "MQTT Outbound", "MQTT Client": "MQTT Client", "Buffer Time from Event": "Buffer Time from Event", + "detected": "detected", "fieldTextEventFilters": "Enable to have all Events honor your Event Filter rules.", "fieldTextBufferTimeFromEvent": "The amount of seconds to record before the trigger happened. If this is consistently inaccurate you will need to look at the <a target='_blank' href='https://hub.shinobi.video/articles/view/DmWIID78VtvEfnf'>optimization guide</a> or force encoding on the server.", "fieldTextMode": "This is the primary task of the monitor.", diff --git a/libs/events/utils.js b/libs/events/utils.js index 39df199a..98e50cdb 100644 --- a/libs/events/utils.js +++ b/libs/events/utils.js @@ -35,6 +35,7 @@ module.exports = (s,config,lang) => { isEven, fetchTimeout, } = require('../basic/utils.js')(process.cwd(),config) + const glyphs = require('../../definitions/glyphs.js') async function saveImageFromEvent(options,frameBuffer){ const monitorId = options.mid || options.id const groupKey = options.ke @@ -828,7 +829,27 @@ module.exports = (s,config,lang) => { return newRegions; } + function getTagWithIcon(tag){ + var icon = glyphs[tag.toLowerCase()] || glyphs._default + return `${icon} ${tag}`; + } + function getObjectTagsFromMatrices(d){ + if(d.details.reason === 'motion'){ + return [getTagWithIcon(lang.Motion)] + }else{ + const matrices = d.details.matrices + return [...new Set(matrices.map(matrix => getTagWithIcon(matrix.tag)))]; + } + } + function getObjectTagNotifyText(d){ + const monitorId = d.mid || d.id + const monitorName = s.group[d.ke].rawMonitorConfigurations[monitorId].name + const tags = getObjectTagsFromMatrices(d) + return `${tags.join(', ')} ${lang.detected} in ${monitorName}` + } return { + getObjectTagNotifyText, + getObjectTagsFromMatrices, countObjects: countObjects, isAtleastOneMatrixInRegion, convertRegionPointsToNewDimensions, diff --git a/libs/notifications/discordBot.js b/libs/notifications/discordBot.js index 0f39e60a..d88f7e5b 100644 --- a/libs/notifications/discordBot.js +++ b/libs/notifications/discordBot.js @@ -2,6 +2,7 @@ var fs = require("fs") var Discord = require("discord.js") module.exports = function(s,config,lang,getSnapshot){ const { + getObjectTagNotifyText, getEventBasedRecordingUponCompletion, } = require('../events/utils.js')(s,config,lang) //discord bot @@ -56,6 +57,8 @@ module.exports = function(s,config,lang,getSnapshot){ //discord bot const isEnabled = filter.discord || monitorConfig.details.detector_discordbot === '1' || monitorConfig.details.notify_discord === '1' if(s.group[d.ke].discordBot && isEnabled && !s.group[d.ke].activeMonitors[d.id].detector_discordbot){ + const monitorName = s.group[d.ke].rawMonitorConfigurations[d.id].name + const notifyText = getObjectTagNotifyText(d) var detector_discordbot_timeout if(!monitorConfig.details.detector_discordbot_timeout||monitorConfig.details.detector_discordbot_timeout===''){ detector_discordbot_timeout = 1000 * 60 * 10; @@ -70,11 +73,11 @@ module.exports = function(s,config,lang,getSnapshot){ if(d.screenshotBuffer){ sendMessage({ author: { - name: s.group[d.ke].rawMonitorConfigurations[d.id].name, + name: monitorName, icon_url: config.iconURL }, - title: lang.Event+' - '+d.screenshotName, - description: lang.EventText1+' '+d.currentTimestamp, + title: notifyText, + description: notifyText+' '+d.currentTimestamp, fields: [], timestamp: d.currentTime, footer: { @@ -84,7 +87,7 @@ module.exports = function(s,config,lang,getSnapshot){ },[ { attachment: d.screenshotBuffer, - name: d.screenshotName+'.jpg' + name: notifyText + '.jpg' } ],d.ke) } @@ -106,20 +109,21 @@ module.exports = function(s,config,lang,getSnapshot){ if(videoPath){ sendMessage({ author: { - name: s.group[d.ke].rawMonitorConfigurations[d.id].name, + name: monitorName, icon_url: config.iconURL }, - title: videoName, + title: `${notifyText}`, + description: notifyText, fields: [], timestamp: d.currentTime, footer: { - icon_url: config.iconURL, - text: "Shinobi Systems" + icon_url: config.iconURL, + text: "Shinobi Systems" } },[ { attachment: videoPath, - name: videoName + name: notifyText + '.mp4' } ],d.ke) }