WIP: Locale strings
This commit is contained in:
@@ -22,8 +22,6 @@ async def remind(app: PyroClient) -> None:
|
||||
for user_db in users:
|
||||
user = PyroUser(**user_db)
|
||||
|
||||
logger.info("Processing %s...", user.id)
|
||||
|
||||
if not user.enabled or user.location is None:
|
||||
continue
|
||||
|
||||
@@ -61,7 +59,7 @@ async def remind(app: PyroClient) -> None:
|
||||
|
||||
await app.send_message(
|
||||
user.id,
|
||||
"**Garbage Collection**\n\nType: {type}\nDate: {date}\n\nDon't forget to prepare your bin for collection!".format(
|
||||
app._("reminder", "messages", locale=user.locale).format(
|
||||
type=garbage_type, date=garbage_date
|
||||
),
|
||||
)
|
||||
|
@@ -10,24 +10,37 @@ from modules.database import col_locations
|
||||
|
||||
|
||||
async def search_name(app: PyroClient, message: Message) -> Union[Location, None]:
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
location: Union[Location, None] = None
|
||||
|
||||
await message.reply_text(
|
||||
"Please, send me a location name. It should be the name used in your local authorities' garbage collection schedule. This usually is a name of the district or even the town itself.",
|
||||
reply_markup=ForceReply(placeholder="Location name"),
|
||||
app._("location_request_name", "messages", locale=user.locale),
|
||||
reply_markup=ForceReply(
|
||||
placeholder=app._("location_name", "force_replies", locale=user.locale)
|
||||
),
|
||||
)
|
||||
|
||||
while location is None:
|
||||
answer = await listen_message(app, message.chat.id, 300)
|
||||
|
||||
if answer is None or answer.text == "/cancel":
|
||||
await message.reply_text("Cancelled.", reply_markup=ReplyKeyboardRemove())
|
||||
await message.reply_text(
|
||||
app._("cancelled", "messages", locale=user.locale),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
return
|
||||
|
||||
if answer.text is None:
|
||||
await message.reply_text(
|
||||
"Please, send the name of the location as a text. You can also abort this operation with /cancel command.",
|
||||
reply_markup=ForceReply(placeholder="Location name"),
|
||||
app._("location_name_invalid", "messages", locale=user.locale).format(
|
||||
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
||||
),
|
||||
reply_markup=ForceReply(
|
||||
placeholder=app._(
|
||||
"location_name", "force_replies", locale=user.locale
|
||||
)
|
||||
),
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -37,8 +50,14 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
|
||||
|
||||
if len(locations) == 0:
|
||||
await message.reply_text(
|
||||
"Could not find any locations by this name. Try rephrasing it or make sure you use the same location language and name itself as it in written by your local authorities in garbage collection schedule.\n\nYou can also abort this operation with /cancel command.",
|
||||
reply_markup=ForceReply(placeholder="Location name"),
|
||||
app._("location_name_empty", "messages", locale=user.locale).format(
|
||||
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
||||
),
|
||||
reply_markup=ForceReply(
|
||||
placeholder=app._(
|
||||
"location_name", "force_replies", locale=user.locale
|
||||
)
|
||||
),
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -46,7 +65,8 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
|
||||
keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations])
|
||||
|
||||
await message.reply_text(
|
||||
"Select the location using the keyboard", reply_markup=keyboard
|
||||
app._("location_select", "messages", locale=user.locale),
|
||||
reply_markup=keyboard,
|
||||
)
|
||||
|
||||
while True:
|
||||
@@ -54,7 +74,8 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
|
||||
|
||||
if answer is None or answer.text == "/cancel":
|
||||
await message.reply_text(
|
||||
"Cancelled.", reply_markup=ReplyKeyboardRemove()
|
||||
app._("cancelled", "messages", locale=user.locale),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
return
|
||||
|
||||
@@ -64,7 +85,9 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
|
||||
|
||||
if answer.text is None or location is None:
|
||||
await answer.reply_text(
|
||||
"Please, select a valid location using keyboard provided. Use /cancel if you want to cancel this operation.",
|
||||
app._("selection_invalid", "messages", locale=user.locale).format(
|
||||
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
from bson.son import SON
|
||||
from convopyro import listen_message
|
||||
from pykeyboard import ReplyButton, ReplyKeyboard
|
||||
from pyrogram.types import Message, ReplyKeyboardRemove
|
||||
@@ -12,6 +11,8 @@ from modules.search_name import search_name
|
||||
|
||||
|
||||
async def search_nearby(app: PyroClient, message: Message) -> Union[Location, None]:
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
query = {
|
||||
"location": {
|
||||
"$within": {
|
||||
@@ -27,7 +28,7 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
|
||||
|
||||
if len(locations) == 0:
|
||||
await message.reply_text(
|
||||
"Could not find any locations nearby. Let's try using the name search."
|
||||
app._("search_nearby_empty", "messages", locale=user.locale)
|
||||
)
|
||||
return await search_name(app, message)
|
||||
|
||||
@@ -35,7 +36,8 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
|
||||
keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations])
|
||||
|
||||
await message.reply_text(
|
||||
"Select the location using the keyboard", reply_markup=keyboard
|
||||
app._("location_select", "messages", locale=user.locale),
|
||||
reply_markup=keyboard,
|
||||
)
|
||||
|
||||
while True:
|
||||
@@ -43,7 +45,10 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
|
||||
location: Union[Location, None] = None
|
||||
|
||||
if answer is None or answer.text == "/cancel":
|
||||
await message.reply_text("Cancelled.", reply_markup=ReplyKeyboardRemove())
|
||||
await message.reply_text(
|
||||
app._("cancelled", "messages", locale=user.locale),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
return
|
||||
|
||||
for db_record in locations:
|
||||
@@ -53,7 +58,9 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
|
||||
|
||||
if answer.text is None or location is None:
|
||||
await answer.reply_text(
|
||||
"Please, select a valid location using keyboard provided. Use /cancel if you want to cancel this operation."
|
||||
app._("selection_invalid", "messages", locale=user.locale).format(
|
||||
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
|
Reference in New Issue
Block a user