-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistorybot.py
38 lines (38 loc) · 1.74 KB
/
historybot.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
import telebot
from telebot import types
import os
bot = telebot.TeleBot('')#Сюда токен
@bot.message_handler(commands=['start'])
def start(message):
openf = open("history.txt", 'a', encoding='utf-8')
markup = types.InlineKeyboardMarkup(row_width=2)
item = types.InlineKeyboardButton('📓Лента историй📓', callback_data='history_list')
item2 = types.InlineKeyboardButton('➕Добавить историю➕', callback_data='add_history')
markup.add(item, item2)
bot.send_message(message.chat.id, f'Привет {message.from_user.first_name}!', reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def markup(call):
if call.message:
if call.data == 'add_history':
bot.send_message(call.message.chat.id, 'Добавьте имя вашей истории и историю')
if call.data == 'history_list':
with open('history.txt', 'r', encoding='utf-8') as list:
len = os.path.getsize("history.txt")
if len > 0:
readl = list.read()
bot.send_message(call.message.chat.id, readl)
else:
bot.send_message(call.message.chat.id, '🥺Увы, но историй пока нет🥺')
@bot.message_handler(content_types=['text'])
def mess(message):
if message.text == message.text:
with open('history.txt', 'a', encoding='utf-8') as list2:
list2.write('\n' + message.text + '\n' + '________________' + '\n')
bot.send_message(message.chat.id, '✅История успешно добавлена✅')
start(message)
while True:
try:
bot.polling(none_stop=True)
except Exception as _ex:
print(_ex)
sleep(15)