async def find_by_id(message: types.Message, state: FSMContext): _id = re.match("^/?[i|I][d|D]\s*:?\s*([0-9a-z]{24})", message.text).group(1) res = botutils.get_from_wiki(id=_id, ret_fields=["name"])["_id"] if res: async with state.proxy() as idp: idp["_id"] = res["_id"] await EditProcess._id.set() await message.answer(f"Found : {res['name']}") await message.answer("Are you sure you want to edit this one?", reply_markup=botutils.get_replymarkup_yesno())
async def finish_adding_media(message: types.Message, state: FSMContext): async with state.proxy() as data: _id = data["_id"] new_attachments = data.get("new_field_media", []) old_field = data["old_field"] access_token = data.get("access_token", "") res = botutils.update_in_wiki(_id, {old_field : new_attachments}, access_token) await message.answer(f"Send to API {len(new_attachments)} items.", reply_markup=botutils.get_replymarkup_yesno()) if res == 1: await message.answer(f"You have succesfully updated field '{old_field}'.") else: await message.answer(f"Something went wrong, the field was not updated. Try /login command.") await message.answer(f"Do you want to change another one?") await EditProcess._id.set()
async def process_name(message: types.Message, state: FSMContext): async with state.proxy() as data: matches = re.match("(.*) \((.+)\)", message.text) if matches is None: return name, _id = matches.groups() for word_id, word_name in data['names'].items(): if word_name == name and str(word_id)[-5:] == _id: data["_id"] = word_id data["word_info"] = botutils.get_from_wiki(id=word_id)["_id"] word_info = data["word_info"] break await EditProcess._id.set() await message.answer(botutils.format_page_info(word_info)) await message.answer("Are you sure you want to edit this one?", reply_markup=botutils.get_replymarkup_yesno())
async def process_name(message: types.Message, state: FSMContext): async with state.proxy() as data: data["_id"] = data['names'][message.text] await EditProcess._id.set() await message.answer("Are you sure want to edit this one?", reply_markup=botutils.get_replymarkup_yesno())
async def get_new_field_value(message: types.Message, state: FSMContext): global ARRAY_FIELDS async with state.proxy() as data: _id = data["_id"] old_field = data["old_field"] access_token = data.get("access_token", "") if old_field in ARRAY_FIELDS: new_val = [x.strip() for x in message.text.strip().lstrip("[").rstrip("]").split(",")] else: new_val = message.text res = botutils.update_in_wiki(_id, {old_field : new_val}, access_token) if res == 1: await message.answer(f"You have succesfully updated the field '{old_field}'.", reply_markup=botutils.get_replymarkup_yesno()) else: await message.answer(f"Something went wrong, the field is not updated. Try /login command.", reply_markup=botutils.get_replymarkup_yesno()) await message.answer(f"Do you want to change another one?") await EditProcess._id.set()
async def edit_or_delete(message: types.Message, state: FSMContext): async with state.proxy() as data: data["word_info"] = botutils.get_from_wiki(id=data["_id"])["_id"] word_info = data["word_info"] if message.text == 'Edit': logging.debug(f"User {message.from_user.id} is edititng {data['_id']}") del word_info["_id"] await EditProcess.old_field.set() await message.answer("What field do you want to change? (or create a new one)", reply_markup=botutils.get_replymarkup_fields(word_info)) elif message.text == 'Delete': await EditProcess.delete_confirmation.set() await message.answer('Are you sure you want to delete this object?', reply_markup=botutils.get_replymarkup_yesno())
async def confirm_new_obj(message: types.Message, state: FSMContext): await CreateProcess.confiramtion.set() await message.answer("Are you sure you want to create this one?", reply_markup=botutils.get_replymarkup_yesno())