From 0be4979c0deb8587fb6fce619bca7a2bd90e5b23 Mon Sep 17 00:00:00 2001 From: missytake Date: Sun, 9 Nov 2025 08:46:39 +0100 Subject: [PATCH] initial commit, thanks to a --- bot.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ unlock.sh | 5 +++++ 2 files changed, 62 insertions(+) create mode 100644 bot.py create mode 100644 unlock.sh diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..2bf93d9 --- /dev/null +++ b/bot.py @@ -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() diff --git a/unlock.sh b/unlock.sh new file mode 100644 index 0000000..854fe5d --- /dev/null +++ b/unlock.sh @@ -0,0 +1,5 @@ +#!/bin/sh +. venv/bin/activate +cd keyblepy +./keyble.py --device
--qrdata --user-key --user-id 0 --verbose --open +