Advertisement
Guest User

mybot[v0.1].py

a guest
Feb 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1.  
  2. # -*- coding: utf-8 -*-
  3.  
  4. import telepot, sys
  5. reload(sys)
  6. sys.setdefaultencoding('utf8')
  7.  
  8. bot = telepot.Bot('491145488:AAE17Hyw1Zk_9UFhTrkRqTiTF1L5ZHqcQoM')
  9.  
  10. def handle(msg):
  11. # Parametros do bot.
  12.     chat_id = msg['chat']['id']
  13.     texto = msg['text']
  14.     first_name = msg['from']['first_name']
  15.     if 'username' not in msg['from']:
  16.         user = 'None'
  17.     else:
  18.         user = '@' + msg['from']['username']
  19. # Mostrar as informações recebidas.
  20.     print ('Comando enviado:' + texto)
  21.     print ('Enviado por:' + user)
  22.     print ('ID:' + str(chat_id))
  23.     print (' ')
  24. # Comandos do bot.  
  25.     if texto == '/start':
  26.         bot.sendMessage(chat_id, '👋 Bem-vindo {}.'.format (first_name))
  27.     elif texto[0] == '~' and chat_id == 390562343:
  28.         bot.sendMessage(chat_id, '{}'.format(texto[1::]))  
  29.     else:
  30.         bot.sendMessage (chat_id, '❌ Comando invalido')
  31. # Loop de execução.
  32. print('Em execução...')
  33. bot.message_loop(handle)
  34. while 1:
  35.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement