Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Конфиг группы:
- {"admin": "462116938", "cmdrunning": "", "cmdstate": -1, "cmddata": {}, "minigamedata": {}, "cmdinfo": {}, "users": {"462116938": ""}}
- Конфиг юзера:
- {"cmdrunning": "", "cmdstate": -1, "cmddata": {}, "cmdinfo": {}, "dialogues": ["-278290295"], "current": "-278290295"}
- Тестовая команда с мультиинпутом:
- import command_system, json
- def test(data):
- path = r'mysite/data/'+data['id']+r'/Config.json'
- with open(path) as f:
- config = json.load(f)
- if config['cmdstate'] == -1:
- message = 'Ввод0'
- config['cmdrunning'] = '/test'
- config['cmdstate'] = 0
- config['cmddata']['text'] = ''
- if len(data['cmd']) > 0:
- try:
- config['cmdinfo']['times'] = int(data['cmd'][0])
- if (config['cmdinfo']['times'] > 10) or (config['cmdinfo']['times'] < 1):
- return 'Ошибка!'
- except:
- return 'Ошибка!'
- else:
- config['cmdinfo']['times'] = 1
- else:
- message = 'Ввод'+str(config['cmdstate']+1)
- text = ' '.join(data['cmd'])
- if config['cmdstate'] != config['cmdinfo']['times']-1:
- text += '\n'
- config['cmddata']['text'] += text
- if config['cmdstate'] == config['cmdinfo']['times']-1:
- message = config['cmddata']['text']
- config['cmdrunning'] = ''
- config['cmdstate'] = -1
- config['cmddata'] = {}
- config['cmdinfo'] = {}
- else:
- config['cmdstate'] += 1
- with open(path,'w') as f:
- json.dump(config,f)
- return message
- ptest_command = command_system.PrivateCommand()
- ptest_command.keys = ['test']
- ptest_command.description = 'test'
- ptest_command.process = test
- test_command = command_system.Command()
- test_command.keys = ['test']
- test_command.description = 'test'
- test_command.process = test
- Пример взаимодействия с групповым чатом из лички (Нерабочий, но принцип такой):
- import command_system, os, json
- def char(data):
- if len(data['cmd']) > 1:
- path = r'mysite/data/'+data['cmd'][0]
- if os.path.exists(path):
- with open(path+r'/Config.json','r') as f:
- config = json.load(f)
- if data['id'] in config['users']:
- config['users']['id'] = data['cmd'][1]
- with open(path+r'/Config.json','r') as f:
- json.dump(config,f)
- message = 'Готово!'
- else:
- message = 'Ошибка доступа'
- else:
- message = 'Диалога не существует.'
- else:
- message = 'Ошибка!'
- return message
- char_command = command_system.PrivateCommand()
- char_command.keys = ['char']
- char_command.description = 'char'
- char_command.process = char
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement