reduce useless code da.
This commit is contained in:
1 parent
b958bddcfb
commit
bbad4ff2c3
2 files changed
+79
-80
No files matched your search
+1
-1
@@ -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."
|
||||
|
||||
@@ -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"
|
||||
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, "гостевой режим не работает с опросами. либо добавь меня " \
|
||||
"в группу, либо напиши мне в личку чтобы я выдал тебе опрос. ✅"
|
||||
)
|
||||
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:
|
||||
print(f"{RED} -- err poll {e} {RESET}")
|
||||
return
|
||||
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 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
|
||||
|
||||
Reference in new issue
Block a user