-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculamebot.py
36 lines (31 loc) · 1.28 KB
/
calculamebot.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
import telebot
bot = telebot.TeleBot("599557504:AAE4DprZ0HUQJoBV7p7_VRvpS6Hu4WecIoY")
@bot.message_handler(commands=["start"])
def send_welcome(message):
print(message)
chatid = message.chat.id
nombreUsuario = message.chat.first_name
saludo = "Hola {nombre}, Bienvenidos al Bot de Calculos "
bot.send_message(chatid, saludo.format(nombre=nombreUsuario))
@bot.message_handler(commands=["help"])
def send_welcome(message):
print(message)
chatid = message.chat.id
nombreUsuario = message.chat.first_name
saludo = "Hola {nombre}, Para hacer algun tipo de operacion escribeme un mensaje con tu operación Ejemplo 2+2"
bot.send_message(chatid, saludo.format(nombre=nombreUsuario))
@bot.message_handler(func=lambda message: True)
def echo_all(message):
chatid = message.chat.id
calculo = message.text
try:
resultado = eval(calculo)
respeusta = "El resultado es {calc}"
bot.send_message(chatid, respeusta.format(calc=resultado))
#bot.send_message(chatid, eval(calculo))
except ZeroDivisionError:
bot.send_message(chatid, "No se puede realizar la operación por error de division entre 0")
except NameError:
bot.send_message(chatid, "Se ingresaron Datos no numericos, No Se puede Relizar ningun tipo de operación")
print("el bot corre")
bot.polling()