Exemple #1
0
def config(bot, event, cmd=None, *args):
    """Show or change bot configuration
       Usage: /bot config [get|set] [key] [subkey] [...] [value]"""

    if cmd == 'get' or cmd is None:
        config_args = list(args)
        value = bot.config.get_by_path(config_args) if config_args else dict(bot.config)
    elif cmd == 'set':
        config_args = list(args[:-1])
        if len(args) >= 2:
            bot.config.set_by_path(config_args, json.loads(args[-1]))
            bot.config.save()
            value = bot.config.get_by_path(config_args)
        else:
            yield from command.unknown_command(bot, event)
            return
    else:
        yield from command.unknown_command(bot, event)
        return

    if value is None:
        value = _('Key not found!')

    config_path = ' '.join(k for k in ['config'] + config_args)
    text = (
        '**{}:**\n'
        '{}'
    ).format(config_path, json.dumps(value, indent=2, sort_keys=True))
    yield from event.conv.send_message(text_to_segments(text))
Exemple #2
0
def config(bot, event, cmd=None, *args):
    """Show or change bot configuration
       Usage: config [get | set] [key] [subkey] [...] [value]"""

    if cmd == 'get' or cmd is None:
        config_args = list(args)
        value = bot.config.get_by_path(config_args) if config_args else dict(
            bot.config)
    elif cmd == 'set':
        config_args = list(args[:-1])
        if len(args) >= 2:
            bot.config.set_by_path(config_args, json.loads(args[-1]))
            bot.config.save()
            value = bot.config.get_by_path(config_args)
        else:
            yield from command.unknown_command(bot, event)
            return
    else:
        yield from command.unknown_command(bot, event)
        return

    if value is None:
        value = _('Key not found!')

    config_path = ' '.join(k for k in ['config'] + config_args)
    text = ('**{}:**\n'
            '{}').format(config_path,
                         json.dumps(value, indent=2, sort_keys=True))
    yield from event.conv.send_message(text_to_segments(text))
Exemple #3
0
def config(bot, event, cmd=None, *args):
    """Show or change bot configuration
       Usage: /bot config [get|set] [key] [subkey] [...] [value]"""

    if cmd == 'get' or cmd is None:
        config_args = list(args)
        value = bot.config.get_by_path(config_args) if config_args else dict(bot.config)
    elif cmd == 'set':
        config_args = list(args[:-1])
        if len(args) >= 2:
            bot.config.set_by_path(config_args, json.loads(args[-1]))
            bot.config.save()
            value = bot.config.get_by_path(config_args)
        else:
            yield from command.unknown_command(bot, event)
            return
    else:
        yield from command.unknown_command(bot, event)
        return

    if value is None:
        value = _('Key not found!')

    config_path = ' '.join(k for k in ['config'] + config_args)
    segments = [hangups.ChatMessageSegment('{}:'.format(config_path),
                                           is_bold=True),
                hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)]
    segments.extend(text_to_segments(json.dumps(value, indent=2, sort_keys=True)))
    bot.send_message_segments(event.conv, segments)
Exemple #4
0
def help(bot, event, cmd=None, *args):
    """Help me, Obi-Wan Kenobi. You're my only hope.
       Usage: help [command]"""

    cmd = cmd if cmd else 'help'
    try:
        command_fn = command.commands[cmd]
    except KeyError:
        yield from command.unknown_command(bot, event)
        return

    text = _('**{}:**\n'
             '{}').format(cmd, _(command_fn.__doc__))

    if cmd == 'help':
        # See if the user has admin privileges to limit commands displayed
        admins_list = bot.get_config_suboption(event.conv_id, 'admins')
        if event.user_id.chat_id not in admins_list:
            command_list = command.get_user_commands(bot, event.conv_id)
        else:
            command_list = command.commands.keys()
        text += _('\n\n'
                  '**Supported commands:**\n'
                  '{}').format(', '.join(sorted(command_list)))

    yield from event.conv.send_message(text_to_segments(text))
