def test_config_path_with_tilde(self, mock_os_path_exists: bool) -> None:
     parser = zulip.add_default_arguments(argparse.ArgumentParser(usage="lorem ipsum"))
     test_path = '~/zuliprc'
     args = parser.parse_args(['--config-file', test_path])
     with self.assertRaises(ZulipError) as cm:
         zulip.init_from_options(args)
     expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
     self.assertEqual(str(cm.exception), 'api_key or email not specified and '
                      'file {} does not exist'.format(expanded_test_path))
 def test_config_path_with_tilde(self, mock_os_path_exists):
     # type: (bool) -> None
     parser = zulip.add_default_arguments(argparse.ArgumentParser(usage="lorem ipsum"))
     test_path = '~/zuliprc'
     args = parser.parse_args(['--config-file', test_path])
     with self.assertRaises(ZulipError) as cm:
         zulip.init_from_options(args)
     expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
     self.assertEqual(str(cm.exception), 'api_key or email not specified and '
                      'file {} does not exist'.format(expanded_test_path))
Пример #3
0
    def initialize(self, bot_handler):
        self.config_info = bot_handler.get_config_info('github_detail',
                                                       optional=True)
        self.owner = self.config_info.get("owner", False)
        self.repo = self.config_info.get("repo", False)

        args = argparse.Namespace()

        args.cert_bundle = None
        args.client_cert = None
        args.client_cert_key = None
        args.insecure = False
        args.verbose = False
        args.zulip_api_key = None
        args.zulip_client = None
        dir_path = os.path.dirname(os.path.realpath(__file__))
        args.zulip_config_file = os.path.join(dir_path, 'humanrc')
        args.zulip_email = None
        args.zulip_site = None

        client = zulip.init_from_options(args)

        data = client.get_subscribers(stream='core team')
        # subscriptions =  client.get_subscribers(stream='GCI mentors')
        self.data = data
        print(data)
Пример #4
0
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,
Пример #5
0
        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
Пример #6
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()
Пример #7
0
def main():
    # type: () -> int
    usage = """zulip-send [options] [recipient...]

    Sends a message to specified recipients.

    Examples: zulip-send --stream denmark --subject castle -m "Something is rotten in the state of Denmark."
              zulip-send [email protected] [email protected] -m "Conscience doth make cowards of us all."

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

    parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))

    parser.add_argument(
        'recipients',
        nargs='*',
        help='email addresses of the recipients of the message')

    parser.add_argument(
        '-m',
        '--message',
        help='Specifies the message to send, prevents interactive prompting.')

    group = parser.add_argument_group('Stream parameters')
    group.add_argument(
        '-s',
        '--stream',
        dest='stream',
        action='store',
        help='Allows the user to specify a stream for the message.')
    group.add_argument(
        '-S',
        '--subject',
        dest='subject',
        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,
        }

    if not do_send_message(client, message_data):
        return 1
    return 0
Пример #8
0
                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")

    zulip = 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 = zulip.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(zulip))

    address = None
    if options.jabber_server_address:
Пример #9
0
def main() -> int:
    usage = """zulip-send [options] [recipient...]

    Sends a message to specified recipients.

    Examples: zulip-send --stream denmark --subject castle -m "Something is rotten in the state of Denmark."
              zulip-send [email protected] [email protected] -m "Conscience doth make cowards of us all."

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

    parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))

    parser.add_argument(
        "recipients", nargs="*", help="email addresses of the recipients of the message"
    )

    parser.add_argument(
        "-m", "--message", help="Specifies the message to send, prevents interactive prompting."
    )

    group = parser.add_argument_group("Stream parameters")
    group.add_argument(
        "-s",
        "--stream",
        dest="stream",
        action="store",
        help="Allows the user to specify a stream for the message.",
    )
    group.add_argument(
        "-S",
        "--subject",
        dest="subject",
        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,
        }

    if not do_send_message(client, message_data):
        return 1
    return 0
Пример #10
0
                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:
Пример #11
0
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
Пример #12
0
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
Пример #13
0
def main():
    # type: () -> int
    usage = """zulip-send [options] [recipient...]

    Sends a message to specified recipients.

    Examples: zulip-send --stream denmark --subject castle -m "Something is rotten in the state of Denmark."
              zulip-send [email protected] [email protected] -m "Conscience doth make cowards of us all."

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

    parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))

    parser.add_argument('recipients',
                        nargs='*',
                        help='email addresses of the recipients of the message')

    parser.add_argument('-m', '--message',
                        help='Specifies the message to send, prevents interactive prompting.')

    group = parser.add_argument_group('Stream parameters')
    group.add_argument('-s', '--stream',
                       dest='stream',
                       action='store',
                       help='Allows the user to specify a stream for the message.')
    group.add_argument('-S', '--subject',
                       dest='subject',
                       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,
        }

    if not do_send_message(client, message_data):
        return 1
    return 0