Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. Конфиг группы:
  2. {"admin": "462116938", "cmdrunning": "", "cmdstate": -1, "cmddata": {}, "minigamedata": {}, "cmdinfo": {}, "users": {"462116938": ""}}
  3.  
  4. Конфиг юзера:
  5. {"cmdrunning": "", "cmdstate": -1, "cmddata": {}, "cmdinfo": {}, "dialogues": ["-278290295"], "current": "-278290295"}
  6.  
  7. Тестовая команда с мультиинпутом:
  8. import command_system, json
  9.  
  10. def test(data):
  11.     path = r'mysite/data/'+data['id']+r'/Config.json'
  12.     with open(path) as f:
  13.         config = json.load(f)
  14.     if config['cmdstate'] == -1:
  15.         message = 'Ввод0'
  16.         config['cmdrunning'] = '/test'
  17.         config['cmdstate'] = 0
  18.         config['cmddata']['text'] = ''
  19.         if len(data['cmd']) > 0:
  20.             try:
  21.                 config['cmdinfo']['times'] = int(data['cmd'][0])
  22.                 if (config['cmdinfo']['times'] > 10) or (config['cmdinfo']['times'] < 1):
  23.                     return 'Ошибка!'
  24.             except:
  25.                 return 'Ошибка!'
  26.         else:
  27.             config['cmdinfo']['times'] = 1
  28.     else:
  29.         message = 'Ввод'+str(config['cmdstate']+1)
  30.         text = ' '.join(data['cmd'])
  31.         if config['cmdstate'] != config['cmdinfo']['times']-1:
  32.             text += '\n'
  33.         config['cmddata']['text'] += text
  34.         if config['cmdstate'] == config['cmdinfo']['times']-1:
  35.             message = config['cmddata']['text']
  36.             config['cmdrunning'] = ''
  37.             config['cmdstate'] = -1
  38.             config['cmddata'] = {}
  39.             config['cmdinfo'] = {}
  40.         else:
  41.             config['cmdstate'] += 1
  42.     with open(path,'w') as f:
  43.         json.dump(config,f)
  44.     return message
  45.  
  46. ptest_command = command_system.PrivateCommand()
  47.  
  48. ptest_command.keys = ['test']
  49. ptest_command.description = 'test'
  50. ptest_command.process = test
  51.  
  52. test_command = command_system.Command()
  53.  
  54. test_command.keys = ['test']
  55. test_command.description = 'test'
  56. test_command.process = test
  57.  
  58. Пример взаимодействия с групповым чатом из лички (Нерабочий, но принцип такой):
  59. import command_system, os, json
  60.  
  61. def char(data):
  62.     if len(data['cmd']) > 1:
  63.         path = r'mysite/data/'+data['cmd'][0]
  64.         if os.path.exists(path):
  65.             with open(path+r'/Config.json','r') as f:
  66.                 config = json.load(f)
  67.             if data['id'] in config['users']:
  68.                 config['users']['id'] = data['cmd'][1]
  69.                 with open(path+r'/Config.json','r') as f:
  70.                     json.dump(config,f)
  71.                 message = 'Готово!'
  72.             else:
  73.                 message = 'Ошибка доступа'
  74.         else:
  75.             message = 'Диалога не существует.'
  76.     else:
  77.         message = 'Ошибка!'
  78.     return message
  79.  
  80. char_command = command_system.PrivateCommand()
  81.  
  82. char_command.keys = ['char']
  83. char_command.description = 'char'
  84. char_command.process = char
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement