Exemple #1
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 #2
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)
Exemple #3
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!')))