def extract_alphanum_str(text: str, unique_words = False, min_length = 0, replace_yo = False, remove_duplicated_spaces = True, return_mode = 'text'):
S = text.replace('\n', ' ').replace(r'\n', ' ').replace('\xa0', ' ')
S = S.upper()
if replace_yo:
S = replace_yo_and_convert_to_uppercase(S)
temp = ''
for letter in S:
item = str(letter)
if item.isalnum():
temp += item
else:
temp += ' '
if remove_duplicated_spaces:
temp_list = remove_duplicated(temp, ' ').split()
else:
temp_list = temp.split()
List = []
for item in temp_list:
if len(str(item)) < min_length:
continue
if not unique_words:
List.append(item)
continue
if str(item) not in List:
List.append(item)
if return_mode == 'text':
return ' '.join(List) # возвращаем строку
else:
return List # возвращаем список
def remove_duplicated(text, dup:str, strip = True):
temp = text
while temp.find(dup + dup) != -1:
temp = temp.replace(dup + dup, dup)
if strip:
return temp.strip(dup)
return temp
def replace_yo_and_convert_to_uppercase(text):
# все слова приводятся к UPPERCASE. Все Ё заменяются на Е
cyr_Yo = 'Ё' # Ё из русского набора
non_cyr_Yo = 'Ë' # 'Ë' - из латинского набора
return text.upper().replace(cyr_Yo, 'Е').replace(non_cyr_Yo, 'Е')
InlineKeyboardButton
This object represents one button of an inline keyboard. Exactly one of the optional fields must be used to specify type of the button.
@bot.message_handler(content_types = ['new_chat_member', 'new_chat_members', 'new_chat_participant']) #??? Хэндлер вступления нового члена в группу
def get_user_text(message: types.Message):
try:
if '@' + str(message.chat.username) == const.main_chat_name:
greet_new_member(message)
if ('@' + str(message.chat.username)) in [const.patient_chat, const.my_personal_group_name]:
greet_new_patient(message)
except Exception as e:
text = f'Ошибка при приветствии нового пользователя: {e}'
print(cur_time(), text)
notify_support(message, text, must_forward_message = True, for_developer_only = True)
def greet_new_member(message: types.Message):
Author = get_author(chat_id = message.chat.id, user_id = message.new_chat_members[0].id)
send_message(message.chat.id, f'{Author}приветствуем Вас в группе', disable_preview = True, markup = kb.greet_new_doc_keyboard(message.from_user.id), thread_id = const.main_thread_id)
def greet_new_patient(message: types.Message):
Author = get_author(chat_id = message.chat.id, user_id = message.new_chat_members[0].id)
send_message(message.chat.id, f'{Author}приветствуем Вас в группе', disable_preview = True, markup = kb.greet_new_patient_keyboard(message.from_user.id))
А в чем причина такого подхода к решению проблемы?