Skip to content

Commit 5b7f0c2

Browse files
rhttimabbott
authored andcommitted
bridge_with_irc: Implement nickserv password.
1 parent 5b704b7 commit 5b7f0c2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

zulip/integrations/bridge_with_irc/irc-mirror.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
--stream is a Zulip stream.
2323
--topic is a Zulip topic, is optionally specified, defaults to "IRC".
24+
--nickserv-pw is a password for the nickserv, is optionally specified.
2425
2526
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
2627
@@ -35,14 +36,15 @@
3536
parser.add_argument('--channel', default=None)
3637
parser.add_argument('--stream', default="general")
3738
parser.add_argument('--topic', default="IRC")
39+
parser.add_argument('--nickserv-pw', default='')
3840

3941
options = parser.parse_args()
4042
# Setting the client to irc_mirror is critical for this to work
4143
options.client = "irc_mirror"
4244
zulip_client = zulip.init_from_options(options)
4345
try:
4446
from irc_mirror_backend import IRCBot
45-
except ImportError as e:
47+
except ImportError:
4648
traceback.print_exc()
4749
print("You have unsatisfied dependencies. Install all missing dependencies with "
4850
"{} --provision".format(sys.argv[0]))
@@ -52,5 +54,6 @@
5254
parser.error("Missing required argument")
5355

5456
nickname = options.nick_prefix + "_zulip"
55-
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel, nickname, options.irc_server, options.port)
57+
bot = IRCBot(zulip_client, options.stream, options.topic, options.channel,
58+
nickname, options.irc_server, options.nickserv_pw, options.port)
5659
bot.start()

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

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

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
12+
def __init__(self, zulip_client, stream, topic, channel,
13+
nickname, server, nickserv_password='', port=6667):
14+
# type: (Any, str, str, irc.bot.Channel, str, str, str, int) -> None
1415
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
1516
self.channel = channel # type: irc.bot.Channel
1617
self.zulip_client = zulip_client
1718
self.stream = stream
1819
self.topic = topic
1920
self.IRC_DOMAIN = server
21+
self.nickserv_password = nickserv_password
2022

2123
def zulip_sender(self, sender_string):
2224
# type: (str) -> str
@@ -38,6 +40,9 @@ def on_nicknameinuse(self, c, e):
3840

3941
def on_welcome(self, c, e):
4042
# type: (ServerConnection, Event) -> None
43+
if len(self.nickserv_password) > 0:
44+
msg = 'identify %s' % (self.nickserv_password,)
45+
c.privmsg('NickServ', msg)
4146
c.join(self.channel)
4247

4348
def forward_to_irc(msg):

0 commit comments

Comments
 (0)