-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpush_announcement.py
65 lines (52 loc) · 2.63 KB
/
push_announcement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
import os
import asyncio
from dotenv import load_dotenv, find_dotenv
from telebot.async_telebot import AsyncTeleBot
from dao import get_user_id_list, get_user_push_tags, get_notifications_user_id_list
from utils import UserStates, tag_id2text
from telebot import types
load_dotenv(find_dotenv())
BOT_TOKEN = os.environ.get('BOT_TOKEN')
bot = AsyncTeleBot(BOT_TOKEN)
logging.getLogger('asyncio').setLevel(logging.CRITICAL)
# Это пуш для тех, кто еще не выполнил настройку
async def send_message(chat_id):
await bot.set_state(chat_id, UserStates.default, chat_id)
tags_select_buttons = list()
user_tags = get_user_push_tags(chat_id)
if len(user_tags) == 0:
for tag_id in tag_id2text:
tags_select_buttons.append(types.InlineKeyboardButton(f"✅ {tag_id2text[tag_id]}",
callback_data=f"notifications_topic_{tag_id}"))
else:
for tag_id in tag_id2text:
if tag_id in user_tags:
tags_select_buttons.append(types.InlineKeyboardButton(f"✅ {tag_id2text[tag_id]}",
callback_data=f"notifications_topic_{tag_id}"))
else:
tags_select_buttons.append(types.InlineKeyboardButton(tag_id2text[tag_id],
callback_data=f"notifications_topic_{tag_id}"))
notifications_topic_save_button = types.InlineKeyboardButton("Далее >",
callback_data=f"start_save_notifications_topic")
notifications_inline_keyboard = types.InlineKeyboardMarkup().add(*tags_select_buttons, row_width=2)
notifications_inline_keyboard.add(notifications_topic_save_button)
pre_speech = "Мы обновились!\n" \
"И я заметил, что ты до сих пор не заходил в настройки."
try:
await bot.send_message(
chat_id,
f"{pre_speech}"
)
await bot.send_message(
chat_id,
"Выберите тематики, которые Вам интересны:",
reply_markup=notifications_inline_keyboard
)
except:
pass
user_id_list = list(map(lambda x: x[0], get_user_id_list()))
notifications_user_id_list = list(map(lambda x: x[0], get_notifications_user_id_list()))
users_without_settings = list(set(user_id_list) - set(notifications_user_id_list))
for user_id in users_without_settings:
asyncio.run(send_message(user_id))