using right chat id for callback message

Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
klux2 2019-10-02 19:16:40 +02:00
parent c98619a524
commit 2c7337f0e0

View file

@ -70,11 +70,6 @@ class EnumEncode(json.JSONEncoder):
class HSMensaW(telepot.aio.helper.ChatHandler):
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Deutsch", callback_data=Language.GERMAN.value)],
[InlineKeyboardButton(text="English", callback_data=Language.ENGLISH.value)],
[InlineKeyboardButton(text="Deutsch + English", callback_data=Language.GERMAN_ENGLISH.value)],
])
async def on_chat_message(self, msg: dict) -> None:
global config, essen, status, var, logging_enabled
@ -137,9 +132,15 @@ class HSMensaW(telepot.aio.helper.ChatHandler):
elif text.startswith("/settings"):
if chat_id in ids:
await send_message(bot_obj=bot, chat_id=chat_id,
msg="Bitte Sprache(n) auswählen/Please select language(s)",
reply_markup=self.keyboard)
callback_chat_id = "::" + str(chat_id)
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Deutsch", callback_data=Language.GERMAN.value + callback_chat_id)],
[InlineKeyboardButton(text="English", callback_data=Language.ENGLISH.value + callback_chat_id)],
[InlineKeyboardButton(text="Deutsch + English",
callback_data=Language.GERMAN_ENGLISH.value + callback_chat_id)],
])
await send_message(bot_obj=bot, chat_id=chat_id, msg="Bitte Sprache(n) auswählen/Please select "
"language(s)", reply_markup=keyboard)
else:
await send_message(bot_obj=bot, chat_id=chat_id,
msg="Bitte starten Sie zuerst den Bot/Please start the bot first.\n/start")
@ -176,20 +177,25 @@ class HSMensaW(telepot.aio.helper.ChatHandler):
global config, ids
query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
lang = query_data[:query_data.index("::")]
chat_id = int(query_data[query_data.index("::") + 2:])
message = "Fehler beim Setzen der Sprache"
if query_data == Language.GERMAN.value:
if lang == Language.GERMAN.value:
message = "Sprache geändert nach _deutsch_."
elif query_data == Language.ENGLISH.value:
elif lang == Language.ENGLISH.value:
message = "Changed language to _english_."
elif query_data == Language.GERMAN_ENGLISH.value:
elif lang == Language.GERMAN_ENGLISH.value:
message = "Sprache geändert nach _deutsch + englisch_. Changed language to _german + english_."
if from_id in ids:
ids[from_id] = Language(query_data)
if chat_id in ids:
ids[chat_id] = Language(lang)
config['ids'] = ids
write_config()
else:
message = "Fehler: Bot nicht aktiviert für diesen Chat!"
await send_message(bot_obj=bot, chat_id=from_id, msg=message, parse_mode="markdown")
await send_message(bot_obj=bot, chat_id=chat_id, msg=message, parse_mode="markdown")
async def send_essen(chat_id: int, sprache: Language = Language.GERMAN) -> None: