Update No Motion Detector; Add Discord Notification

merge-requests/134/head
Moe 2019-10-31 17:26:52 -07:00
parent 662ddedef1
commit 115752820d
5 changed files with 62 additions and 24 deletions

View File

@ -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,

View File

@ -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 <small>Leave blank to use Host URL</small>",

View File

@ -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===''){

View File

@ -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(){

View File

@ -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: '<i>'+lang.NoMotionEmailText2+' '+e.details.detector_notrigger_timeout+' '+lang.minutes+'.</i>',
html: '<i>'+lang.NoMotionEmailText2+' ' + (e.details.detector_notrigger_timeout || 10) + ' '+lang.minutes+'.</i>',
}
mailOptions.html+='<div><b>'+lang['Monitor Name']+' </b> : '+e.name+'</div>'
mailOptions.html+='<div><b>'+lang['Monitor ID']+' </b> : '+e.id+'</div>'