mirror of
https://github.com/Noettore/lagomareGateKeeperBot.git
synced 2025-10-15 19:46:40 +02:00
Refactor gates creating service, repository and tests
This commit is contained in:
50
src/handlers/main.py
Normal file
50
src/handlers/main.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import Application, ContextTypes
|
||||
from .gates import open_gate_menu
|
||||
from .access import requestaccess
|
||||
from models import Gates, Users, Role
|
||||
from config import BotConfig
|
||||
|
||||
async def post_init(application: Application, bot_config: BotConfig) -> None:
|
||||
await application.bot.set_my_name(bot_config.name)
|
||||
await application.bot.set_my_description(bot_config.description)
|
||||
await application.bot.set_my_short_description(bot_config.short_description)
|
||||
await application.bot.set_my_commands(bot_config.commands)
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users):
|
||||
assert update.effective_user is not None
|
||||
assert update.message is not None
|
||||
|
||||
user_id = str(update.effective_user.id)
|
||||
role = users.get_role(user_id)
|
||||
keyboard = []
|
||||
|
||||
if role == Role.GUEST:
|
||||
# Guests: can request access, or open a gate if granted
|
||||
if users.has_grants(user_id):
|
||||
keyboard.append([InlineKeyboardButton("Open Gate", callback_data="open_gate_menu")])
|
||||
keyboard.append([InlineKeyboardButton("Request Access", callback_data="request_access")])
|
||||
elif role == Role.MEMBER:
|
||||
# Members: can open gates and set credentials
|
||||
keyboard.append([InlineKeyboardButton("Open Gate", callback_data="open_gate_menu")])
|
||||
keyboard.append([InlineKeyboardButton("Set Credentials", callback_data="set_credentials")])
|
||||
elif role == Role.ADMIN:
|
||||
# Admins: can open gates, grant access, and set credentials
|
||||
keyboard.append([InlineKeyboardButton("Open Gate", callback_data="open_gate_menu")])
|
||||
keyboard.append([InlineKeyboardButton("Grant Access", callback_data="grant_access")])
|
||||
keyboard.append([InlineKeyboardButton("Set Credentials", callback_data="set_credentials")])
|
||||
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await update.message.reply_text(
|
||||
"Welcome to GatekeeperBot! Use the buttons below or commands.",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
async def handle_main_menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users, gates: Gates):
|
||||
query = update.callback_query
|
||||
assert query is not None
|
||||
data = query.data
|
||||
if data == "open_gate_menu":
|
||||
await open_gate_menu(update, context, users=users, gates=gates)
|
||||
elif data == "request_access":
|
||||
await requestaccess(update, context, users=users)
|
Reference in New Issue
Block a user