2020-04-02 09:59:28 -04:00
|
|
|
#!/usr/bin/env python3
|
2013-10-09 14:03:47 -04:00
|
|
|
#
|
|
|
|
# EXPERIMENTAL
|
|
|
|
# IRC <=> Zulip mirroring bot
|
|
|
|
#
|
|
|
|
|
2017-08-01 17:38:33 -04:00
|
|
|
import argparse
|
2017-09-01 10:27:46 -04:00
|
|
|
import sys
|
|
|
|
import traceback
|
2016-09-10 15:19:08 -04:00
|
|
|
|
2021-05-28 05:00:04 -04:00
|
|
|
import zulip
|
|
|
|
|
2018-08-13 02:39:31 -04:00
|
|
|
usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel=<CHANNEL> --nick-prefix=<NICK> --stream=<STREAM> [optional args]
|
2013-10-09 14:03:47 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2018-08-13 05:46:42 -04:00
|
|
|
./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --stream='test' --topic='#mypy'
|
2018-08-13 02:39:31 -04:00
|
|
|
|
|
|
|
--stream is a Zulip stream.
|
2018-08-13 05:46:42 -04:00
|
|
|
--topic is a Zulip topic, is optionally specified, defaults to "IRC".
|
2018-12-16 22:43:12 -05:00
|
|
|
--nickserv-pw is a password for the nickserv, is optionally specified.
|
2017-08-25 05:03:06 -04:00
|
|
|
|
|
|
|
Specify your Zulip API credentials and server in a ~/.zuliprc file or using the options.
|
2013-10-09 14:03:47 -04:00
|
|
|
|
|
|
|
Note that "_zulip" will be automatically appended to the IRC nick provided
|
|
|
|
"""
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-05-28 05:03:46 -04:00
|
|
|
parser = zulip.add_default_arguments(
|
|
|
|
argparse.ArgumentParser(usage=usage), allow_provisioning=True
|
|
|
|
)
|
2017-08-01 17:38:33 -04:00
|
|
|
parser.add_argument('--irc-server', default=None)
|
|
|
|
parser.add_argument('--port', default=6667)
|
|
|
|
parser.add_argument('--nick-prefix', default=None)
|
|
|
|
parser.add_argument('--channel', default=None)
|
2018-08-13 02:39:31 -04:00
|
|
|
parser.add_argument('--stream', default="general")
|
2018-08-13 05:46:42 -04:00
|
|
|
parser.add_argument('--topic', default="IRC")
|
2018-12-16 22:43:12 -05:00
|
|
|
parser.add_argument('--nickserv-pw', default='')
|
2017-08-01 17:38:33 -04:00
|
|
|
|
|
|
|
options = parser.parse_args()
|
2013-10-09 14:03:47 -04:00
|
|
|
# Setting the client to irc_mirror is critical for this to work
|
|
|
|
options.client = "irc_mirror"
|
|
|
|
zulip_client = zulip.init_from_options(options)
|
2017-09-01 10:27:46 -04:00
|
|
|
try:
|
|
|
|
from irc_mirror_backend import IRCBot
|
2018-12-16 22:43:12 -05:00
|
|
|
except ImportError:
|
2017-09-01 10:27:46 -04:00
|
|
|
traceback.print_exc()
|
2021-05-28 05:03:46 -04:00
|
|
|
print(
|
|
|
|
"You have unsatisfied dependencies. Install all missing dependencies with "
|
|
|
|
"{} --provision".format(sys.argv[0])
|
|
|
|
)
|
2017-09-01 10:27:46 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if options.irc_server is None or options.nick_prefix is None or options.channel is None:
|
|
|
|
parser.error("Missing required argument")
|
2013-10-09 14:03:47 -04:00
|
|
|
|
|
|
|
nickname = options.nick_prefix + "_zulip"
|
2021-05-28 05:03:46 -04:00
|
|
|
bot = IRCBot(
|
|
|
|
zulip_client,
|
|
|
|
options.stream,
|
|
|
|
options.topic,
|
|
|
|
options.channel,
|
|
|
|
nickname,
|
|
|
|
options.irc_server,
|
|
|
|
options.nickserv_pw,
|
|
|
|
options.port,
|
|
|
|
)
|
2013-10-09 14:03:47 -04:00
|
|
|
bot.start()
|