Verified Commit 60ff0bf5 authored by Mroik's avatar Mroik
Browse files

First working verison

parent e494707b
**/__pycache__
__pycache__
......@@ -9,16 +9,16 @@ class Bot:
self.server = server
self.port = port
self.updater = updater
self.mqtt = Client()
def start(self):
self.mqtt = Client(client_id="Telegram_notifier")
self.mqtt.on_connect = on_connect
self.mqtt.on_message = on_message
def start(self):
self.mqtt.connect(self.server, self.port)
self.updater.start_polling()
print("test")
try:
self.mqtt.loop_forever()
except KeyboardInterrupt:
pass
self.updater.stop()
print("Stopping bot...")
self.updater.stop()
return
......@@ -3,16 +3,17 @@ from tgbot import updater, where_am_i
def on_connect(client, userdata, flags, rc):
print("Connected with rc:", rc)
client.subscribe("sede/status") # Maybe should make it into a constant set'd from config file
def on_message(client, userdata, msg):
print("Received:", msg.topic, "\nWith:", msg.payload.decode("utf-8"))
if msg.topic is not "sede/status":
print("Received:", msg.topic, "\tWith:", msg.payload.decode("utf-8"))
if msg.topic != "sede/status":
return
if msg.payload.decode("utf-8") == 0:
if msg.payload.decode("utf-8") == "1":
for id_ in where_am_i:
updater.bot.send_message(id_, "Il POuL è aperto!")
elif msg.payload.decode("utf-8") == 1:
elif msg.payload.decode("utf-8") == "0":
for id_ in where_am_i:
updater.bot.send_message(id_, "Il POuL è chiuso!")
......
......@@ -4,6 +4,7 @@ from telegram import Update
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)
......
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