aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorhuker667 <huker@tuta.io>2026-07-09 16:07:31 +0300
committerhuker667 <huker@tuta.io>2026-07-09 16:07:31 +0300
commitee5a6bdcc379527c537e23b689816555832fda5c (patch)
treee6c0d99573a744ea750a821ad7b5cb16ccc242d9 /main.py
parentf6109bb91a0dd4bd2558c087752a381d6ffdb4a3 (diff)
downloaduzbekgpt-ee5a6bdcc379527c537e23b689816555832fda5c.tar.gz
uzbekgpt-ee5a6bdcc379527c537e23b689816555832fda5c.tar.bz2
uzbekgpt-ee5a6bdcc379527c537e23b689816555832fda5c.zip
add poll answer support
Diffstat (limited to 'main.py')
-rw-r--r--main.py64
1 files changed, 63 insertions, 1 deletions
diff --git a/main.py b/main.py
index c9d1cfa..14c1ba2 100644
--- a/main.py
+++ b/main.py
@@ -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: