async def exped(self):
while self.config.get("expedition", False):
if self.nextexp is None or datetime.now() >= datetime.strptime(self.nextexp, "%Y-%m-%d %H:%M:%S"):
await self.client.send_message("@game_bot", "Expeditions")
await asyncio.sleep(3)
msg = await self.client.get_messages("@game_bot")
if "Current Expedition" in msg[0].message:
wait_time_match = re.search(r"After : s+(d+)h.s+(d+)min.s+(d+)sec", msg[0].message)
if wait_time_match:
hours, minutes, seconds = map(int, wait_time_match.groups())
next_exp_time = datetime.now() + timedelta(hours=hours, minutes=minutes, seconds=seconds)
self.set("nextexp", next_exp_time.strftime("%Y-%m-%d %H:%M:%S"))
self.nextexp = next_exp_time.strftime("%Y-%m-%d %H:%M:%S")
elif "Expedition levels" in msg[0].message:
await msg[0].click(0)
await asyncio.sleep(3)
if "Available expeditions" in msg[0].message:
time_matches = re.findall(r"⏳.*?(d+)h.s*(d+)min.s*(d+)sec", msg[0].message)
if time_matches:
max_time = max([int(hours) * 3600 + int(minutes) * 60 + int(seconds) for hours, minutes, seconds in time_matches])
longest_index = [int(hours) * 3600 + int(minutes) * 60 + int(seconds) for hours, minutes, seconds in time_matches].index(max_time)
hours, minutes, seconds = map(int, time_matches[longest_index])
next_expedition_time = datetime.now() + timedelta(hours=hours, minutes=minutes, seconds=seconds)
self.set("nextexp", next_expedition_time.strftime("%Y-%m-%d %H:%M:%S"))
self.nextexp = next_expedition_time.strftime("%Y-%m-%d %H:%M:%S")
if 0 <= longest_index <= 2 and msg[0].buttons and longest_index < len(msg[0].buttons):
await msg[0].click(longest_index)
await asyncio.sleep(2)
await msg[0].click(0)
elif "The expedition is over" in msg[0].message:
if msg and msg[0].buttons:
await msg[0].click(0)
self.set("nextexp", None)
else:
wait_seconds = (datetime.strptime(self.nextexp, "%Y-%m-%d %H:%M:%S") - datetime.now()).total_seconds() + 2
await asyncio.sleep(wait_seconds)
There is such a module code for a userbot on telegram. Which performs the function of automatically sending to the expedition in the game bot. My problem starts with ” elif ” Expedition levels” in msg[0].message:”
After the code clicks on the inline form of the message, it is edited and the buttons are changed, I need to correctly parse the modified message and the new buttons on it. Because there is an important stage in estimating the time of this expedition.
I tried saving the message.id and then accessing it, but unfortunately the message.id changes after edith.
And so, to summarize, what ways are there to find out message.text and message.buttons on the edited message?