Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import telepot
  2. from telepot.loop import MessageLoop
  3. import parser
  4. from math import *
  5. import random, datetime
  6.  
  7. falas = ('Booom Dia', 'É que sou muito sistemático...', 'Está fácil pra quem estudou.')
  8. falas_prov = ('Está fácil pra quem estudou.', 'O corno está ferrado!', 'Terá tudo o que dei.', 'Rá!')
  9.  
  10. bot = telepot.Bot('TOKEN') # Colocar aqui o token do bot do telegram, gerado no BotFather
  11.  
  12. def handle(msg):
  13. print(msg)
  14. content_type, chat_type, chat_id = telepot.glance(msg)
  15. if 'gelso' in msg['text'].lower() and '?' not in msg['text']:
  16. random.seed(datetime.datetime.now())
  17. bot.sendMessage(chat_id, falas[random.randint(0, 2)], reply_to_message_id=msg['message_id'])
  18. if msg['text'].lower().startswith('/conta'):
  19. resp = op_mat(' '.join(msg['text'].split(' ')[1::1]))
  20. bot.sendMessage(chat_id, resp, reply_to_message_id=msg['message_id'])
  21. if 'dormir' in msg['text'].lower() or 'sono' in msg['text'].lower():
  22. bot.sendMessage(chat_id, 'Quer um travesseiro e um suquinho?', reply_to_message_id=msg['message_id'])
  23. if '?' in msg['text'] and 'gelso' in msg['text'].lower():
  24. resp = ('sim', 'não')
  25. random.seed(datetime.datetime.now())
  26. bot.sendMessage(chat_id, resp[random.randint(0, 1)], reply_to_message_id=msg['message_id'])
  27. if 'gelso' in msg['text'].lower() and 'fala' in msg['text'] and len(msg['text'].split(' ')) >= 2 and 'prova' not in msg['text']:
  28. fala = ' '.join(msg['text'].split(' ')[2::])
  29. bot.sendMessage(chat_id, fala, reply_to_message_id=msg['message_id'])
  30.  
  31. if 'gelso' in msg['text'].lower() and 'prova' in msg['text']:
  32. random.seed(datetime.datetime.now())
  33. bot.sendMessage(chat_id, falas_prov[random.randint(0, 3)], reply_to_message_id=msg['message_id'])
  34.  
  35.  
  36.  
  37. def op_mat(op):
  38. try:
  39. code = parser.expr(op).compile()
  40. return str(eval(code))
  41. except (SyntaxError, TypeError, NameError):
  42. return 'O corno digitou algo errado.'
  43.  
  44.  
  45. MessageLoop(bot, handle).run_as_thread()
  46.  
  47. while 1:
  48. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement