add poll answer support

This commit is contained in:
huker667 committed 2026-07-09 16:07:31 +03:00
1 parent f6109bb91a
commit ee5a6bdcc3
4 files changed
+100 -4

No files matched your search

+63 -1
View File
@@ -33,7 +33,7 @@ from colors import *
from helpers import *
from commands import *
from dotenv import load_dotenv
from random import uniform
from random import uniform, shuffle
try:
from config import *
@@ -331,6 +331,68 @@ async def guest_middleware(handler, event, data):
last_command_time[user_id][1] = False
last_command_time[user_id][2] = []
if result.startswith("[") and ":" in result:
rl = result.split("\n")
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
allow_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"
allow_multiple_answers = False
elif poll_type == "multipoll":
poll_type = "regular"
allow_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,
correct_option_id=correct_option_id,
user_id=mid
)
except Exception as e:
if event.guest_message:
await g_answer(data, message, "гостевой режим не работает с опросами. либо добавь меня " \
"в группу, либо напиши мне в личку чтобы я выдал тебе опрос. ✅"
)
else:
print(f"{RED} -- err poll {e} {RESET}")
return
if result and event.guest_message:
await g_answer(data, message, "отправил опрос в личку, так как гостевой режим не работает с " \
"опросами✅✅"
)
return
try:
if event.guest_message: