Skip to content

Commit 6212354

Browse files
committed
IRC bridge: Do not append "_zulip" to the specified nickname.
1 parent a5657e4 commit 6212354

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

zulip/integrations/bridge_with_irc/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Usage
44

55
```
6-
./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nick-prefix=<NICK> --stream=<STREAM> [optional args]
6+
./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nickname=<NICK> --stream=<STREAM> [optional args]
77
```
88

99
`--stream` is a Zulip stream.
@@ -14,12 +14,10 @@ IMPORTANT: Make sure the bot is subscribed to the relevant Zulip stream!!
1414

1515
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
1616

17-
IMPORTANT: Note that "_zulip" will be automatically appended to the IRC nick provided, so make sure that your actual registered nick ends with "_zulip".
18-
1917
## Example
2018

2119
```
22-
./irc-mirror.py --irc-server=irc.freenode.net --channel='#python-mypy' --nick-prefix=irc_mirror \
20+
./irc-mirror.py --irc-server=irc.freenode.net --channel='#python-mypy' --nickname=irc_mirror \
2321
--stream='test here' --topic='#mypy' \
2422
--site="https://chat.zulip.org" --user=<bot-email> \
2523
--api-key=<bot-api-key>

zulip/integrations/bridge_with_irc/irc-mirror.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@
99
import sys
1010
import traceback
1111

12-
usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nick-prefix=<NICK> --stream=<STREAM> [optional args]
12+
usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nickname=<NICK> --stream=<STREAM> [optional args]
1313
1414
Example:
1515
16-
./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' --topic='#mypy'
16+
./irc-mirror.py --irc-server=irc.freenode.net --channel='#test' --nickname=username --stream='test' --topic='#mypy'
1717
1818
--stream is a Zulip stream.
1919
--topic is a Zulip topic, is optionally specified, defaults to "IRC".
2020
--nickserv-pw is a password for the nickserv, is optionally specified.
2121
2222
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
23-
24-
Note that "_zulip" will be automatically appended to the IRC nick provided
2523
"""
2624

2725
if __name__ == "__main__":
2826
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage), allow_provisioning=True)
2927
parser.add_argument('--irc-server', default=None)
3028
parser.add_argument('--port', default=6667)
31-
parser.add_argument('--nick-prefix', default=None)
29+
parser.add_argument('--nickname', default=None)
3230
parser.add_argument('--channel', default=None)
3331
parser.add_argument('--stream', default="general")
3432
parser.add_argument('--topic', default="IRC")
@@ -46,10 +44,10 @@
4644
"{} --provision".format(sys.argv[0]))
4745
sys.exit(1)
4846

49-
if options.irc_server is None or options.nick_prefix is None or options.channel is None:
47+
if options.irc_server is None or options.nickname is None or options.channel is None:
5048
parser.error("Missing required argument")
5149

52-
nickname = options.nick_prefix + "_zulip"
50+
nickname = options.nickname
5351
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel,
5452
nickname, options.irc_server, options.nickserv_pw, options.port)
5553
bot.start()

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, zulip_client: Any, stream: str, topic: str, channel: irc.bot.
1515
self.zulip_client = zulip_client
1616
self.stream = stream
1717
self.topic = topic
18+
self.nickname = nickname
1819
self.IRC_DOMAIN = server
1920
self.nickserv_password = nickserv_password
2021
# Make sure the bot is subscribed to the stream
@@ -84,7 +85,7 @@ def forward_to_irc(msg: Dict[str, Any]) -> None:
8485
def on_privmsg(self, c: ServerConnection, e: Event) -> None:
8586
content = e.arguments[0]
8687
sender = self.zulip_sender(e.source)
87-
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
88+
if sender == (self.nickname + "@" + self.IRC_DOMAIN):
8889
return
8990

9091
# Forward the PM to Zulip
@@ -98,7 +99,7 @@ def on_privmsg(self, c: ServerConnection, e: Event) -> None:
9899
def on_pubmsg(self, c: ServerConnection, e: Event) -> None:
99100
content = e.arguments[0]
100101
sender = self.zulip_sender(e.source)
101-
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
102+
if sender == (self.nickname + "@" + self.IRC_DOMAIN):
102103
return
103104

104105
# Forward the stream message to Zulip

0 commit comments

Comments
 (0)