def user_list(bot, event, conv_name='', user_name='', *args): """List all participants in current (or specified) conversation You can also use . for current conversation. Includes G+ accounts and emails. Usage: /bot users_list [conversation_name] [user_name]""" conv_name = strip_quotes(conv_name) user_name = strip_quotes(user_name) convs = [event.conv] if not conv_name or conv_name == '.' else bot.find_conversations(conv_name) segments = [] for c in convs: segments.append(hangups.ChatMessageSegment(_('List of participants in "{}" ({} total):').format( get_conv_name(c, truncate=True), len(c.users)), is_bold=True)) segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)) for u in bot.find_users(user_name, conv=c): link = 'https://plus.google.com/u/0/{}/about'.format(u.id_.chat_id) segments.append(hangups.ChatMessageSegment(u.full_name, hangups.SegmentType.LINK, link_target=link)) if u.emails: segments.append(hangups.ChatMessageSegment(' (')) segments.append(hangups.ChatMessageSegment(u.emails[0], hangups.SegmentType.LINK, link_target='mailto:{}'.format(u.emails[0]))) segments.append(hangups.ChatMessageSegment(')')) segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)) segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)) bot.send_message_segments(event.conv, segments)
def conv_rename(bot, event, conv_name, *args): """Rename conversation (use . for current conversation) Usage: /bot conv_rename conversation_name new_conversation_name""" conv_name = strip_quotes(conv_name) new_conv_name = strip_quotes(' '.join(args)) convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name) for c in convs: yield from bot._client.setchatname(c.id_, new_conv_name)
def conv_rename(bot, event, conv_name, *args): """Rename conversation (use . for current conversation) Usage: /bot conv_rename conversation_name new_conversation_name""" conv_name = strip_quotes(conv_name) new_conv_name = strip_quotes(' '.join(args)) convs = [event.conv ] if conv_name == '.' else bot.find_conversations(conv_name) for c in convs: yield from c.rename(new_conv_name)
def buen(bot, event, que, *args): """Que bueno es el bot\b <bot> buen (bot)""" if strip_quotes(que) == "bot": text = _('Gracias, me esfuerzo') else: text = _('QUE?') yield from event.conv.send_message(text_to_segments(text))
def conv_refresh(bot, event, conv_name, *args): """Create new conversation with same users as in old one except kicked users (use . for current conversation) Usage: /bot conv_refresh conversation_name [kicked_user_name_1] [kicked_user_name_2] [...]""" conv_name = strip_quotes(conv_name) convs = [event.conv ] if conv_name == '.' else bot.find_conversations(conv_name) kicked_chat_ids = get_unique_users(bot, args) for c in convs: old_chat_ids = {u.id_.chat_id for u in bot.find_users('', conv=c)} new_chat_ids = list(old_chat_ids - set(kicked_chat_ids)) # Create new conversation res = yield from bot._client.createconversation(new_chat_ids, force_group=True) conv_id = res['conversation']['id']['id'] yield from bot._client.setchatname(conv_id, c.name) yield from bot._conv_list.get(conv_id).send_message( text_to_segments( _('**Welcome!**\n' 'This is new refreshed conversation. Old conversation has been ' 'terminated, but you are one of the lucky ones who survived cleansing! ' 'If you are still in old conversation, please leave it.'))) # Destroy old one and leave it yield from bot._client.setchatname(c.id_, _('[TERMINATED] {}').format(c.name)) yield from c.send_message( text_to_segments( _('**!!! WARNING !!!**\n' 'This conversation has been terminated! Please leave immediately!' ))) yield from bot._conv_list.leave_conversation(c.id_)
def user_list(bot, event, conv_name="", user_name="", *args): """List all participants in current (or specified) conversation You can also use . for current conversation. Includes G+ accounts and emails. Usage: /bot user_list [conversation_name] [user_name]""" conv_name = strip_quotes(conv_name) user_name = strip_quotes(user_name) convs = [event.conv] if not conv_name or conv_name == "." else bot.find_conversations(conv_name) text = [] for c in convs: text.append( _('**List of participants in "{}" ({} total):**').format(get_conv_name(c, truncate=True), len(c.users)) ) for u in bot.find_users(user_name, conv=c): text.append(user_to_text(u)) text.append("") yield from event.conv.send_message(text_to_segments("\n".join(text)))
def conv_refresh(bot, event, conv_name, *args): """Create new conversation with same users as in old one except kicked users (use . for current conversation) Usage: /bot conv_refresh conversation_name [kicked_user_name_1] [kicked_user_name_2] [...]""" conv_name = strip_quotes(conv_name) convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name) kicked_chat_ids = get_unique_users(bot, args) for c in convs: old_chat_ids = {u.id_.chat_id for u in bot.find_users('', conv=c)} new_chat_ids = list(old_chat_ids - set(kicked_chat_ids)) # Create new conversation res = yield from bot._client.createconversation(new_chat_ids, force_group=True) conv_id = res['conversation']['id']['id'] yield from bot._client.setchatname(conv_id, c.name) yield from bot._conv_list.get(conv_id).send_message( text_to_segments(_('**Welcome!**\n' 'This is new refreshed conversation. Old conversation has been ' 'terminated, but you are one of the lucky ones who survived cleansing! ' 'If you are still in old conversation, please leave it.')) ) # Destroy old one and leave it yield from bot._client.setchatname(c.id_, _('[TERMINATED] {}').format(c.name)) yield from c.send_message( text_to_segments(_('**!!! WARNING !!!**\n' 'This conversation has been terminated! Please leave immediately!')) ) yield from bot._conv_list.leave_conversation(c.id_)
def user_list(bot, event, conv_name='', user_name='', *args): """List all participants in current (or specified) conversation You can also use . for current conversation. Includes G+ accounts and emails. Usage: /bot user_list [conversation_name] [user_name]""" conv_name = strip_quotes(conv_name) user_name = strip_quotes(user_name) convs = [event.conv] if not conv_name or conv_name == '.' else bot.find_conversations(conv_name) text = [] for c in convs: text.append(_( '**List of participants in "{}" ({} total):**' ).format(get_conv_name(c, truncate=True), len(c.users))) for u in bot.find_users(user_name, conv=c): text.append(user_to_text(u)) text.append('') yield from event.conv.send_message(text_to_segments('\n'.join(text)))
def conv_send(bot, event, conv_name, *args): """Send message to conversation as bot (use . for current conversation) Usage: /bot conv_send conversation_name text""" conv_name = strip_quotes(conv_name) convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name) for c in convs: yield from c.send_message(text_to_segments(' '.join(args)))
def user_find(bot, event, user_name='', *args): """Find users known to bot by their name Usage: /bot user_find [user_name]""" user_name = strip_quotes(user_name) text = [_('**Search results for user name "{}":**').format(user_name)] for u in bot.find_users(user_name): text.append(user_to_text(u)) yield from event.conv.send_message(text_to_segments('\n'.join(text)))
def user_find(bot, event, user_name="", *args): """Find users known to bot by their name Usage: /bot user_find [user_name]""" user_name = strip_quotes(user_name) text = [_('**Search results for user name "{}":**').format(user_name)] for u in bot.find_users(user_name): text.append(user_to_text(u)) yield from event.conv.send_message(text_to_segments("\n".join(text)))
def conv_send(bot, event, conv_name, *args): """Send message to conversation as bot (use . for current conversation) Usage: /bot conv_send conversation_name text""" conv_name = strip_quotes(conv_name) convs = [event.conv ] if conv_name == '.' else bot.find_conversations(conv_name) for c in convs: yield from c.send_message(text_to_segments(' '.join(args)))
def conv_leave(bot, event, conv_name='', *args): """Leave current (or specified) conversation Usage: /bot conv_leave [conversation_name]""" conv_name = strip_quotes(conv_name) convs = [event.conv] if not conv_name or conv_name == '.' else bot.find_conversations(conv_name) for c in convs: yield from c.send_message(text_to_segments(_('I\'ll be back!'))) yield from bot._conv_list.leave_conversation(c.id_)
def easteregg(bot, event, easteregg, eggcount=1, period=0.5, conv_name='', *args): """Annoy people with easter egg combo in current (or specified) conversation! Usage: /bot easteregg easter_egg_type [count] [period] [conv_name] Supported easter eggs: ponies, pitchforks, bikeshed, shydino""" conv_name = strip_quotes(conv_name) convs = [event.conv] if not conv_name or conv_name == '.' else bot.find_conversations(conv_name) for c in convs: asyncio.async( easteregg_combo(bot._client, c.id_, easteregg, int(eggcount), float(period)) ).add_done_callback(lambda future: future.result())
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)
def conv_leave(bot, event, conv_name='', *args): """Leave current (or specified) conversation Usage: /bot conv_leave [conversation_name]""" conv_name = strip_quotes(conv_name) convs = [ event.conv ] if not conv_name or conv_name == '.' else bot.find_conversations( conv_name) for c in convs: yield from c.send_message(text_to_segments(_('I\'ll be back!'))) yield from c.leave()
def adminify(bot, event, user_name='', *args): """Add user as admin by name or ID Usage: adminify [user_name|ID]""" username = strip_quotes(user_name) matches = bot.find_users(user_name) if matches > 1: text = [_('**Multiple matches for name "{}":**').format(user_name)] for match in matches: text.append(user_to_text(match)) yield from event.conv.send_message(text_to_segments('\n'.join(text))) else: pass
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!')))
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)
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!')))
def conv_refresh(bot, event, conv_name, *args): """Create new conversation with same users as in old one except kicked users (use . for current conversation) Usage: /bot conv_refresh conversation_name [kicked_user_name_1] [kicked_user_name_2] [...]""" conv_name = strip_quotes(conv_name) convs = [event.conv ] if conv_name == '.' else bot.find_conversations(conv_name) kicked_chat_ids = get_unique_users(bot, args) for c in convs: new_chat_ids = { u for u in bot.find_users('', conv=c) if u.id_.chat_id not in set(kicked_chat_ids) } invitee_ids = [ InviteeID(gaia_id=u.id_.gaia_id, fallback_name=u.full_name) for u in new_chat_ids ] # Create new conversation 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=c.name, invitee_id=invitee_ids) res = yield from bot._client.create_conversation(request) conv_id = res.conversation.conversation_id.id bot._conv_list.add_conversation(res.conversation) conv = bot._conv_list.get(conv_id) yield from conv.rename(c.name) yield from conv.send_message( text_to_segments(( '**Welcome!**\n' 'This is the new refreshed conversation. Old conversation has been ' 'terminated, but you are one of the lucky ones who survived cleansing! ' 'If you are still in old conversation, please leave it.'))) # Destroy old one and leave it yield from c.rename(('[TERMINATED] {}').format(c.name)) yield from c.send_message( text_to_segments(( '**!!! WARNING !!!**\n' 'This conversation has been terminated! Please leave immediately!' ))) yield from c.leave()
def conv_list(bot, event, conv_name='', *args): """List all conversations where bot is wreaking havoc Usage: /bot conv_list [conversation_name] Legend: c ... commands, f ... forwarding, a ... autoreplies""" conv_name = strip_quotes(conv_name) convs = bot.list_conversations() if not conv_name else bot.find_conversations(conv_name) segments = [hangups.ChatMessageSegment(_('Active conversations:'), is_bold=True), hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)] for c in convs: s = '{} [c: {:d}, f: {:d}, a: {:d}]'.format(get_conv_name(c, truncate=True), bot.get_config_suboption(c.id_, 'commands_enabled'), bot.get_config_suboption(c.id_, 'forwarding_enabled'), bot.get_config_suboption(c.id_, 'autoreplies_enabled')) segments.append(hangups.ChatMessageSegment(s)) segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)) bot.send_message_segments(event.conv, segments)
def user_find(bot, event, user_name='', *args): """Find users known to bot by their name Usage: /bot users_find [user_name]""" user_name = strip_quotes(user_name) segments = [hangups.ChatMessageSegment(_('Search results for user name "{}":').format(user_name), is_bold=True), hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)] for u in bot.find_users(user_name): link = 'https://plus.google.com/u/0/{}/about'.format(u.id_.chat_id) segments.append(hangups.ChatMessageSegment(u.full_name, hangups.SegmentType.LINK, link_target=link)) if u.emails: segments.append(hangups.ChatMessageSegment(' (')) segments.append(hangups.ChatMessageSegment(u.emails[0], hangups.SegmentType.LINK, link_target='mailto:{}'.format(u.emails[0]))) segments.append(hangups.ChatMessageSegment(')')) segments.append(hangups.ChatMessageSegment(' ... {}'.format(u.id_.chat_id))) segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)) bot.send_message_segments(event.conv, segments)
def conv_list(bot, event, conv_name='', *args): """List all conversations where bot is wreaking havoc Usage: /bot conv_list [conversation_name] Legend: c ... commands, f ... forwarding, a ... autoreplies""" conv_name = strip_quotes(conv_name) convs = bot.list_conversations( ) if not conv_name else bot.find_conversations(conv_name) convs_text = [] for c in convs: s = '{} [c: {:d}, f: {:d}, a: {:d}]'.format( get_conv_name(c, truncate=True), bot.get_config_suboption(c.id_, 'commands_enabled'), bot.get_config_suboption(c.id_, 'forwarding_enabled'), bot.get_config_suboption(c.id_, 'autoreplies_enabled')) convs_text.append(s) text = _('**Active conversations:**\n' '{}').format('\n'.join(convs_text)) yield from event.conv.send_message(text_to_segments(text))
def conv_refresh(bot, event, conv_name, *args): """Create new conversation with same users as in old one except kicked users (use . for current conversation) Usage: /bot conv_refresh conversation_name [kicked_user_name_1] [kicked_user_name_2] [...]""" conv_name = strip_quotes(conv_name) convs = [event.conv] if conv_name == '.' else bot.find_conversations(conv_name) kicked_chat_ids = get_unique_users(bot, args) for c in convs: new_chat_ids = {u for u in bot.find_users('', conv=c) if u.id_.chat_id not in set(kicked_chat_ids)} invitee_ids = [InviteeID( gaia_id=u.id_.gaia_id, fallback_name=u.full_name ) for u in new_chat_ids] # Create new conversation 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=c.name, invitee_id=invitee_ids ) res = yield from bot._client.create_conversation(request) conv_id = res.conversation.conversation_id.id bot._conv_list.add_conversation(res.conversation) conv = bot._conv_list.get(conv_id) yield from conv.rename(c.name) yield from conv.send_message( text_to_segments(('**Welcome!**\n' 'This is the new refreshed conversation. Old conversation has been ' 'terminated, but you are one of the lucky ones who survived cleansing! ' 'If you are still in old conversation, please leave it.')) ) # Destroy old one and leave it yield from c.rename(('[TERMINATED] {}').format(c.name)) yield from c.send_message( text_to_segments(('**!!! WARNING !!!**\n' 'This conversation has been terminated! Please leave immediately!')) ) yield from c.leave()
def conv_list(bot, event, conv_name='', *args): """List all conversations where bot is wreaking havoc Usage: /bot conv_list [conversation_name] Legend: c ... commands, f ... forwarding, a ... autoreplies""" conv_name = strip_quotes(conv_name) convs = bot.list_conversations() if not conv_name else bot.find_conversations(conv_name) convs_text = [] for c in convs: s = '{} [c: {:d}, f: {:d}, a: {:d}]'.format( get_conv_name(c, truncate=True), bot.get_config_suboption(c.id_, 'commands_enabled'), bot.get_config_suboption(c.id_, 'forwarding_enabled'), bot.get_config_suboption(c.id_, 'autoreplies_enabled') ) convs_text.append(s) text = _('**Active conversations:**\n' '{}').format('\n'.join(convs_text)) yield from event.conv.send_message(text_to_segments(text))
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)
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!')))
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!')))
def dado(bot, event, caras, *args): """Lanza un dado, es posible definir el numero de caras del dado\n Uso: <bot> dado [numero de caras]""" text = 'Se lanzo un dado de {} caras\n El resultado fue: '.format( strip_quotes(caras)) + str(randint(1, int(caras))) yield from event.conv.send_message(text_to_segments(text))
def get_unique_users(bot, user_list): """Return list of unique chat_ids from list of user names""" users = itertools.chain.from_iterable(bot.find_users(strip_quotes(u)) for u in user_list) unique_users = list({u.id_.chat_id for u in users}) return unique_users
def multi(bot, event, n1, n2, *args): """Multiplica 2 numeros\n Uso: bot multi [numero1] [numero2]""" text = str(int(strip_quotes(n1)) * int(strip_quotes(n2))) yield from event.conv.send_message(text_to_segments(text))
def div(bot, event, n1, n2, *args): """Divide 2 numeros\n Uso: bot div [numero1] [numero2]""" text = str(int(strip_quotes(n1)) / int(strip_quotes(n2))) yield from event.conv.send_message(text_to_segments(text))
def raiz(bot, event, n1, *args): """Raiz Cuadrada\n Uso: bot raiz [numero1] """ num = float(strip_quotes(n1)) num = sqrt(num) text = str(num) yield from event.conv.send_message(text_to_segments(text))
def get_unique_user_objects(bot, user_list): """Return list of unique user objects from list of user names""" return itertools.chain.from_iterable(bot.find_users(strip_quotes(u)) for u in user_list)
def get_unique_users(bot, user_list): """Return list of unique chat_ids from list of user names""" users = itertools.chain.from_iterable( bot.find_users(strip_quotes(u)) for u in user_list) unique_users = list({u.id_.chat_id for u in users}) return unique_users
def resta(bot, event, n1, n2, *args): """Resta 2 numeros\n Uso: bot resta [numero1] [numero2]""" text = str(int(strip_quotes(n1)) - int(strip_quotes(n2))) yield from event.conv.send_message(text_to_segments(text))
def get_unique_user_objects(bot, user_list): """Return list of unique user objects from list of user names""" return itertools.chain.from_iterable( bot.find_users(strip_quotes(u)) for u in user_list)