diff --git a/definitions/en_CA.js b/definitions/en_CA.js index b514c0b6..db5af321 100644 --- a/definitions/en_CA.js +++ b/definitions/en_CA.js @@ -2702,7 +2702,7 @@ module.exports = function(s,config,lang){ }, { "name": "detail=detector_notrigger_mail", - "field": `Email on "No Motion"`, + "field": lang['Email'], "description": "If motion has not been detected after the timeout period you will recieve an email.", "default": "0", "example": "", @@ -2718,6 +2718,24 @@ module.exports = function(s,config,lang){ } ] }, + { + "name": "detail=detector_notrigger_discord", + "field": lang['Discord'], + "description": "If motion has not been detected after the timeout period you will recieve an Discord notification.", + "default": "0", + "example": "", + "fieldType": "select", + "possible": [ + { + "name": lang.No, + "value": "0" + }, + { + "name": lang.Yes, + "value": "1" + } + ] + }, { "name": "detail=detector_notrigger_timeout", "field": lang.Timeout, diff --git a/languages/en_CA.json b/languages/en_CA.json index 92201a5c..2b968840 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -562,6 +562,7 @@ "Full Frame Detection": "Full Frame Detection", "Country of Plates": "Country of Plates", "Email on No Motion": "Email on \"No Motion\"", + "Discord on No Motion": "Discord on \"No Motion\"", "Timeout": "Timeout", "Controllable": "Controllable", "Custom Base URL": "Custom Base URL Leave blank to use Host URL", diff --git a/libs/events.js b/libs/events.js index 216ba853..7814a3f5 100644 --- a/libs/events.js +++ b/libs/events.js @@ -258,14 +258,7 @@ module.exports = function(s,config,lang){ s.sqlQuery('INSERT INTO Events (ke,mid,details,time) VALUES (?,?,?,?)',[d.ke,d.id,detailString,eventTime]) } if(currentConfig.detector_notrigger === '1'){ - var detector_notrigger_timeout - if(!currentConfig.detector_notrigger_timeout||currentConfig.detector_notrigger_timeout === ''){ - detector_notrigger_timeout = 10 - } - detector_notrigger_timeout = parseFloat(currentConfig.detector_notrigger_timeout)*1000*60; - s.group[d.ke].activeMonitors[d.id].detector_notrigger_timeout = detector_notrigger_timeout; - clearInterval(s.group[d.ke].activeMonitors[d.id].detector_notrigger_timeout) - s.group[d.ke].activeMonitors[d.id].detector_notrigger_timeout = setInterval(s.group[d.ke].activeMonitors[d.id].detector_notrigger_timeout_function,detector_notrigger_timeout) + s.setNoEventsDetector(s.group[d.ke].rawMonitorConfigurations[d.id]) } var detector_timeout if(!currentConfig.detector_timeout||currentConfig.detector_timeout===''){ diff --git a/libs/monitor.js b/libs/monitor.js index 2fcdaac6..2ae5e55f 100644 --- a/libs/monitor.js +++ b/libs/monitor.js @@ -1215,6 +1215,17 @@ module.exports = function(s,config,lang){ s.userLog(e,{type:"FFMPEG STDERR",msg:d}) }) } + //formerly known as "No Motion" Detector + s.setNoEventsDetector = function(e){ + var monitorId = e.id || e.mid + var detector_notrigger_timeout = (parseFloat(e.details.detector_notrigger_timeout) || 10) * 1000 * 60 + clearInterval(s.group[e.ke].activeMonitors[monitorId].detector_notrigger_timeout) + s.group[e.ke].activeMonitors[monitorId].detector_notrigger_timeout = setInterval(function(){ + s.onDetectorNoTriggerTimeoutExtensions.forEach(function(extender){ + extender(e) + }) + },detector_notrigger_timeout) + } //set master based process launcher s.launchMonitorProcesses = function(e){ // e = monitor object @@ -1229,24 +1240,14 @@ module.exports = function(s,config,lang){ mid : e.id },e.ke) if(e.details.detector_trigger === '1'){ - s.group[e.ke].activeMonitors[e.id].motion_lock=setTimeout(function(){ - clearTimeout(s.group[e.ke].activeMonitors[e.id].motion_lock); - delete(s.group[e.ke].activeMonitors[e.id].motion_lock); + s.group[e.ke].activeMonitors[e.id].motion_lock = setTimeout(function(){ + clearTimeout(s.group[e.ke].activeMonitors[e.id].motion_lock) + delete(s.group[e.ke].activeMonitors[e.id].motion_lock) },15000) } //start "no motion" checker if(e.details.detector === '1' && e.details.detector_notrigger === '1'){ - if(!e.details.detector_notrigger_timeout || e.details.detector_notrigger_timeout === ''){ - e.details.detector_notrigger_timeout = 10 - } - e.detector_notrigger_timeout = parseFloat(e.details.detector_notrigger_timeout)*1000*60; - s.group[e.ke].activeMonitors[e.id].detector_notrigger_timeout_function = function(){ - s.onDetectorNoTriggerTimeoutExtensions.forEach(function(extender){ - extender(e) - }) - } - clearInterval(s.group[e.ke].activeMonitors[e.id].detector_notrigger_timeout) - s.group[e.ke].activeMonitors[e.id].detector_notrigger_timeout=setInterval(s.group[e.ke].activeMonitors[e.id].detector_notrigger_timeout_function,s.group[e.ke].activeMonitors[e.id].detector_notrigger_timeout) + s.setNoEventsDetector(e) } if(e.details.snap === '1'){ var resetSnapCheck = function(){ diff --git a/libs/notification.js b/libs/notification.js index fbf57cdc..f2d9ff0c 100644 --- a/libs/notification.js +++ b/libs/notification.js @@ -162,11 +162,36 @@ module.exports = function(s,config,lang){ delete(s.group[user.ke].discordBot) } } + var onDetectorNoTriggerTimeoutForDiscord = function(e){ + //e = monitor object + var currentTime = new Date() + if(e.details.detector_notrigger_discord === '1'){ + var html = '*'+lang.NoMotionEmailText2+' ' + (e.details.detector_notrigger_timeout || 10) + ' '+lang.minutes+'.*\n' + html += '**' + lang['Monitor Name'] + '** : '+e.name + '\n' + html += '**' + lang['Monitor ID'] + '** : '+e.id + '\n' + html += currentTime + s.discordMsg({ + author: { + name: s.group[e.ke].rawMonitorConfigurations[e.id].name, + icon_url: config.iconURL + }, + title: lang['\"No Motion"\ Detector'], + description: html, + fields: [], + timestamp: currentTime, + footer: { + icon_url: config.iconURL, + text: "Shinobi Systems" + } + },[],e.ke) + } + } s.loadGroupAppExtender(loadDiscordBotForUser) s.unloadGroupAppExtender(unloadDiscordBotForUser) s.onTwoFactorAuthCodeNotification(onTwoFactorAuthCodeNotificationForDiscord) s.onEventTrigger(onEventTriggerForDiscord) s.onEventTriggerBeforeFilter(onEventTriggerBeforeFilterForDiscord) + s.onDetectorNoTriggerTimeout(onDetectorNoTriggerTimeoutForDiscord) }catch(err){ console.log(err) console.log('Could not start Discord bot, please run "npm install discord.js" inside the Shinobi folder.') @@ -188,7 +213,7 @@ module.exports = function(s,config,lang){ from: config.mail.from, // sender address to: r.mail, // list of receivers subject: lang.NoMotionEmailText1+' '+e.name+' ('+e.id+')', // Subject line - html: ''+lang.NoMotionEmailText2+' '+e.details.detector_notrigger_timeout+' '+lang.minutes+'.', + html: ''+lang.NoMotionEmailText2+' ' + (e.details.detector_notrigger_timeout || 10) + ' '+lang.minutes+'.', } mailOptions.html+='
'+lang['Monitor Name']+' : '+e.name+'
' mailOptions.html+='
'+lang['Monitor ID']+' : '+e.id+'
'