initial commit, thanks to a
This commit is contained in:
commit
0be4979c0d
57
bot.py
Normal file
57
bot.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from deltachat2 import MsgData, events
|
||||
from deltabot_cli import BotCli
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
cli = BotCli("doorbot")
|
||||
|
||||
allowed_chats = [10,12,13]
|
||||
|
||||
@cli.on(events.RawEvent)
|
||||
def log_event(bot, accid, event):
|
||||
bot.logger.info(event)
|
||||
|
||||
def open_downstairs(bot, accid, msg):
|
||||
pin = 24
|
||||
if not msg.chat_id in allowed_chats:
|
||||
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="permission denied"))
|
||||
return
|
||||
bot.rpc.send_reaction(accid, msg.id, ["🆗"])
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(pin,GPIO.OUT)
|
||||
GPIO.output(pin,GPIO.HIGH)
|
||||
time.sleep(3)
|
||||
GPIO.output(pin,GPIO.LOW)
|
||||
|
||||
@cli.on(events.NewMessage)
|
||||
def echo(bot, accid, event):
|
||||
# TODO: make this only work in one allowed verified group
|
||||
# TODO: check the time this was sent that it is not too far ago
|
||||
# or and use realtime channels
|
||||
msg = event.msg
|
||||
if msg.text == "/open2":
|
||||
if not msg.chat_id in allowed_chats:
|
||||
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="permission denied"))
|
||||
return
|
||||
bot.rpc.send_reaction(accid, msg.id, ["🆗"])
|
||||
try:
|
||||
subprocess.run(["./unlock.sh"], timeout=60)
|
||||
except subprocess.TimeoutExpired:
|
||||
bot.rpc.send_reaction(accid, msg.id, ["❌"])
|
||||
elif msg.text.startswith("/open"):
|
||||
try:
|
||||
n = int(msg.text.removeprefix("/open"))
|
||||
except ValueError:
|
||||
n = 0
|
||||
time.sleep(n)
|
||||
open_downstairs(bot, accid, msg)
|
||||
elif msg.text == "/id":
|
||||
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="the id of this chat is {id}, add this to the allowlist to allow opening the door from this group".format(id = msg.chat_id)))
|
||||
elif msg.text == "/help":
|
||||
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="/open [delay]\n/open2\n/id - get ID of the chat"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli.start()
|
||||
Loading…
Reference in a new issue