Verified Commit 9da690a9 authored by Mroik's avatar Mroik
Browse files

More logging

parent e6cb633a
import logging
from mt.bot import Bot
import mt
from config import (
......@@ -7,8 +9,11 @@ from config import (
PASSWORD,
)
LOGGER = logging.getLogger(__name__)
def main():
# logging.basicConfig(level=logging.INFO) # Uncomment for DUBUG
mt.bot = Bot(SERVER, PORT)
mt.bot.start(USERNAME, PASSWORD)
......
......@@ -12,7 +12,7 @@ def on_connect(client, userdata, flags, rc):
LOGGER.error(RETURN_CODE[rc])
return
res, mid = client.subscribe("sede/status") # Maybe should make it into a constant set'd from config file
LOGGER.info(res, mid)
LOGGER.info(f"{res} {mid}")
def on_message(client, userdata, msg):
......
import logging
from datetime import datetime
from telegram.ext import CallbackContext, DispatcherHandlerStop
from telegram import Update, Message
......@@ -8,6 +9,7 @@ from config import ADMIN_CHANNELS
LOGGER = logging.getLogger(__name__)
last_change = None
def on_message(update: Update, context: CallbackContext):
......@@ -38,6 +40,15 @@ def set_open(update: Update, context: CallbackContext):
def set_closed(update: Update, context: CallbackContext):
global last_change
if last_change is None:
last_change = datetime.now()
else:
if datetime.now() - 10000 < last_change:
print(datetime.now())
return
if not check_admin(update, context):
raise DispatcherHandlerStop
resp = mt.bot.mqtt.publish("sede/status", 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment