def find_thx(s, text):
"""Slack?????????????thx???????
:param s: sqlalchemy.orm.session.Session
:param str text: ???????????
:return dict word_map_names_dict:
???thx??????????Slack????????
:return list hint_names: Slack??????????????????
:return list not_matched: Slack???????????????????
"""
word_map_names_dict = {}
hint_names = []
not_matched = []
thx_matcher = re.compile('(?P<user_names>.+)[ \t\f\v]*\+\+[ \t\f\v]+(?P<word>.+)',
re.MULTILINE)
for thx in thx_matcher.finditer(text):
user_names = [x for x in thx.group('user_names').split(' ') if x]
for name in user_names:
if get_user_name(name.lstrip('<@').rstrip('>')):
slack_id = name.lstrip('<@').rstrip('>')
else:
slack_id = get_slack_id(s, name)
if slack_id:
word_map_names_dict.setdefault(
thx.group('word'), []
).append((slack_id, name))
else:
# ????????????
hint = get_close_matches(name, get_users_info().values())
if hint:
hint_names.append(hint[0])
# ?????????????????
else:
not_matched.append(name)
return word_map_names_dict, hint_names, not_matched
评论列表
文章目录