Advertisement
shadsokoloff

Untitled

Aug 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import json
  2. import keyword
  3.  
  4. class UpdateObject:
  5.     def __init__(self, dict):
  6.         vars(self).update(dict)
  7.         for i in vars(self).keys():
  8.             if keyword.iskeyword(i):
  9.                 upd_i = 'upd_' + i
  10.                 vars(self)[upd_i] = vars(self).pop(i)
  11.  
  12.  
  13. class Bot:
  14.     def __init__(self, update, uid):
  15.         upd_obj = json.loads(update, object_hook= UpdateObject)
  16.         self.process_update(upd_obj)
  17.  
  18.     def process_update(self, update):
  19.         if hasattr(update, 'message'):
  20.             message = Message(update.message)
  21.         if hasattr(update.message, 'chat'):
  22.             chat = Chat(update.message.chat)
  23.         if hasattr(update.message, 'upd_from'):
  24.             user = User(update.message.upd_from)
  25.  
  26.  
  27. class Message:
  28.     def __init__ (self, message):
  29.         self = message
  30.         print(vars(self))
  31.  
  32.  
  33. class Chat:
  34.      def __init__ (self, chat):
  35.         self = chat
  36.         print(vars(self))
  37.  
  38.  
  39. class User:
  40.     def __init__ (self, user):
  41.         self = user
  42.         print(vars(user))
  43.        
  44.  
  45. data = b'{"update_id":68063223,\n"message":{"message_id":456,"from":{"id":1144234,"is_bot":false,"first_name":"SOKOLOV","username":"S0K0L0V","language_code":"ru"},"chat":{"id":-1001331469539,"title":"asker-bot-test-chat","username":"asker_bot_test","type":"supergroup"},"date":1566481244,"text":"fdfq"}}'
  46. b = Bot(data, 112233)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement