territory deep
This commit is contained in:
parent
c1aa007b1a
commit
6a4333e7c1
|
@ -97,15 +97,17 @@ class TgBot:
|
||||||
self.inv,
|
self.inv,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
TgBot.app.add_handler(CommandHandler("ter", self.ter, filters.ChatType.PRIVATE))
|
||||||
TgBot.app.add_handler(
|
TgBot.app.add_handler(
|
||||||
MessageHandler(
|
MessageHandler(
|
||||||
filters.ChatType.PRIVATE & filters.Regex(r"/ter_(\d.*)"),
|
filters.ChatType.PRIVATE & filters.Regex(r"/ter_(\d.*)"),
|
||||||
self.ter_deep,
|
self.ter_deep,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
TgBot.app.add_handler(CommandHandler("ter", self.ter, filters.ChatType.PRIVATE))
|
|
||||||
TgBot.app.add_handler(CallbackQueryHandler(self.ter_back, "ter_back"))
|
TgBot.app.add_handler(CallbackQueryHandler(self.ter_back, "ter_back"))
|
||||||
TgBot.app.add_handler(CallbackQueryHandler(self.ter_next, "ter_next"))
|
TgBot.app.add_handler(CallbackQueryHandler(self.ter_next, "ter_next"))
|
||||||
|
TgBot.app.add_handler(CallbackQueryHandler(self.terdeep_back, "terdeep_back"))
|
||||||
|
TgBot.app.add_handler(CallbackQueryHandler(self.terdeep_next, "terdeep_next"))
|
||||||
TgBot.app.add_handler(CallbackQueryHandler(self.stop_inv, "stop_inv"))
|
TgBot.app.add_handler(CallbackQueryHandler(self.stop_inv, "stop_inv"))
|
||||||
TgBot.app.add_handler(CallbackQueryHandler(self.get_inv, r"get_inv@(.*?)"))
|
TgBot.app.add_handler(CallbackQueryHandler(self.get_inv, r"get_inv@(.*?)"))
|
||||||
TgBot.app.add_handler(CallbackQueryHandler(self.add_tmc, r"add_tmc@(.*?)"))
|
TgBot.app.add_handler(CallbackQueryHandler(self.add_tmc, r"add_tmc@(.*?)"))
|
||||||
|
@ -189,20 +191,6 @@ class TgBot:
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
async def ter_back(self, update: Update, context: CallbackContext):
|
|
||||||
query = update.callback_query
|
|
||||||
await query.answer()
|
|
||||||
context.chat_data["territory_start"] -= context.chat_data["territory_count"]
|
|
||||||
context.chat_data["territory_renew"] = True
|
|
||||||
await self.inv(update, context)
|
|
||||||
|
|
||||||
async def ter_next(self, update: Update, context: CallbackContext):
|
|
||||||
query = update.callback_query
|
|
||||||
await query.answer()
|
|
||||||
context.chat_data["territory_start"] += context.chat_data["territory_count"]
|
|
||||||
context.chat_data["territory_renew"] = True
|
|
||||||
await self.inv(update, context)
|
|
||||||
|
|
||||||
async def stop_inv(self, update: Update, context: CallbackContext):
|
async def stop_inv(self, update: Update, context: CallbackContext):
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
await update.effective_message.edit_reply_markup(InlineKeyboardMarkup([]))
|
await update.effective_message.edit_reply_markup(InlineKeyboardMarkup([]))
|
||||||
|
@ -262,23 +250,37 @@ class TgBot:
|
||||||
|
|
||||||
await self.inv(update, context)
|
await self.inv(update, context)
|
||||||
|
|
||||||
|
async def ter_back(self, update: Update, context: CallbackContext):
|
||||||
|
query = update.callback_query
|
||||||
|
await query.answer()
|
||||||
|
context.chat_data["ter_start"] -= context.chat_data["ter_count"]
|
||||||
|
context.chat_data["ter_renew"] = True
|
||||||
|
await self.ter(update, context)
|
||||||
|
|
||||||
|
async def ter_next(self, update: Update, context: CallbackContext):
|
||||||
|
query = update.callback_query
|
||||||
|
await query.answer()
|
||||||
|
context.chat_data["ter_start"] += context.chat_data["ter_count"]
|
||||||
|
context.chat_data["ter_renew"] = True
|
||||||
|
await self.ter(update, context)
|
||||||
|
|
||||||
async def ter(self, update: Update, context: CallbackContext):
|
async def ter(self, update: Update, context: CallbackContext):
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
current_step = context.chat_data.get("step", None)
|
current_step = context.chat_data.get("step", None)
|
||||||
|
|
||||||
logger.info(f"Step {current_step} from user {user.full_name}")
|
logger.info(f"Step {current_step} from user {user.full_name}")
|
||||||
context.chat_data["step"] = "territory"
|
context.chat_data["step"] = "territory"
|
||||||
if "territory_start" not in context.chat_data:
|
if "ter_start" not in context.chat_data:
|
||||||
context.chat_data["territory_start"] = 10
|
context.chat_data["ter_start"] = 0
|
||||||
if "territory_count" not in context.chat_data:
|
if "ter_count" not in context.chat_data:
|
||||||
context.chat_data["territory_count"] = 10
|
context.chat_data["ter_count"] = 10
|
||||||
|
|
||||||
locations = []
|
locations = []
|
||||||
async for e in Territory.objects.all():
|
async for e in Territory.objects.all():
|
||||||
locations.append({"name": e.name, "id": e.id})
|
locations.append({"name": e.name, "id": e.id})
|
||||||
|
|
||||||
ter_start = context.chat_data["territory_start"]
|
ter_start = context.chat_data["ter_start"]
|
||||||
ter_step = context.chat_data["territory_count"]
|
ter_step = context.chat_data["ter_count"]
|
||||||
ter_end = ter_start + ter_step
|
ter_end = ter_start + ter_step
|
||||||
|
|
||||||
text = "\n".join(
|
text = "\n".join(
|
||||||
|
@ -295,6 +297,7 @@ class TgBot:
|
||||||
)
|
)
|
||||||
|
|
||||||
keyboard = []
|
keyboard = []
|
||||||
|
logger.info((ter_start, ter_end))
|
||||||
if ter_start > 0:
|
if ter_start > 0:
|
||||||
keyboard.append(InlineKeyboardButton(text="←", callback_data="ter_back"))
|
keyboard.append(InlineKeyboardButton(text="←", callback_data="ter_back"))
|
||||||
if ter_end < len(locations):
|
if ter_end < len(locations):
|
||||||
|
@ -302,7 +305,7 @@ class TgBot:
|
||||||
|
|
||||||
keyboard = [keyboard]
|
keyboard = [keyboard]
|
||||||
|
|
||||||
if "territory_renew" in context.chat_data:
|
if "ter_renew" in context.chat_data:
|
||||||
await update.effective_message.edit_text(
|
await update.effective_message.edit_text(
|
||||||
text,
|
text,
|
||||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
||||||
|
@ -315,28 +318,39 @@ class TgBot:
|
||||||
),
|
),
|
||||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
||||||
)
|
)
|
||||||
|
async def terdeep_back(self, update: Update, context: CallbackContext):
|
||||||
|
query = update.callback_query
|
||||||
|
await query.answer()
|
||||||
|
context.chat_data["terdeep_start"] -= context.chat_data["terdeep_count"]
|
||||||
|
context.chat_data["terdeep_renew"] = True
|
||||||
|
await self.ter(update, context)
|
||||||
|
|
||||||
|
async def terdeep_next(self, update: Update, context: CallbackContext):
|
||||||
|
query = update.callback_query
|
||||||
|
await query.answer()
|
||||||
|
context.chat_data["terdeep_start"] += context.chat_data["terdeep_count"]
|
||||||
|
context.chat_data["terdeep_renew"] = True
|
||||||
|
await self.ter(update, context)
|
||||||
|
|
||||||
async def ter_deep(self, update: Update, context: CallbackContext):
|
async def ter_deep(self, update: Update, context: CallbackContext):
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
current_step = context.chat_data.get("step", None)
|
current_step = context.chat_data.get("step", None)
|
||||||
|
|
||||||
logger.info(f"Step {current_step} from user {user.full_name}")
|
logger.info(f"Step {current_step} from user {user.full_name}")
|
||||||
context.chat_data["step"] = "territory"
|
context.chat_data["step"] = "terdeep"
|
||||||
# if "territory_start" not in context.chat_data:
|
if "terdeep_start" not in context.chat_data:
|
||||||
# context.chat_data["territory_start"] = 10
|
context.chat_data["terdeep_start"] = 0
|
||||||
# if "territory_count" not in context.chat_data:
|
if "terdeep_count" not in context.chat_data:
|
||||||
# context.chat_data["territory_count"] = 10
|
context.chat_data["terdeep_count"] = 10
|
||||||
|
|
||||||
parent = re.findall(r"/ter_(\d.*)", update.effective_message.text)
|
parent = re.findall(r"/ter_(\d.*)", update.effective_message.text)
|
||||||
ter = await Territory.objects.aget(id=parent[0])
|
ter = await Territory.objects.aget(id=parent[0])
|
||||||
locations = []
|
locations = []
|
||||||
async for e in TerritoryItem.objects.filter(parent=ter):
|
async for e in TerritoryItem.objects.filter(parent=ter):
|
||||||
locations.append({"name": e.name, "id": e.id})
|
locations.append({"name": e.name, "id": e.id})
|
||||||
logger.info(parent[0])
|
|
||||||
# ter_start = context.chat_data["territory_start"]
|
ter_start = context.chat_data["terdeep_start"]
|
||||||
# ter_step = context.chat_data["territory_count"]
|
ter_step = context.chat_data["terdeep_count"]
|
||||||
ter_start = 0
|
|
||||||
ter_step = 10
|
|
||||||
ter_end = ter_start + ter_step
|
ter_end = ter_start + ter_step
|
||||||
|
|
||||||
text = "\n".join(
|
text = "\n".join(
|
||||||
|
@ -344,7 +358,7 @@ class TgBot:
|
||||||
"Выберите:",
|
"Выберите:",
|
||||||
"\n".join(
|
"\n".join(
|
||||||
[
|
[
|
||||||
f"/ter_{i['id']} {i['name']}"
|
f"/terdeep_{i['id']} {i['name']}"
|
||||||
for i in locations[ter_start:ter_end]
|
for i in locations[ter_start:ter_end]
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
@ -353,13 +367,17 @@ class TgBot:
|
||||||
|
|
||||||
keyboard = []
|
keyboard = []
|
||||||
if ter_start > 0:
|
if ter_start > 0:
|
||||||
keyboard.append(InlineKeyboardButton(text="←", callback_data="ter_back"))
|
keyboard.append(
|
||||||
|
InlineKeyboardButton(text="←", callback_data="terdeep_back")
|
||||||
|
)
|
||||||
if ter_end < len(locations):
|
if ter_end < len(locations):
|
||||||
keyboard.append(InlineKeyboardButton(text="→", callback_data="ter_next"))
|
keyboard.append(
|
||||||
|
InlineKeyboardButton(text="→", callback_data="terdeep_next")
|
||||||
|
)
|
||||||
|
|
||||||
keyboard = [keyboard]
|
keyboard = [keyboard]
|
||||||
|
|
||||||
if "territory_renew" in context.chat_data:
|
if "terdeep_renew" in context.chat_data:
|
||||||
await update.effective_message.edit_text(
|
await update.effective_message.edit_text(
|
||||||
text,
|
text,
|
||||||
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
reply_markup=InlineKeyboardMarkup(inline_keyboard=keyboard),
|
||||||
|
|
Loading…
Reference in New Issue