Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ef0aba

Browse files
rhttimabbott
authored andcommitted
bridge_with_irc: Add command line arg to specify topic.
1 parent 8e69598 commit 8ef0aba

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

zulip/integrations/bridge_with_irc/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
```
88

99
`--stream` is a Zulip stream.
10+
`--topic` is a Zulip topic, is optionally specified, defaults to "IRC".
1011

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

@@ -15,6 +16,8 @@ Note that "_zulip" will be automatically appended to the IRC nick provided
1516
## Example
1617

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

zulip/integrations/bridge_with_irc/irc-mirror.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
1818
Example:
1919
20-
./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test'
20+
./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' --topic='#mypy'
2121
2222
--stream is a Zulip stream.
23+
--topic is a Zulip topic, is optionally specified, defaults to "IRC".
2324
2425
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
2526
@@ -33,6 +34,7 @@
3334
parser.add_argument('--nick-prefix', default=None)
3435
parser.add_argument('--channel', default=None)
3536
parser.add_argument('--stream', default="general")
37+
parser.add_argument('--topic', default="IRC")
3638

3739
options = parser.parse_args()
3840
# Setting the client to irc_mirror is critical for this to work
@@ -50,5 +52,5 @@
5052
parser.error("Missing required argument")
5153

5254
nickname = options.nick_prefix + "_zulip"
53-
bot = IRCBot(zulip_client, options.stream, options.channel, nickname, options.irc_server, options.port)
55+
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel, nickname, options.irc_server, options.port)
5456
bot.start()

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
class IRCBot(irc.bot.SingleServerIRCBot):
1010
reactor_class = AioReactor
1111

12-
def __init__(self, zulip_client, stream, channel, nickname, server, port=6667):
13-
# type: (Any, str, irc.bot.Channel, str, str, int) -> None
12+
def __init__(self, zulip_client, stream, topic, channel, nickname, server, port=6667):
13+
# type: (Any, str, str, irc.bot.Channel, str, str, int) -> None
1414
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
1515
self.channel = channel # type: irc.bot.Channel
1616
self.zulip_client = zulip_client
1717
self.stream = stream
18+
self.topic = topic
1819
self.IRC_DOMAIN = server
1920

2021
def zulip_sender(self, sender_string):
@@ -77,16 +78,15 @@ def on_privmsg(self, c, e):
7778
def on_pubmsg(self, c, e):
7879
# type: (ServerConnection, Event) -> None
7980
content = e.arguments[0]
80-
stream = self.stream
8181
sender = self.zulip_sender(e.source)
8282
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
8383
return
8484

8585
# Forward the stream message to Zulip
8686
print(self.zulip_client.send_message({
8787
"type": "stream",
88-
"to": stream,
89-
"subject": "IRC",
88+
"to": self.stream,
89+
"subject": self.topic,
9090
"content": content,
9191
"content": "**{0}**: {1}".format(sender, content),
9292
}))

0 commit comments

Comments
 (0)