remember-remember-bot/src/remember_remember_bot/loop.py

36 lines
998 B
Python
Raw Normal View History

import time
2023-09-01 13:00:55 +00:00
import deltachat
2023-12-10 13:46:42 +00:00
from remember_remember_bot.commands import remind_chat, activate_chat, reply, store_file, send_help
2023-09-01 15:01:03 +00:00
from remember_remember_bot.util import check_new_day, update_day
2023-09-01 13:00:55 +00:00
def loop(ac: deltachat.Account):
current_day = 0
while True:
if check_new_day(current_day):
for chat in ac.get_chats():
remind_chat(chat)
current_day = update_day()
2023-09-01 21:58:54 +00:00
for msg in ac.get_fresh_messages():
handle_incoming_message(msg)
time.sleep(1)
2023-09-03 11:24:22 +00:00
def handle_incoming_message(msg: deltachat.Message):
print(str(msg.chat.id), msg.text)
if "/start" in msg.text:
activate_chat(msg)
elif "/stop" in msg.text:
msg.chat.set_ephemeral_timer(0)
reply(msg.chat, "I will stop sending you messages now.", quote=msg)
2023-12-10 10:58:42 +00:00
elif "/file" in msg.text:
if msg.filename:
store_file(msg)
else:
activate_chat(msg)
2023-12-10 13:46:42 +00:00
else:
send_help(msg)
2023-09-03 11:24:22 +00:00
msg.mark_seen()