def setup(): if db_gen.installed: return redirect('/') tokens = format_tokens( [request.form.get('access_token'), request.form.get('me_token')]) user_id = check_tokens(tokens)[0] if type(user_id) != int: return user_id db_gen.set_user(user_id) db = DB() db.access_token = tokens[0] db.me_token = tokens[1] db.secret = gen_secret() db_gen.host = "https://" + request.host db_gen.installed = True db.trusted_users.append(db.duty_id) db.save() db_gen.save() VkApi(db.access_token).msg_op( 1, -174105461, f'+api {db.secret} https://{request.host}/callback') return redirect('/login')
def api(method: str): login_check(request) db = DB() if method == "edit_current_user": tokens = format_tokens([ request.form.get('access_token', ''), request.form.get('me_token', '') ]) if tokens[0]: db.access_token = tokens[0] if tokens[1]: db.me_token = tokens[1] db.save() if method == 'connect_to_iris': try: VkApi(db.access_token, raise_excepts=True)( 'messages.send', peer_id=-174105461, message=f'+api {db.secret} https://{request.host}/callback', random_id=0) except VkApiResponseException as e: return int_error(f'Ошибка VK #{e.error_code}: {e.error_msg}') if method == "edit_responses": for key in db.responses.keys(): response = request.form.get(key) if response: db.responses[key] = response db.save() return redirect('/admin#Responses') if method == "edit_dyntemplates": name = request.form['temp_name'] length = int(request.form['length']) i = 0 frames = [] while True: if i >= length: break frame = request.form.get(f'frame{i}') if frame: frames.append(frame) elif i < length: frames.append('Пустой кадр') else: break i += 1 temp = { 'name': request.form['new_name'], 'frames': frames, 'speed': float(request.form['speed']) } for i in range(len(db.anims)): if db.anims[i]['name'] == name: db.anims[i].update(temp) break db.save() return redirect('/admin#DynTemplates') if method == 'add_dyntemplate': db.anims.append({ 'name': 'анимка', 'frames': ['Отсутствует'], 'speed': 1.0 }) db.save() return redirect('/admin#DynTemplates') if method == 'delete_anim': name = request.form['name'] for i in range(len(db.anims)): if db.anims[i]['name'] == name: del (db.anims[i]) db.save() return redirect('/admin#DynTemplates') if method == 'dc_auth': if request.form.get('permit') == 'on': db_gen.dc_auth = True else: db_gen.dc_auth = False db_gen.save() return redirect('/')
def api(method: str): if method == "setup_cb": #-------------------------------------------------------------- if db_gen.installed: return redirect('/') tokens = format_tokens( [request.form.get('access_token'), request.form.get('me_token')]) user_id = check_tokens(tokens)[0] if type(user_id) != int: return user_id db_gen.set_user(user_id) db = DB(user_id) db.access_token = tokens[0] db.me_token = tokens[1] db.secret = gen_secret() # db_gen.vk_app_id = int(request.form.get('vk_app_id')) # db_gen.vk_app_secret = request.form.get('vk_app_secret') db_gen.host = "http://" + request.host db_gen.installed = True db.trusted_users.append(db.duty_id) db.save() db_gen.save() return redirect('/login?next=/admin') db = DB(auth['user']) login = login_check(request, db, db_gen) if login: return login if method == "edit_current_user": #-------------------------------------------------------------- tokens = format_tokens([ request.form.get('access_token', ''), request.form.get('me_token', '') ]) if tokens[0]: db.access_token = tokens[0] if tokens[1]: db.me_token = tokens[1] db.save() return redirect('/admin') if method == 'connect_to_iris': try: VkApi(db.access_token, raise_excepts=True)( 'messages.send', random_id=0, message=f'+api {db.secret} {db.gen.host}/callback', peer_id=-174105461) except VkApiResponseException as e: return int_error(f'Ошибка VK #{e.error_code}: {e.error_msg}') return redirect('/') if method == "edit_responses": #-------------------------------------------------------------- for key in db.responses.keys(): response = request.form.get(key) if response: db.responses[key] = response db.save() return redirect('/admin#Responses') if method == "edit_dyntemplates": name = request.form['temp_name'] length = int(request.form['length']) i = 0 frames = [] while True: if i >= length: break frame = request.form.get(f'frame{i}') if frame: frames.append(frame) elif i < length: frames.append('Пустой кадр') else: break i += 1 temp = { 'name': request.form['new_name'], 'frames': frames, 'speed': float(request.form['speed']) } for i in range(len(db.anims)): if db.anims[i]['name'] == name: db.anims[i].update(temp) break db.save() return redirect('/admin#DynTemplates') if method == 'add_dyntemplate': db.anims.append({ 'name': 'анимка', 'frames': ['Отсутствует'], 'speed': 1.0 }) db.save() return redirect('/admin#DynTemplates') if method == 'delete_anim': name = request.form['name'] for i in range(len(db.anims)): if db.anims[i]['name'] == name: del (db.anims[i]) db.save() return redirect('/admin#DynTemplates') if method == 'dc_auth': if request.form.get('permit') == 'on': db_gen.dc_auth = True else: db_gen.dc_auth = False db_gen.save() return redirect('/admin') return int_error('Тебя здесь быть не должно')