Sync #6

Merged
profitroll merged 9 commits from dev into i18n 2023-08-30 15:43:30 +03:00
17 changed files with 61 additions and 16 deletions

View File

@ -18,6 +18,7 @@ class PyroClient(LibPyroClient):
self.scheduler.add_job( self.scheduler.add_job(
remind, CronTrigger.from_crontab("* * * * *"), args=(self,) remind, CronTrigger.from_crontab("* * * * *"), args=(self,)
) )
self.contexts = []
async def start(self, **kwargs): async def start(self, **kwargs):
await col_locations.create_index( await col_locations.create_index(

View File

@ -10,4 +10,9 @@ async def _owner_func(_, __: PyroClient, message: Message):
return False if message.from_user is None else __.owner == message.from_user.id return False if message.from_user is None else __.owner == message.from_user.id
async def _context_func(_, __: PyroClient, message: Message):
return message.from_user.id in __.contexts
owner = filters.create(_owner_func) owner = filters.create(_owner_func)
context = filters.create(_context_func)

View File

@ -39,7 +39,7 @@ async def remind(app: PyroClient) -> None:
entries = await col_entries.find( entries = await col_entries.find(
{ {
"location": {"$in": location.id}, "locations": location.id,
"date": user_date.replace(hour=0, minute=0), "date": user_date.replace(hour=0, minute=0),
} }
).to_list() ).to_list()

View File

@ -22,7 +22,9 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
) )
while location is None: while location is None:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(
@ -48,7 +50,7 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
locations = await col_locations.find(query).limit(6).to_list() locations = await col_locations.find(query).limit(6).to_list()
if len(locations) == 0: if len(locations) == 0 or locations is None:
await message.reply_text( await message.reply_text(
app._("location_name_empty", "messages", locale=user.locale).format( app._("location_name_empty", "messages", locale=user.locale).format(
cancel_notice=app._("cancel", "messages", locale=user.locale) cancel_notice=app._("cancel", "messages", locale=user.locale)
@ -61,6 +63,8 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
) )
continue continue
locations.reverse()
keyboard = ReplyKeyboard(resize_keyboard=True, row_width=2) keyboard = ReplyKeyboard(resize_keyboard=True, row_width=2)
keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations]) keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations])
@ -70,7 +74,9 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -32,6 +32,8 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
) )
return await search_name(app, message) return await search_name(app, message)
locations.reverse()
keyboard = ReplyKeyboard(resize_keyboard=True, row_width=2) keyboard = ReplyKeyboard(resize_keyboard=True, row_width=2)
keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations]) keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations])
@ -41,7 +43,10 @@ async def search_nearby(app: PyroClient, message: Message) -> Union[Location, No
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
location: Union[Location, None] = None location: Union[Location, None] = None
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":

View File

@ -8,12 +8,13 @@ from pyrogram.types import Message, ReplyKeyboardRemove
from ujson import dumps from ujson import dumps
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["checkout"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["checkout"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_checkout(app: PyroClient, message: Message): async def command_checkout(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -42,7 +43,9 @@ async def command_checkout(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer_delete = await listen_message(app, message.chat.id, 300) answer_delete = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer_delete is None or answer_delete.text == "/cancel": if answer_delete is None or answer_delete.text == "/cancel":
await message.reply_text( await message.reply_text(
@ -84,7 +87,9 @@ async def command_checkout(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer_confirm = await listen_message(app, message.chat.id, 300) answer_confirm = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer_confirm is None or answer_confirm.text == "/cancel": if answer_confirm is None or answer_confirm.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -2,10 +2,11 @@ from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["help"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["help"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_help(app: PyroClient, message: Message): async def command_help(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)

View File

@ -12,18 +12,22 @@ from modules.database import col_entries
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & custom_filters.owner & filters.command(["import"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & custom_filters.owner & filters.command(["import"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_import(app: PyroClient, message: Message): async def command_import(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
await message.reply_text( await message.reply_text(
app._("import", "messages", locale=user.locale), app._("import", "messages", locale=user.locale),
reply_markup=ForceReply(placeholder=""), reply_markup=ForceReply(
placeholder=app._("import", "force_replies", locale=user.locale)
),
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -2,10 +2,11 @@ from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_remove_commands(app: PyroClient, message: Message): async def command_remove_commands(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)

View File

@ -6,12 +6,13 @@ from pyrogram import filters
from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["set_offset"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["set_offset"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_set_offset(app: PyroClient, message: Message): async def command_set_offset(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -24,7 +25,9 @@ async def command_set_offset(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -6,12 +6,13 @@ from pyrogram import filters
from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["set_time"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["set_time"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_set_time(app: PyroClient, message: Message): async def command_set_time(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -24,7 +25,9 @@ async def command_set_time(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -8,6 +8,7 @@ from pyrogram import filters
from pyrogram.types import Message, ReplyKeyboardRemove from pyrogram.types import Message, ReplyKeyboardRemove
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
from modules.search_name import search_name from modules.search_name import search_name
from modules.search_nearby import search_nearby from modules.search_nearby import search_nearby
@ -15,7 +16,7 @@ logger = logging.getLogger(__name__)
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["setup"] + i18n.sync.in_all_locales("start_configure", "buttons"), prefixes=["/", ""]) # type: ignore ~filters.scheduled & filters.private & filters.command(["setup"] + i18n.sync.in_all_locales("start_configure", "buttons"), prefixes=["/", ""]) & ~custom_filters.context # type: ignore
) )
async def command_setup(app: PyroClient, message: Message): async def command_setup(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -34,7 +35,9 @@ async def command_setup(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer_type = await listen_message(app, message.chat.id, 300) answer_type = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer_type is None or answer_type.text == "/cancel": if answer_type is None or answer_type.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -4,12 +4,14 @@ from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled ~filters.scheduled
& filters.private & filters.private
& filters.command(["shutdown", "reboot", "restart"], prefixes=["/"]) # type: ignore & filters.command(["shutdown", "reboot", "restart"], prefixes=["/"])
& ~custom_filters.context # type: ignore
) )
async def command_shutdown(app: PyroClient, msg: Message): async def command_shutdown(app: PyroClient, msg: Message):
if msg.from_user.id == app.owner: if msg.from_user.id == app.owner:

View File

@ -10,10 +10,11 @@ from pyrogram.types import (
) )
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_start(app: PyroClient, message: Message): async def command_start(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -52,7 +53,9 @@ async def command_start(app: PyroClient, message: Message):
) )
while True: while True:
app.contexts.append(message.from_user.id)
answer = await listen_message(app, message.chat.id, 300) answer = await listen_message(app, message.chat.id, 300)
app.contexts.remove(message.from_user.id)
if answer is None or answer.text == "/cancel": if answer is None or answer.text == "/cancel":
await message.reply_text( await message.reply_text(

View File

@ -4,10 +4,11 @@ from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["toggle"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["toggle"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_toggle(app: PyroClient, message: Message): async def command_toggle(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)

View File

@ -6,11 +6,12 @@ from pytz import timezone as pytz_timezone
from classes.garbage_entry import GarbageEntry from classes.garbage_entry import GarbageEntry
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
from modules.database import col_entries from modules.database import col_entries
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["upcoming"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["upcoming"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_upcoming(app: PyroClient, message: Message): async def command_upcoming(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)
@ -37,7 +38,7 @@ async def command_upcoming(app: PyroClient, message: Message):
await GarbageEntry.from_record(entry) await GarbageEntry.from_record(entry)
async for entry in col_entries.find( async for entry in col_entries.find(
{ {
"location": {"$in": user.location.id}, "locations": user.location.id,
"date": {"$gte": date_min, "$lte": date_max}, "date": {"$gte": date_min, "$lte": date_max},
} }
) )

View File

@ -6,10 +6,11 @@ from pyrogram.types import CallbackQuery, Message
from classes.callbacks import CallbackLanguage from classes.callbacks import CallbackLanguage
from classes.pyroclient import PyroClient from classes.pyroclient import PyroClient
from modules import custom_filters
@PyroClient.on_message( @PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) & ~custom_filters.context # type: ignore
) )
async def command_language(app: PyroClient, message: Message): async def command_language(app: PyroClient, message: Message):
user = await app.find_user(message.from_user) user = await app.find_user(message.from_user)