First implementation of cambot, missing configuration
This commit is contained in:
parent
b2215b5426
commit
d844e8ccb5
|
@ -12,11 +12,11 @@ RUN pip install -r requirements.txt
|
|||
|
||||
COPY bot.py *.json *.pickle /bot/
|
||||
COPY config config
|
||||
COPY modules modules
|
||||
|
||||
VOLUME /bot/config
|
||||
RUN useradd -m HomeBot && chown HomeBot -R /bot && apt install curl jq -y
|
||||
USER HomeBot
|
||||
WORKDIR /bot
|
||||
COPY modules modules
|
||||
|
||||
CMD [ "python", "-u", "./bot.py" ]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from modules.common.module import BotModule
|
||||
import requests
|
||||
|
||||
|
@ -6,19 +7,49 @@ class MatrixModule(BotModule):
|
|||
def __init__(self,name):
|
||||
super().__init__(name)
|
||||
self.motionurl = 'http://192.168.1.220:8080'
|
||||
self.allowed_cmds = {
|
||||
'config': ['list','set','get','write'],
|
||||
'detection': ['status','connection','start','pause'],
|
||||
'action': ['eventstart','eventend','snapshot','restart','quit','end']
|
||||
}
|
||||
self.helptext = """Control the motion daemon.
|
||||
Available commands:
|
||||
- config list|set|get|write
|
||||
- detection status|connection|start|pause
|
||||
- action eventstart|eventend|snapshot|restart|quit|end
|
||||
|
||||
Usage: '!cam <id> category command'
|
||||
|
||||
<id> is the numerical id of the camera. Use 0 for all cameras.
|
||||
If <id> is omitted, 0 is assumed."""
|
||||
|
||||
async def matrix_message(self, bot, room, event):
|
||||
args = event.body.split()
|
||||
args.pop(0)
|
||||
if args[0] == 'help':
|
||||
await bot.send_text(room, self.helptext, event)
|
||||
return
|
||||
|
||||
if args[0] == 'config':
|
||||
if args[1] == 'list':
|
||||
req_url = self.motionurl
|
||||
for arg in args:
|
||||
req_url = f'{req_url}/{arg}'
|
||||
|
||||
resp = requests.get(req_url)
|
||||
await bot.send_text(resp.content)
|
||||
recvd_camid = 1
|
||||
try:
|
||||
# Check if first argument is numeric (camera id)
|
||||
camid = int(args[0])
|
||||
camid = str(camid)
|
||||
except ValueError:
|
||||
recvd_camid = 0
|
||||
camid = '0'
|
||||
if args[recvd_camid] not in self.allowed_cmds:
|
||||
await bot.send_text(room, f'Unknown category: "{args[1]}"', event)
|
||||
return
|
||||
category = args[recvd_camid]
|
||||
recvd_camid = recvd_camid + 1
|
||||
if args[recvd_camid] not in self.allowed_cmds[category]:
|
||||
await bot.send_text(room, f'Unknown command: "{args[recvd_camid]}"', event)
|
||||
return
|
||||
command = args[recvd_camid]
|
||||
req_url = f'{self.motionurl}/{camid}/{category}/{command}'
|
||||
resp = requests.get(req_url).text
|
||||
await bot.send_text(room, resp, event)
|
||||
|
||||
def help(self):
|
||||
return 'Echoes back what user has said'
|
||||
return self.helptext.splitlines()[0]
|
||||
|
|
Loading…
Reference in New Issue