/setup command implemented
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from convopyro import listen_message
|
||||
from libbot import i18n
|
||||
@@ -7,6 +8,8 @@ from pyrogram import filters
|
||||
from pyrogram.types import Message, ReplyKeyboardRemove
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
from modules.search_name import search_name
|
||||
from modules.search_nearby import search_nearby
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -17,88 +20,52 @@ logger = logging.getLogger(__name__)
|
||||
async def command_setup(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
await message.reply_text(
|
||||
"Holy... This one is still WIP...", reply_markup=ReplyKeyboardRemove()
|
||||
keyboard_type = ReplyKeyboard(resize_keyboard=True, row_width=1)
|
||||
keyboard_type.add(
|
||||
ReplyButton("Search nearby locations", request_location=True),
|
||||
ReplyButton("Search by location name"),
|
||||
)
|
||||
|
||||
# # City selection
|
||||
# city_names = [city_iter.name for city_iter in await app.get_cities()]
|
||||
# keyboard_cities = ReplyKeyboard(resize_keyboard=True, row_width=2)
|
||||
# keyboard_cities.add(*[ReplyButton(name) for name in city_names])
|
||||
await message.reply_text(
|
||||
"Let's begin configuration with the search for your location. Please, select whether you want to search among the locations near you or go straight to the search by location name.\n\nNote that the location you send to the bot will **NOT** be saved anywhere and is only used for location lookup in the database.",
|
||||
reply_markup=keyboard_type,
|
||||
)
|
||||
|
||||
# await message.reply_text(
|
||||
# "Alright. Please, use the keyboard provided to choose your town.",
|
||||
# reply_markup=keyboard_cities,
|
||||
# )
|
||||
while True:
|
||||
answer_type = await listen_message(app, message.chat.id, 300)
|
||||
|
||||
# while True:
|
||||
# answer_city = await listen_message(app, message.chat.id, 300)
|
||||
if answer_type is None or answer_type.text == "/cancel":
|
||||
await message.reply_text("Cancelled.", reply_markup=ReplyKeyboardRemove())
|
||||
return
|
||||
|
||||
# if answer_city is None or answer_city.text == "/cancel":
|
||||
# await message.reply_text("Cancelled.")
|
||||
# return
|
||||
if answer_type.location is None and answer_type.text not in [
|
||||
"Search by location name",
|
||||
]:
|
||||
await answer_type.reply_text(
|
||||
"Please, select a valid option using keyboard provided. Use /cancel if you want to cancel this operation."
|
||||
)
|
||||
continue
|
||||
|
||||
# if answer_city.text not in city_names:
|
||||
# await answer_city.reply_text(
|
||||
# "Please, select a valid town using keyboard provided. Use /cancel if you want to cancel this operation."
|
||||
# )
|
||||
# continue
|
||||
break
|
||||
|
||||
# break
|
||||
location = (
|
||||
await search_name(app, answer_type)
|
||||
if answer_type.location is None
|
||||
else await search_nearby(app, answer_type)
|
||||
)
|
||||
|
||||
# # City recognition
|
||||
# city = await app.find_city(name=answer_city.text)
|
||||
if location is None:
|
||||
await answer_type.reply_text(
|
||||
"If you want try selecting the location again, use the /setup command.",
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
return
|
||||
|
||||
# # District selection
|
||||
# district_names = [district_iter.name for district_iter in city.districts]
|
||||
# keyboard_districts = ReplyKeyboard(resize_keyboard=True, row_width=2)
|
||||
# keyboard_districts.add(*[ReplyButton(name) for name in district_names])
|
||||
await user.update_location(location.id)
|
||||
|
||||
# await message.reply_text(
|
||||
# "Alright. Please, use the keyboard provided to choose your district.",
|
||||
# reply_markup=keyboard_districts,
|
||||
# )
|
||||
user_time = datetime(1970, 1, 1, user.time_hour, user.time_minute)
|
||||
|
||||
# while True:
|
||||
# answer_district = await listen_message(app, message.chat.id, 300)
|
||||
|
||||
# if answer_district is None or answer_district.text == "/cancel":
|
||||
# await message.reply_text("Cancelled.")
|
||||
# return
|
||||
|
||||
# if answer_district.text not in district_names:
|
||||
# await answer_district.reply_text(
|
||||
# "Please, select a valid district using keyboard provided. Use /cancel if you want to cancel this operation."
|
||||
# )
|
||||
# continue
|
||||
|
||||
# break
|
||||
|
||||
# # District recognition
|
||||
# district_results = city.find_district(answer_district.text)
|
||||
|
||||
# if len(district_results) == 0:
|
||||
# await answer_district.reply_text(
|
||||
# "Something went wrong. Could not find this district in the database.",
|
||||
# reply_markup=ReplyKeyboardRemove(),
|
||||
# )
|
||||
# return
|
||||
|
||||
# district = district_results[0]
|
||||
|
||||
# await user.update_city(city.id)
|
||||
# await user.update_district(district.id)
|
||||
|
||||
# logger.info(
|
||||
# "User %s has finished the location set up with city %s and district %s selected",
|
||||
# user.id,
|
||||
# city.id,
|
||||
# district.id,
|
||||
# )
|
||||
|
||||
# notice = "" if user.enabled else "Execute /toggle to enable notifications."
|
||||
|
||||
# await answer_district.reply_text(
|
||||
# f"All set! You will now receive notification about garbage collection in district **{district.name}** of the town **{city.name}**. {notice}",
|
||||
# reply_markup=ReplyKeyboardRemove(),
|
||||
# )
|
||||
await message.reply_text(
|
||||
f"You will now receive the notifications for **{location.name}** at {user_time.strftime(app._('time', 'formats', locale=user.locale))}, {user.offset} d. before collection.",
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
|
Reference in New Issue
Block a user