Slack importer: Map Slack channel mentions to Zulip stream mentions.

This commit is contained in:
rht
2018-04-06 23:00:05 +01:00
committed by Tim Abbott
parent 035c440ff3
commit 630adb406b
2 changed files with 16 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ from typing import Any, Dict, Tuple, List
# stubs
ZerverFieldsT = Dict[str, Any]
AddedUsersT = Dict[str, int]
AddedChannelsT = Dict[str, Tuple[str, int]]
# Slack link can be in the format <http://www.foo.com|www.foo.com> and <http://foo.com/>
LINK_REGEX = r"""
@@ -66,6 +67,7 @@ def get_user_full_name(user: ZerverFieldsT) -> str:
# Markdown mapping
def convert_to_zulip_markdown(text: str, users: List[ZerverFieldsT],
added_channels: AddedChannelsT,
added_users: AddedUsersT) -> Tuple[str, List[int], bool]:
mentioned_users_id = []
text = convert_markdown_syntax(text, SLACK_BOLD_REGEX, "**")
@@ -80,6 +82,11 @@ def convert_to_zulip_markdown(text: str, users: List[ZerverFieldsT],
text = text.replace('<!channel>', '@**all**')
text = text.replace('<!here>', '@**all**')
# Map Slack channel mention: '<#C5Z73A7RA|general>' to '#**general**'
for cname, ids in added_channels.items():
cid = ids[0]
text = text.replace('<#%s|%s>' % (cid, cname), '#**' + cname + '**')
tokens = text.split(' ')
for iterator in range(len(tokens)):