aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuker667 <huker@tuta.io>2026-07-16 12:51:07 +0300
committerhuker667 <huker@tuta.io>2026-07-16 12:51:07 +0300
commitbbad4ff2c370505d98722e59280dbd85bbe670ec (patch)
treed8b79918a39d022984d3865c7e973202f1cbb12d
parentb958bddcfb5cec9ff076522803e90181a96af7d0 (diff)
downloaduzbekgpt-bbad4ff2c370505d98722e59280dbd85bbe670ec.tar.gz
uzbekgpt-bbad4ff2c370505d98722e59280dbd85bbe670ec.tar.bz2
uzbekgpt-bbad4ff2c370505d98722e59280dbd85bbe670ec.zip
reduce useless code da.
-rw-r--r--helpers.py2
-rw-r--r--main.py153
2 files changed, 77 insertions, 78 deletions
diff --git a/helpers.py b/helpers.py
index f7525ea..454d49f 100644
--- a/helpers.py
+++ b/helpers.py
@@ -21,7 +21,7 @@ def is_blocked(user_id):
if time_diff < 3:
alo = "🚫 *файл не вошёл.* хватит так быстро слать свои сообщения.\n" \
f"подожди {round(3 - time_diff, 3)} секунд, брат😡😡"
- elif last_command_time[user_id][1] and time_diff < 10:
+ elif last_command_time[user_id][1] and time_diff < 5:
alo = "🚫 *файл не вошёл.* я ещё не сгенерировал прошлое сообщение.\n" \
f"подожди {round(10 - time_diff, 3)} секунд, чтобы я закрыл глаза " \
"на это da."
diff --git a/main.py b/main.py
index 3afe945..60bd542 100644
--- a/main.py
+++ b/main.py
@@ -152,6 +152,12 @@ async def guest_middleware(handler, event, data):
voice = message.voice
elif replied and replied.voice:
voice = replied.voice
+
+ location = None
+ if message.location:
+ location = message.location
+ elif replied and replied.voice:
+ location = replied.location
if voice:
if voice.duration > 60:
@@ -223,21 +229,12 @@ async def guest_middleware(handler, event, data):
except Exception as e:
print(f"{RED} -- {e}{RESET}")
return
-
- if replied and replied.location:
- loc = replied.location
- prompt += (
- f"<ответ на локацию>\n"
- f"{loc.latitude}, {loc.longitude}\n"
- f"</ответ на локацию>\n"
- )
- if message.location:
- loc = message.location
+ if location:
prompt += (
- f"<локация>\n"
- f"{loc.latitude}, {loc.longitude}\n"
- f"</локация>\n"
+ f"<геолокация>\n"
+ f"{location.latitude}, {location.longitude}\n"
+ f"</геолокация>\n"
)
if replied and replied.poll:
@@ -376,74 +373,76 @@ async def guest_middleware(handler, event, data):
last_command_time[user_id][1] = False
last_command_time[user_id][2] = []
- if ":" in result and ("poll" in result or "quiz" in result):
- pw = ["[poll]", "poll", "quiz"]
- rl = result.split("\n")
- for i, line in enumerate(rl):
- if any(line.startswith(w) for w in pw):
- rl = rl[i:]
- break
- poll_type = rl[0].split(":")[0].replace("[", "").replace("]", "")
- poll_name = rl[0].split(":")[1]
- if len(rl) > 1:
- options = rl[1].split(" =| ")
- else:
- options = ["варианты не указаны"]
- correct_option = options[0]
- correct_option_id = None
- is_anon = True
- allows_multiple_answers = False
-
- if event.guest_message:
- mid = user_id
- elif message.chat.type == "private":
- mid = user_id
- elif message.chat.type in ("group", "supergroup"):
- mid = message.chat.id
- else:
- return
-
- if poll_type == "quiz":
- shuffle(options)
- correct_option_id = options.index(correct_option)
- elif poll_type == "poll":
- poll_type = "regular"
+ try:
+ if ":" in result and ("poll" in result or "quiz" in result):
+ pw = ["[poll]", "poll", "quiz"]
+ rl = result.split("\n")
+ for i, line in enumerate(rl):
+ if any(line.startswith(w) for w in pw):
+ rl = rl[i:]
+ break
+ poll_type = rl[0].split(":")[0].replace("[", "").replace("]", "")
+ poll_name = rl[0].split(":")[1]
+ if len(rl) > 1:
+ options = rl[1].split(" =| ")
+ else:
+ options = ["варианты не указаны"]
+ correct_option = options[0]
+ correct_option_id = None
+ is_anon = True
allows_multiple_answers = False
- elif poll_type == "multipoll":
- poll_type = "regular"
- allows_multiple_answers = True
- else:
- poll_type = "regular"
-
-
-
- try:
- result = await answer_poll(
- data=data,
- message=message,
- question=poll_name,
- options=options,
- is_anonymous=is_anon,
- poll_type=poll_type,
- allows_multiple_answers=allows_multiple_answers,
- correct_option_id=correct_option_id,
- user_id=mid
- )
- except Exception as e:
+
if event.guest_message:
- await g_answer(message, "гостевой режим не работает с опросами. либо добавь меня " \
- "в группу, либо напиши мне в личку чтобы я выдал тебе опрос. ✅"
- )
+ mid = user_id
+ elif message.chat.type == "private":
+ mid = user_id
+ elif message.chat.type in ("group", "supergroup"):
+ mid = message.chat.id
else:
- print(f"{RED} -- err poll {e} {RESET}")
- return
+ return
- if result and event.guest_message:
- await g_answer(message, "отправил опрос в личку, так как гостевой режим не работает с " \
- "опросами✅✅"
- )
+ if poll_type == "quiz":
+ shuffle(options)
+ correct_option_id = options.index(correct_option)
+ elif poll_type == "poll":
+ poll_type = "regular"
+ allows_multiple_answers = False
+ elif poll_type == "multipoll":
+ poll_type = "regular"
+ allows_multiple_answers = True
+ else:
+ poll_type = "regular"
-
+
+
+ try:
+ result = await answer_poll(
+ data=data,
+ message=message,
+ question=poll_name,
+ options=options,
+ is_anonymous=is_anon,
+ poll_type=poll_type,
+ allows_multiple_answers=allows_multiple_answers,
+ correct_option_id=correct_option_id,
+ user_id=mid
+ )
+ except Exception as e:
+ if event.guest_message:
+ await g_answer(message, "гостевой режим не работает с опросами. либо добавь меня " \
+ "в группу, либо напиши мне в личку чтобы я выдал тебе опрос. ✅"
+ )
+ else:
+ print(f"{RED} -- err poll {e} {RESET}")
+ return
+
+ if result and event.guest_message:
+ await g_answer(message, "отправил опрос в личку, так как гостевой режим не работает с " \
+ "опросами✅✅"
+ )
+ except Exception as e:
+ print(f"{YELLOW} -- poll parsing - {e}{RESET}")
+ else:
return
kwargs = (
@@ -491,7 +490,7 @@ async def guest_middleware(handler, event, data):
else:
await message.reply(**kwargs)
except Exception as e:
- print(f"{RED} -- send guest - {e}{RESET}")
+ print(f"{RED} -- send msg - {e}{RESET}")
else:
print(f"{YELLOW} -- markdown - {e}{RESET}")
return