Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TELEGRAM BOT
- import telepot
- import urllib3
- import certifi
- import json
- def on_chat_message(msg):
- content_type, chat_type, chat_id = telepot.glance(msg)
- if content_type == 'text':
- name = msg["from"]["first_name"]
- txt = msg['text']
- bot.sendMessage(chat_id, 'ciao %s, sono un bot molto stupido!'%name)
- bot.sendMessage(chat_id, 'ho ricevuto questo: %s'%txt)
- bot.sendMessage(chat_id, check(txt))
- def check(line):
- url = 'https://api.mojang.com/users/profiles/minecraft/'
- http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
- try:
- r = http.request('GET', url + line)
- # print str(url + line)
- except urllib3.exceptions.SSLError as e:
- print (str(e))
- try:
- r_data = json.loads(r.data.decode('utf-8'))
- # print r_data
- except Exception as e:
- # print(str(e))
- r_data = ""
- if r_data:
- return ' è premium'
- None
- else:
- return 'non è premium'
- TOKEN = '381146052:AAGKiOdRntjXw-ac0Hbe3-BGQY30JzA_MUQ'
- bot = telepot.Bot(TOKEN)
- bot.message_loop(on_chat_message)
- print ('Listening ...')
- import time
- while 1:
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement