Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
teleexit/callbackQuery/new.py

44 lines
2.9 KiB
Python
Raw Normal View History

2020-11-07 12:16:52 +01:00
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
from telegram.ext import CallbackContext
2020-11-07 15:15:44 +01:00
import db
from main import reasons
def new(update: Update, context: CallbackContext):
2020-11-07 15:15:44 +01:00
s = db.Session()
u = s.query(db.User).get(update["_effective_user"]["id"])
if not u or not all([u.first_name, u.last_name, u.birth_date, u.birth_city, u.address]):
context.bot.send_message(chat_id=update.effective_chat.id, text="You have no data saved !",
2020-11-07 15:34:03 +01:00
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("⚙️ Set data",
callback_data="data")],
2020-11-07 15:34:03 +01:00
[InlineKeyboardButton("🏘 Home", callback_data="home")]
]))
else:
2020-11-07 12:16:52 +01:00
if update.effective_chat.id not in reasons:
reasons[update.effective_chat.id] = {}
if update["_effective_user"]["id"] not in reasons[update.effective_chat.id]:
reasons[update.effective_chat.id][update["_effective_user"]["id"]] = []
2020-11-07 15:34:03 +01:00
last_line = [InlineKeyboardButton("🏘 Home", callback_data="home")]
2020-11-07 12:16:52 +01:00
if len(reasons[update.effective_chat.id][update["_effective_user"]["id"]]) != 0:
2020-11-07 15:34:03 +01:00
last_line.append(InlineKeyboardButton("✅ Send", callback_data="create"))
2020-11-07 12:16:52 +01:00
context.bot.send_message(chat_id=update.effective_chat.id,
text=f"Select your reasons\n`" +
"`, `".join(reasons[update.effective_chat.id][update["_effective_user"]["id"]]) +
"`",
parse_mode=ParseMode.MARKDOWN_V2,
reply_markup=InlineKeyboardMarkup([
2020-11-07 15:34:03 +01:00
[InlineKeyboardButton("💼 Work", callback_data="reason_work"),
InlineKeyboardButton("🛒 Shopping", callback_data="reason_shopping")],
[InlineKeyboardButton("💊 Health", callback_data="reason_health"),
InlineKeyboardButton("👨‍👩‍👧‍👦 Family", callback_data="reason_family")],
[InlineKeyboardButton("♿️ Handicap", callback_data="reason_handicap"),
InlineKeyboardButton("🚴‍♀️🐕 Sport/animal", callback_data="reason_sport_animal")],
[InlineKeyboardButton("⚖️ Injunction", callback_data="reason_injunction"),
InlineKeyboardButton("📜 Missions", callback_data="reason_missions")],
[InlineKeyboardButton("👶 Children", callback_data="reason_children")],
2020-11-07 12:16:52 +01:00
last_line]))