black: Reformat skipping string normalization.

This commit is contained in:
PIG208 2021-05-28 17:03:46 +08:00 committed by Tim Abbott
parent 5580c68ae5
commit fba21bb00d
178 changed files with 6562 additions and 4469 deletions

View file

@ -4,11 +4,13 @@ config = {
"api_key": "key1",
"site": "https://realm1.zulipchat.com",
"stream": "bridges",
"subject": "<- realm2"},
"subject": "<- realm2",
},
"bot_2": {
"email": "tunnel-bot@realm2.zulipchat.com",
"api_key": "key2",
"site": "https://realm2.zulipchat.com",
"stream": "bridges",
"subject": "<- realm1"}
"subject": "<- realm1",
},
}

View file

@ -11,9 +11,9 @@ import interrealm_bridge_config
import zulip
def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
to_bot: Dict[str, Any], stream_wide: bool
) -> Callable[[Dict[str, Any]], None]:
def create_pipe_event(
to_client: zulip.Client, from_bot: Dict[str, Any], to_bot: Dict[str, Any], stream_wide: bool
) -> Callable[[Dict[str, Any]], None]:
def _pipe_message(msg: Dict[str, Any]) -> None:
isa_stream = msg["type"] == "stream"
not_from_bot = msg["sender_email"] not in (from_bot["email"], to_bot["email"])
@ -32,8 +32,9 @@ def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
if "/user_uploads/" in msg["content"]:
# Fix the upload URL of the image to be the source of where it
# comes from
msg["content"] = msg["content"].replace("/user_uploads/",
from_bot["site"] + "/user_uploads/")
msg["content"] = msg["content"].replace(
"/user_uploads/", from_bot["site"] + "/user_uploads/"
)
if msg["content"].startswith(("```", "- ", "* ", "> ", "1. ")):
# If a message starts with special prefixes, make sure to prepend a newline for
# formatting purpose
@ -45,7 +46,7 @@ def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
"content": "**{}**: {}".format(msg["sender_full_name"], msg["content"]),
"has_attachment": msg.get("has_attachment", False),
"has_image": msg.get("has_image", False),
"has_link": msg.get("has_link", False)
"has_link": msg.get("has_link", False),
}
print(msg_data)
print(to_client.send_message(msg_data))
@ -55,8 +56,10 @@ def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any],
if event["type"] == "message":
msg = event["message"]
_pipe_message(msg)
return _pipe_event
if __name__ == "__main__":
usage = """run-interrealm-bridge [--stream]
@ -71,20 +74,15 @@ if __name__ == "__main__":
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
parser = argparse.ArgumentParser(usage=usage)
parser.add_argument('--stream',
action='store_true',
help="",
default=False)
parser.add_argument('--stream', action='store_true', help="", default=False)
args = parser.parse_args()
options = interrealm_bridge_config.config
bot1 = options["bot_1"]
bot2 = options["bot_2"]
client1 = zulip.Client(email=bot1["email"], api_key=bot1["api_key"],
site=bot1["site"])
client2 = zulip.Client(email=bot2["email"], api_key=bot2["api_key"],
site=bot2["site"])
client1 = zulip.Client(email=bot1["email"], api_key=bot1["api_key"], site=bot1["site"])
client2 = zulip.Client(email=bot2["email"], api_key=bot2["api_key"], site=bot2["site"])
# A bidirectional tunnel
pipe_event1 = create_pipe_event(client2, bot1, bot2, args.stream)
p1 = mp.Process(target=client1.call_on_each_event, args=(pipe_event1, ["message"]))