Exemple #5
0
def conv_add(bot, event, conv_name, *args):
    """Invite users to existing conversation (use . for current conversation)
Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    chat_id_list = get_unique_users(bot, args)
    if not chat_id_list:
        yield from command.unknown_command(bot, event)
        return

    convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name)
    for c in convs:
        yield from bot._client.adduser(c.id_, chat_id_list)
Exemple #6
0
def conv_create(bot, event, conv_name, *args):
    """Create new conversation and invite users to it
Usage: /bot conv_create conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    chat_id_list = get_unique_users(bot, args)
    if not chat_id_list:
        yield from command.unknown_command(bot, event)
        return

    res = yield from bot._client.createconversation(chat_id_list, force_group=True)
    conv_id = res['conversation']['id']['id']
    yield from bot._client.setchatname(conv_id, conv_name)
    yield from bot._conv_list.get(conv_id).send_message(text_to_segments(_('Welcome!')))
Exemple #7
0
def conv_add(bot, event, conv_name, *args):
    """Invite users to existing conversation (use . for current conversation)
       Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    chat_id_list = get_unique_users(bot, args)
    if not chat_id_list:
        yield from command.unknown_command(bot, event)
        return

    convs = [event.conv
             ] if conv_name == '.' else bot.find_conversations(conv_name)
    for c in convs:
        yield from bot._client.adduser(c.id_, chat_id_list)
Exemple #8
0
def conv_create(bot, event, conv_name, *args):
    """Create new conversation and invite users to it
       Usage: /bot conv_create conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    chat_id_list = get_unique_users(bot, args)
    if not chat_id_list:
        yield from command.unknown_command(bot, event)
        return

    res = yield from bot._client.createconversation(chat_id_list,
                                                    force_group=True)
    conv_id = res['conversation']['id']['id']
    yield from bot._client.setchatname(conv_id, conv_name)
    yield from bot._conv_list.get(conv_id).send_message(
        text_to_segments(_('Welcome!')))
Exemple #9
0
def help(bot, event, cmd=None, *args):
    """Help me, Obi-Wan Kenobi. You're my only hope.
       Usage: /bot help [command]"""

    cmd = cmd if cmd else 'help'
    try:
        command_fn = command.commands[cmd]
    except KeyError:
        yield from command.unknown_command(bot, event)
        return

    text = _('**{}:**\n' '{}').format(cmd, _(command_fn.__doc__))

    if cmd == 'help':
        text += _('\n\n'
                  '**Supported commands:**\n'
                  '{}').format(', '.join(sorted(command.commands.keys())))

    yield from event.conv.send_message(text_to_segments(text))
Exemple #10
0
def help(bot, event, cmd=None, *args):
    """Help me, Obi-Wan Kenobi. You're my only hope.
       Usage: /bot help [command]"""

    cmd = cmd if cmd else 'help'
    try:
        command_fn = command.commands[cmd]
    except KeyError:
        yield from command.unknown_command(bot, event)
        return

    text = _('**{}:**\n'
             '{}').format(cmd, _(command_fn.__doc__))

    if cmd == 'help':
        text += _('\n\n'
                  '**Supported commands:**\n'
                  '{}').format(', '.join(sorted(command.commands.keys())))

    yield from event.conv.send_message(text_to_segments(text))
