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)
                         }