Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import keyword
- class UpdateObject:
- def __init__(self, dict):
- vars(self).update(dict)
- for i in vars(self).keys():
- if keyword.iskeyword(i):
- upd_i = 'upd_' + i
- vars(self)[upd_i] = vars(self).pop(i)
- class Bot:
- def __init__(self, update, uid):
- upd_obj = json.loads(update, object_hook= UpdateObject)
- self.process_update(upd_obj)
- def process_update(self, update):
- if hasattr(update, 'message'):
- message = Message(update.message)
- if hasattr(update.message, 'chat'):
- chat = Chat(update.message.chat)
- if hasattr(update.message, 'upd_from'):
- user = User(update.message.upd_from)
- class Message:
- def __init__ (self, message):
- self = message
- print(vars(self))
- class Chat:
- def __init__ (self, chat):
- self = chat
- print(vars(self))
- class User:
- def __init__ (self, user):
- self = user
- print(vars(user))
- 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"}}'
- b = Bot(data, 112233)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement