-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbot.py
executable file
·53 lines (38 loc) · 1.37 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
#!/usr/bin/env python3
"""
d
"""
from threading import current_thread
from LaTeX2IMG.LaTeX2IMG import latex2img
import telebot
from telebot import logging
from telebot import types
TOKEN = ''
with open("token.txt", "r") as file:
TOKEN = file.readline().strip()
bot = telebot.TeleBot(TOKEN)
def send_equation(chat_id, text):
bot.send_chat_action(chat_id, 'upload_document')
filename = 'resultado' + current_thread().name
latex2img(text, filename, 'webp')
with open(filename + '.webp', 'rb') as equation:
bot.send_sticker(chat_id, equation)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "You can convert LaTeX expression using\n\n/latex expression")
@bot.message_handler(commands=['latex'])
def send_expression(message):
chat_id = message.chat.id
text = message.text[7:]
if text and text != "LaTeX2IMGbot":
send_equation(chat_id, text)
else:
new_msg = bot.reply_to(message, "Please send your expression with \"/latex expression\"")
logger = telebot.logger
formatter = logging.Formatter('[%(asctime)s] %(thread)d {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
'%m-%d %H:%M:%S')
ch = logging.FileHandler("log.txt")
logger.addHandler(ch)
logger.setLevel(logging.INFO) # or use logging.INFO
ch.setFormatter(formatter)
bot.polling()