Verified Commit 9548f751 authored by Mroik's avatar Mroik
Browse files

Small fixes

This is why you test code before committing...
parent 37966b5f
from telegram.ext import Updater, MessageHandler, Filters
from telegram.ext import Updater, MessageHandler, Filters, CommandHandler, Dispatcher
from tgbot import handlers
def setup(key):
updater = Updater(token=key)
dispatcher = updater.dispatcher
dispatcher: Dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler(
command="setopen",
callback=handlers.set_open
))
dispatcher.add_handler(CommandHandler(
command="setclosed",
callback=handlers.set_closed
))
dispatcher.add_handler(MessageHandler(
filters=Filters.chat_type.groups,
callback=handlers.on_message
......
from telegram.ext import CallbackContext, DispatcherHandlerStop
from telegram import Update
from mt import bot
import mt
from config import ADMIN_CHANNELS
......@@ -13,12 +13,12 @@ def on_message(update: Update, context: CallbackContext):
def check_admin(update: Update, context: CallbackContext):
if update.message.chat.id not in ADMIN_CHANNELS:
if str(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:
if update.message.from_user.id == member.user.id:
is_admin = True
break
return is_admin
......@@ -27,10 +27,10 @@ def check_admin(update: Update, context: CallbackContext):
def set_open(update: Update, context: CallbackContext):
if not check_admin(update, context):
raise DispatcherHandlerStop
bot.mqtt.publish("sede/status", 1)
mt.bot.mqtt.publish("sede/status", 1)
def set_closed(update: Update, context: CallbackContext):
if not check_admin(update, context):
raise DispatcherHandlerStop
bot.mqtt.publish("sede/status", 0)
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