jabber_group.add_option('--no-use-tls', default=None, action='store_true') jabber_group.add_option( '--jabber-server-address', default=None, action='store', help="The hostname of your Jabber server. This is only needed if " "your server is missing SRV records") jabber_group.add_option( '--jabber-server-port', default='5222', action='store', help="The port of your Jabber server. This is only needed if " "your server is missing SRV records") parser.add_option_group(jabber_group) parser.add_option_group(zulip.generate_option_group(parser, "zulip-")) (options, args) = parser.parse_args() logging.basicConfig(level=options.log_level, format='%(levelname)-8s %(message)s') if options.zulip_config_file is None: config_file = zulip.get_default_config_filename() else: config_file = options.zulip_config_file config = SafeConfigParser() try: with open(config_file, 'r') as f: config.readfp(f, config_file) except IOError:
def main(argv=None): # type: (Optional[List[str]]) -> int if argv is None: argv = sys.argv usage = """%prog [options] [recipient...] Sends a message specified recipients. Examples: %prog --stream denmark --subject castle -m "Something is rotten in the state of Denmark." %prog [email protected] [email protected] -m "Conscience doth make cowards of us all." These examples assume you have a proper '~/.zuliprc'. You may also set your credentials with the '--user' and '--api-key' arguments. """ parser = optparse.OptionParser(usage=usage) # Grab parser options from the API common set parser.add_option_group(zulip.generate_option_group(parser)) parser.add_option( '-m', '--message', help='Specifies the message to send, prevents interactive prompting.') group = optparse.OptionGroup( parser, 'Stream parameters' ) # type: ignore # https://github.com/python/typeshed/pull/1248 group.add_option( '-s', '--stream', dest='stream', action='store', help='Allows the user to specify a stream for the message.') group.add_option( '-S', '--subject', dest='subject', action='store', help='Allows the user to specify a subject for the message.') parser.add_option_group(group) (options, recipients) = parser.parse_args(argv[1:]) if options.verbose: logging.getLogger().setLevel(logging.INFO) # Sanity check user data if len(recipients) != 0 and (options.stream or options.subject): parser.error( 'You cannot specify both a username and a stream/subject.') if len(recipients) == 0 and (bool(options.stream) != bool( options.subject)): parser.error('Stream messages must have a subject') if len(recipients) == 0 and not (options.stream and options.subject): parser.error( 'You must specify a stream/subject or at least one recipient.') client = zulip.init_from_options(options) if not options.message: options.message = sys.stdin.read() if options.stream: message_data = { 'type': 'stream', 'content': options.message, 'subject': options.subject, 'to': options.stream, } else: message_data = { 'type': 'private', 'content': options.message, 'to': recipients, } if not do_send_message(client, message_data): return 1 return 0
./irc-mirror.py --irc-server=127.0.0.1 --channel='#test' --nick-prefix=username --site=https://zulip.example.com [email protected] --api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Note that "_zulip" will be automatically appended to the IRC nick provided Also note that at present you need to edit this code to do the Zulip => IRC side """ if __name__ == "__main__": parser = optparse.OptionParser(usage=usage) parser.add_option('--irc-server', default=None) parser.add_option('--port', default=6667) parser.add_option('--nick-prefix', default=None) parser.add_option('--channel', default=None) parser.add_option_group(zulip.generate_option_group(parser)) (options, args) = parser.parse_args() if options.irc_server is None or options.nick_prefix is None or options.channel is None: parser.error("Missing required argument") # Setting the client to irc_mirror is critical for this to work options.client = "irc_mirror" zulip_client = zulip.init_from_options(options) nickname = options.nick_prefix + "_zulip" bot = IRCBot(options.channel, nickname, options.irc_server, options.port) bot.start()
def main(argv=None): # type: (Optional[List[str]]) -> int if argv is None: argv = sys.argv usage = """%prog [options] [recipient...] Sends a message specified recipients. Examples: %prog --stream denmark --subject castle -m "Something is rotten in the state of Denmark." %prog [email protected] [email protected] -m "Conscience doth make cowards of us all." These examples assume you have a proper '~/.zuliprc'. You may also set your credentials with the '--user' and '--api-key' arguments. """ parser = optparse.OptionParser(usage=usage) # Grab parser options from the API common set parser.add_option_group(zulip.generate_option_group(parser)) parser.add_option('-m', '--message', help='Specifies the message to send, prevents interactive prompting.') group = optparse.OptionGroup(parser, 'Stream parameters') # type: ignore # https://github.com/python/typeshed/pull/1248 group.add_option('-s', '--stream', dest='stream', action='store', help='Allows the user to specify a stream for the message.') group.add_option('-S', '--subject', dest='subject', action='store', help='Allows the user to specify a subject for the message.') parser.add_option_group(group) (options, recipients) = parser.parse_args(argv[1:]) if options.verbose: logging.getLogger().setLevel(logging.INFO) # Sanity check user data if len(recipients) != 0 and (options.stream or options.subject): parser.error('You cannot specify both a username and a stream/subject.') if len(recipients) == 0 and (bool(options.stream) != bool(options.subject)): parser.error('Stream messages must have a subject') if len(recipients) == 0 and not (options.stream and options.subject): parser.error('You must specify a stream/subject or at least one recipient.') client = zulip.init_from_options(options) if not options.message: options.message = sys.stdin.read() if options.stream: message_data = { 'type': 'stream', 'content': options.message, 'subject': options.subject, 'to': options.stream, } else: message_data = { 'type': 'private', 'content': options.message, 'to': recipients, } if not do_send_message(client, message_data): return 1 return 0