SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import telebot
  2. from random import randint
  3.  
  4. token = "915784377:AAHBa31K_FTfyqYzIGjeRzgT1onwNeackuc"
  5.  
  6. bot = telebot.TeleBot(token)
  7.  
  8. def get_json():
  9.     return bot.get_updates()
  10.  
  11. def get_data(upd):
  12.     return upd[-1]
  13.  
  14. def get_messageText(last_data):
  15.     return last_data.message.text
  16.  
  17. def get_dialog(last_data):
  18.     return last_data.message.chat.id
  19.  
  20. def get_name(last_data):
  21.     return last_data.message.first_name
  22.  
  23. def send_pic(dialog):
  24.     path = "pic/" + str(randint(1, 3)) + ".jpg"
  25.     img = open(path, 'rb')
  26.     bot.send_photo(dialog, img)
  27.  
  28. message_id = 0
  29.  
  30. while True:
  31.     upd = get_json()
  32.     data = get_data(upd)
  33.     text = get_messageText(data)
  34.     dialog = get_dialog(data)
  35.     message_id_last = data.update_id
  36.  
  37.     if message_id != message_id_last:
  38.         message_id = message_id_last
  39.         if text.lower() == "картинка":
  40.             send_pic(dialog)
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