Exemple #11
0
def conv_add(bot, event, conv_name, *args):
    """Invite users to existing conversation (use . for current conversation)
       Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    unique_user_objects = get_unique_user_objects(bot, args)
    if not unique_user_objects:
        yield from command.unknown_command(bot, event)
        return
    invitee_ids = [
        InviteeID(gaia_id=u.id_.gaia_id, fallback_name=u.full_name)
        for u in unique_user_objects
    ]
    convs = [event.conv
             ] if conv_name == '.' else bot.find_conversations(conv_name)
    for c in convs:
        req = hangouts_pb2.AddUserRequest(
            request_header=bot._client.get_request_header(),
            invitee_id=invitee_ids,
            event_request_header=c._get_event_request_header())
        res = yield from bot._client.add_user(req)
        c.add_event(res.created_event)
def conv_add(bot, event, conv_name, *args):
    """Invite users to existing conversation (use . for current conversation)
       Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    unique_user_objects = get_unique_user_objects(bot, args)
    if not unique_user_objects:
        yield from command.unknown_command(bot, event)
        return
    invitee_ids = [InviteeID(
        gaia_id=u.id_.gaia_id,
        fallback_name=u.full_name
    ) for u in unique_user_objects]
    convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name)
    for c in convs:
        req = hangouts_pb2.AddUserRequest(
            request_header=bot._client.get_request_header(),
            invitee_id=invitee_ids,
            event_request_header=c._get_event_request_header()
        )
        res = yield from bot._client.add_user(req)
        c.add_event(res.created_event)
Exemple #13
0
def conv_create(bot, event, conv_name, *args):
    """Create new conversation and invite users to it
       Usage: /bot conv_create conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    unique_user_objects = get_unique_user_objects(bot, args)
    if not unique_user_objects:
        yield from command.unknown_command(bot, event)
        return
    invitee_ids = [
        InviteeID(gaia_id=u.id_.gaia_id, fallback_name=u.full_name)
        for u in unique_user_objects
    ]
    request = hangouts_pb2.CreateConversationRequest(
        request_header=bot._client.get_request_header(),
        type=hangouts_pb2.CONVERSATION_TYPE_GROUP,
        client_generated_id=bot._client.get_client_generated_id(),
        name=conv_name,
        invitee_id=invitee_ids)
    res = yield from bot._client.create_conversation(request)
    conv = bot._conv_list.add_conversation(res.conversation)
    yield from conv.rename(conv_name)
    yield from conv.send_message(text_to_segments(('Welcome!')))
Exemple #14
0
def help(bot, event, cmd=None, *args):
    """Help me, Obi-Wan Kenobi. You're my only hope.
       Usage: /bot help [command]"""

    cmd = cmd if cmd else 'help'
    try:
        command_fn = command.commands[cmd]
    except KeyError:
        yield from command.unknown_command(bot, event)
        return

    segments = [hangups.ChatMessageSegment('{}:'.format(cmd), is_bold=True),
                hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)]
    segments.extend(text_to_segments(_(command_fn.__doc__)))

    if cmd == 'help':
        segments.extend([hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                         hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                         hangups.ChatMessageSegment(_('Supported commands:'), is_bold=True),
                         hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                         hangups.ChatMessageSegment(', '.join(sorted(command.commands.keys())))])

    bot.send_message_segments(event.conv, segments)
def conv_create(bot, event, conv_name, *args):
    """Create new conversation and invite users to it
       Usage: /bot conv_create conversation_name [user_name_1] [user_name_2] [...]"""
    conv_name = strip_quotes(conv_name)
    unique_user_objects = get_unique_user_objects(bot, args)
    if not unique_user_objects:
        yield from command.unknown_command(bot, event)
        return
    invitee_ids = [InviteeID(
        gaia_id=u.id_.gaia_id,
        fallback_name=u.full_name
    ) for u in unique_user_objects]
    request = hangouts_pb2.CreateConversationRequest(
        request_header=bot._client.get_request_header(),
        type=hangouts_pb2.CONVERSATION_TYPE_GROUP,
        client_generated_id=bot._client.get_client_generated_id(),
        name=conv_name,
        invitee_id=invitee_ids
    )
    res = yield from bot._client.create_conversation(request)
    conv = bot._conv_list.add_conversation(res.conversation)
    yield from conv.rename(conv_name)
    yield from conv.send_message(text_to_segments(('Welcome!')))