Verified Commit fa3dc529 authored by Mroik's avatar Mroik
Browse files

Added logging and mqtt auth

parent 9548f751
......@@ -3,12 +3,14 @@ import mt
from config import (
SERVER,
PORT,
USERNAME,
PASSWORD,
)
def main():
mt.bot = Bot(SERVER, PORT)
mt.bot.start()
mt.bot.start(USERNAME, PASSWORD)
if __name__ == "__main__":
......
......@@ -13,7 +13,8 @@ class Bot:
self.mqtt.on_connect = on_connect
self.mqtt.on_message = on_message
def start(self):
def start(self, username, password):
self.mqtt.username_pw_set(username, password)
self.mqtt.connect(self.server, self.port)
self.updater.start_polling()
try:
......
import logging
from telegram.ext import CallbackContext, DispatcherHandlerStop
from telegram import Update
from telegram import Update, Message
import mt
from config import ADMIN_CHANNELS
LOGGER = logging.getLogger(__name__)
def on_message(update: Update, context: CallbackContext):
from . import where_am_i # Because circular imports
print("Message received")
if update.message.chat.id not in where_am_i:
where_am_i.append(update.message.chat.id)
msg: Message = update.message
LOGGER.info("Message received from {} by {}".format(msg.chat.id, msg.from_user.id))
if msg.chat.id not in where_am_i:
where_am_i.append(msg.chat.id)
def check_admin(update: Update, context: CallbackContext):
......@@ -27,10 +33,12 @@ def check_admin(update: Update, context: CallbackContext):
def set_open(update: Update, context: CallbackContext):
if not check_admin(update, context):
raise DispatcherHandlerStop
mt.bot.mqtt.publish("sede/status", 1)
resp = mt.bot.mqtt.publish("sede/status", 1)
LOGGER.info(resp.mid)
def set_closed(update: Update, context: CallbackContext):
if not check_admin(update, context):
raise DispatcherHandlerStop
mt.bot.mqtt.publish("sede/status", 0)
resp = mt.bot.mqtt.publish("sede/status", 0)
LOGGER.info(resp.mid)
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