-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
70 lines (52 loc) · 2.05 KB
/
bot.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
66
67
68
69
70
import telebot
import process
import os
from PIL import Image
token = ''
bot = telebot.TeleBot(token)
def dell_all():
os.remove('frame_done.png')
os.remove('1_done.png')
os.remove('2_done.png')
os.remove('3_done.png')
os.remove('1.png')
os.remove('2.png')
os.remove('3.png')
@bot.message_handler(commands=['start'])
def start_message(message):
if message.text == "/start":
bot.send_message(message.chat.id, 'Send me some document(photo), but first send me some msg(text)')
@bot.message_handler(content_types=['text'])
def do_text(message):
global input_str
input_str = message.text
bot.send_chat_action(message.chat.id, 'typing')
text = message.text
array = process.parse_string(text)
main_text = process.hlwn(array)
text = main_text + process.find_hashtags(main_text)
bot.send_message(message.chat.id, text)
@bot.message_handler(content_types=['document'])
def do_photo(message):
bot.send_chat_action(message.chat.id, 'typing')
try:
file_id_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_id_info.file_path)
with open('frame.png', 'wb') as new_file:
bot.send_chat_action(message.chat.id, 'typing')
new_file.write(downloaded_file)
size = process.get_img_size('frame.png')
process.cut_png(size)
process.do_image_png(input_str=input_str, switcher='hlwn')
bot.send_chat_action(message.chat.id, 'typing')
bot.send_photo(message.chat.id, open('frame_done.png', 'rb'))
bot.send_chat_action(message.chat.id, 'typing')
bot.send_photo(message.chat.id, open('1_done.png', 'rb'))
bot.send_chat_action(message.chat.id, 'typing')
bot.send_photo(message.chat.id, open('2_done.png', 'rb'))
bot.send_chat_action(message.chat.id, 'typing')
bot.send_photo(message.chat.id, open('3_done.png', 'rb'))
dell_all()
except Exception as ex:
bot.send_message(message.chat.id, "[!] error - {}".format(str(ex)))
bot.polling()