SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #TELEGRAM BOT
  2.  
  3. import telepot
  4. import urllib3
  5. import certifi
  6. import json
  7.  
  8. def on_chat_message(msg):
  9.     content_type, chat_type, chat_id = telepot.glance(msg)
  10.     if content_type == 'text':
  11.         name = msg["from"]["first_name"]
  12.         txt = msg['text']
  13.         bot.sendMessage(chat_id, 'ciao %s, sono un bot molto stupido!'%name)
  14.         bot.sendMessage(chat_id, 'ho ricevuto questo: %s'%txt)
  15.         bot.sendMessage(chat_id, check(txt))
  16.  
  17.  
  18. def check(line):
  19.  
  20.     url = 'https://api.mojang.com/users/profiles/minecraft/'
  21.     http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
  22.     try:
  23.         r = http.request('GET', url + line)
  24.         # print str(url + line)
  25.     except urllib3.exceptions.SSLError as e:
  26.       print (str(e))
  27.  
  28.     try:
  29.         r_data = json.loads(r.data.decode('utf-8'))
  30.         # print r_data
  31.     except Exception as e:
  32.         # print(str(e))
  33.         r_data = ""
  34.  
  35.     if r_data:
  36.         return ' è premium'
  37.         None
  38.     else:
  39.         return 'non è premium'
  40.  
  41.  
  42.  
  43.  
  44. TOKEN = '381146052:AAGKiOdRntjXw-ac0Hbe3-BGQY30JzA_MUQ'
  45.  
  46. bot = telepot.Bot(TOKEN)
  47. bot.message_loop(on_chat_message)
  48.  
  49. print ('Listening ...')
  50.  
  51. import time
  52. while 1:
  53.     time.sleep(10)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top