-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (71 loc) · 3.27 KB
/
main.py
File metadata and controls
81 lines (71 loc) · 3.27 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import telebot
import creds
from telebot import types
import pickle
bot = telebot.TeleBot(creds.key)
users=[]
try:
with open('data.pickle', "rb") as f:
users = pickle.load(f)
except:
pass
print(len(users))
@bot.message_handler(commands=['start','help','register','i'])
def send_message(message):
markup = types.InlineKeyboardMarkup()
itembtndone = types.InlineKeyboardButton('Написать', url='telegram.me/Notification_handler_bot')
markup.add(itembtndone)
if message.text =='/help':
bot.reply_to(message,'Для того чтобы начать пользоваться ботом:\n'
'1)Напишите в чат команду /register\n'
'2)Перейдите по ссылке в диалог с ботом и нажмите "Start"\n'
'Для создания объявления введите /i а затем текст объявления\n'
'ВАЖНО: чтобы бот смог вам написать, ЗАПУСТИТЕ ЕГО (2 пункт)')
if message.text =='/register':
chat_id = message.chat.id
user_id = message.from_user.id
usr = [user_id,chat_id]
if usr in users:
bot.reply_to(message, 'Вы уже зарегистрированы')
else:
users.append(usr)
bot.reply_to(message, 'Успешная регистрация!')
bot.send_message(usr[1],'Обязательно напишите боту чтобы он смог отправить вам сообщение',reply_markup=markup)
with open('data.pickle', "wb") as f:
pickle.dump(users, f)
for usr in users:
print(usr)
msg = str(message.text)
if msg.startswith('/i'):
sender_id = message.from_user.id
inlist = False
for user in users:
if user[0] == sender_id:
inlist = True
if inlist:
markup = types.InlineKeyboardMarkup()
chat_id = message.chat.id
admin_id = message.from_user.id
message_id = message.message_id
itembtndone = types.InlineKeyboardButton('Выполнено', callback_data=f'return-{admin_id}')
markup.add(itembtndone)
for user in users:
user.append(admin_id)
if user[1] ==chat_id:
try:
bot.forward_message(user[0],user[1],message_id)
bot.send_message(user[0],'Нажмите после выполнения',reply_markup=markup)
except:
pass
else:
bot.reply_to(message,'Вы не зарегистрированы. Используйте команду /register')
@bot.callback_query_handler(func=lambda call: True)
def iq_callback(query):
data = query.data
if data.startswith('return-'):
chat_id = int(data[7:])
bot.edit_message_reply_markup(query.from_user.id,query.message.id)
print(query)
bot.send_message(chat_id,f'{query.from_user.first_name} Выполнил задание')
bot.send_message(query.from_user.id,"Ваш ответ принят")
bot.polling()