Verified Commit 37966b5f authored by Mroik's avatar Mroik
Browse files

Added set HQ's status

Committing untested code cuz I like living on the edge
parent 60ff0bf5
......@@ -6,3 +6,5 @@ PORT = int(environ.get("BITS_PORT", default=1883))
USERNAME = environ.get("BITS_USER")
PASSWORD = environ.get("BITS_PASSWORD", default="")
TG_KEY = environ.get("BITS_TG_KEY", default="")
ADMIN_CHANNELS = [] # Channels that are allowed to change HQ's status
from mt.bot import Bot
import mt
from config import (
SERVER,
PORT,
......@@ -6,8 +7,8 @@ from config import (
def main():
bot = Bot(SERVER, PORT)
bot.start()
mt.bot = Bot(SERVER, PORT)
mt.bot.start()
if __name__ == "__main__":
......
from mt.bot import Bot
bot: Bot = None
......@@ -16,11 +16,3 @@ def on_message(client, userdata, msg):
elif msg.payload.decode("utf-8") == "0":
for id_ in where_am_i:
updater.bot.send_message(id_, "Il POuL è chiuso!")
def send_open(bot):
bot.mqtt.publish("sede/status", 1)
def send_closed(bot):
bot.mqtt.publish("sede/status", 0)
from telegram.ext import CallbackContext
from telegram.ext import CallbackContext, DispatcherHandlerStop
from telegram import Update
from mt import bot
from config import ADMIN_CHANNELS
def on_message(update: Update, context: CallbackContext):
from . import where_am_i # Because circular imports
......@@ -9,11 +12,25 @@ def on_message(update: Update, context: CallbackContext):
where_am_i.append(update.message.chat.id)
def check_admin(update: Update, context: CallbackContext):
if update.message.chat.id not in ADMIN_CHANNELS:
raise DispatcherHandlerStop
is_admin = False
for member in context.bot.get_chat_administrators(update.message.chat.id):
if update.message.from_user.id == member.id:
is_admin = True
break
return is_admin
def set_open(update: Update, context: CallbackContext):
"""TODO"""
pass
if not check_admin(update, context):
raise DispatcherHandlerStop
bot.mqtt.publish("sede/status", 1)
def set_closed(update: Update, context: CallbackContext):
"""TODO"""
pass
if not check_admin(update, context):
raise DispatcherHandlerStop
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