-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_telegram.py
65 lines (50 loc) · 1.63 KB
/
main_telegram.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
"""
This module contains functions that work
directly with a telegram bot
"""
import telebot
from main_logic import check_for_mistake, check_conjunctions, correct_msg
from together_hyphen import main_check
from conf import tok
bot = telebot.TeleBot(tok)
@bot.message_handler(commands=['start'])
def handle_command(message):
"""
Initial message
"""
bot.reply_to(message, "Привіт! Я бот - українізатор!")
@bot.message_handler(func=lambda message: True)
def handle_all_message(message):
"""
Send messages to the bot
"""
special_word(message, message.text)
mess = message.text
correct = check_for_mistake(mess)
correctes_sentence = correct_msg(mess)
errors = check_conjunctions(correctes_sentence)
hyphen = main_check(correctes_sentence)
if correct:
for i in correct:
bot.reply_to(message, i)
if errors:
for i in errors:
bot.reply_to(message, i)
if hyphen:
for i in hyphen:
bot.reply_to(message, i)
def special_word(message, text):
"""
Special cases
"""
if "українізатор" in text:
bot.reply_to(message, "Це я!")
if "україна" in text:
bot.reply_to(message, "Україна - лише з великої.")
if ("Тернопіль" in text) or ("тернопіль" in text):
bot.reply_to(message, "Файне місто")
if "сумно" in text:
bot.reply_to(message, "не сумуй!")
if ("важко" in text) or ("тяжко" in text):
bot.reply_to(message, "нічого, буде ще важче.")
bot.polling()