How to use the zulip.init_from_options function in zulip

To help you get started, we’ve selected a few zulip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zulip / python-zulip-api / zulip / integrations / bridge_with_irc / irc-mirror.py View on Github external
"""

if __name__ == "__main__":
    parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage), allow_provisioning=True)
    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)
    parser.add_argument('--stream', default="general")
    parser.add_argument('--topic', default="IRC")
    parser.add_argument('--nickserv-pw', default='')

    options = parser.parse_args()
    # Setting the client to irc_mirror is critical for this to work
    options.client = "irc_mirror"
    zulip_client = zulip.init_from_options(options)
    try:
        from irc_mirror_backend import IRCBot
    except ImportError:
        traceback.print_exc()
        print("You have unsatisfied dependencies. Install all missing dependencies with "
              "{} --provision".format(sys.argv[0]))
        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")

    nickname = options.nick_prefix + "_zulip"
    bot = IRCBot(zulip_client, options.stream, options.topic, options.channel,
                 nickname, options.irc_server, options.nickserv_pw, options.port)
    bot.start()
github zulip / python-zulip-api / zulip / zulip / send.py View on Github external
action='store',
                       help='Allows the user to specify a subject for the message.')

    options = parser.parse_args()

    if options.verbose:
        logging.getLogger().setLevel(logging.INFO)
    # Sanity check user data
    if len(options.recipients) != 0 and (options.stream or options.subject):
        parser.error('You cannot specify both a username and a stream/subject.')
    if len(options.recipients) == 0 and (bool(options.stream) != bool(options.subject)):
        parser.error('Stream messages must have a subject')
    if len(options.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': options.recipients,
github zulip / python-zulip-api / zulip / integrations / jabber / jabber_mirror_backend.py View on Github external
setattr(options, option, False)

    if options.mode is None:
        options.mode = "personal"

    if options.zulip_email_suffix is None:
        options.zulip_email_suffix = ''

    if options.mode not in ('public', 'personal'):
        config_error("Bad value for --mode: must be one of 'public' or 'personal'")

    if None in (options.jid, options.jabber_password):
        config_error("You must specify your Jabber JID and Jabber password either "
                     "in the Zulip configuration file or on the commandline")

    zulipToJabber = ZulipToJabberBot(zulip.init_from_options(options, "JabberMirror/" + __version__))
    # This won't work for open realms that don't have a consistent domain
    options.zulip_domain = zulipToJabber.client.email.partition('@')[-1]

    try:
        jid = JID(options.jid)
    except InvalidJID as e:
        config_error("Bad JID: %s: %s" % (options.jid, e.message))

    if options.conference_domain is None:
        options.conference_domain = "conference.%s" % (jid.domain,)

    xmpp = JabberToZulipBot(jid, options.jabber_password, get_rooms(zulipToJabber))

    address = None
    if options.jabber_server_address:
        address = (options.jabber_server_address, options.jabber_server_port)