Beispiel #1
0
    async def respond(self, event, caller=None):
        if caller == 'h':
            incoming = re.match(
                '^{}\s+conv(\s.*)?.*$'.format(self.pearl.config['format']),
                hangups.ChatMessageEvent(event).text)
            conversation = self.hangouts.getConversation(event=event)

            channs = await self.pearl.getChannels()

            for sv, cList in channs.items():
                message = ""

                message += f"<b>{str(sv).upper()}</b>\n"

                for c in cList:
                    message += f"<b>{c.name}</b> - {c.id}\n"

                await self.hangouts.send(message.strip(), conversation)

        elif caller == 'd':
            incoming = re.match(
                '^{}\s+conv(\s.*)?.*$'.format(self.pearl.config['format']),
                event.content)
            if not incoming:
                return

            message = discord.Embed(color=int("ffdead", 16))

            chats = await self.hangouts.getGroupChats()

            for c in chats:
                message.add_field(name=c.name, value=c.id_, inline=False)

            await self.pearl.embed(message, event.channel)
Beispiel #2
0
    async def respond(self, event, caller=None):
        if caller == 'h':
            incoming = re.match(
                '^{}\s+bridge(\s.*)$'.format(self.pearl.config['format']),
                hangups.ChatMessageEvent(event).text)
            conversation = self.hangouts.getConversation(event=event)

            if not str(self.hangouts.getUser(
                    event=event).id_.gaia_id) in self.pearl.admins["h"]:
                await self.hangouts.send("Error: not an admin", conversation)
                return

            t = incoming.group(1)

            if t is None:
                message = self.usage + "where <chat_id> is the id of the chat you wish to bridge with. See /dh conv"
                await self.hangouts.send(message, conversation)
                return

            thing = str(t.strip())

            self.pearl.DH[thing] = conversation.id_
            self.pearl.HD[conversation.id_] = thing

            await self.hangouts.send(
                'Bridged to Discord channel ' + str(thing), conversation)

        if caller == 'd':
            incoming = re.match(
                '^{}\s+bridge(\s.*)$'.format(self.pearl.config['format']),
                event.content)

            if not incoming:
                return

            t = incoming.group(1)

            if t is None:
                message = self.usage + "where <chat_id> is the id of the chat you wish to bridge with. See /dh conv"
                await self.pearl.send(message, event.channel)
                return

            if not str(event.author.id) in self.pearl.admins["d"]:
                await self.pearl.send("Error: not an admin", event.channel)
                return

            thing = t.strip()

            self.pearl.DH[str(event.channel.id)] = thing
            self.pearl.HD[thing] = str(event.channel.id)

            await self.pearl.send('Bridged to Hangouts chat ' + str(thing),
                                  event.channel)

        self.pearl.save()
Beispiel #3
0
 async def state_update_listener(self, state_update):
     if self.is_message_event(state_update):
         event = state_update.event_notification.event
         cid = event.conversation_id.id
         if self.send_to.get(cid):
             uid = event.sender_id.gaia_id
             sender = self.users.get_user(hangups.user.UserID(uid, uid))
             if not sender.is_self:
                 message = Message(self.send_to[cid], sender.full_name,
                                   hangups.ChatMessageEvent(event).text)
                 self.transport.send_matrix(message)
Beispiel #4
0
def newMessageFilter(regex):
    pattern = re.compile(regex)
    return lambda event: bool(
        pattern.match(hangups.ChatMessageEvent(event).text))
Beispiel #5
0
 async def sendImage(self, event, conversation):
     image_file = open(
         "plugins/images/" + hangups.ChatMessageEvent(event).text[2:] +
         ".jpg", 'rb')
     await conversation.send_message([], image_file)
Beispiel #6
0
    async def respond(self, event, caller=None):
        if caller == 'h':
            incoming = re.match(
                '^{}\s+admin(\s.*)?.*$'.format(self.pearl.config['format']),
                hangups.ChatMessageEvent(event).text)
            conversation = self.hangouts.getConversation(event=event)

            ident = incoming.group(1)

            if ident is None:
                message = self.usage + "where <user> is either the gaia ID or name of the to-be Hangouts admin"
                await self.hangouts.send(message, conversation)
                return

            if not str(self.hangouts.getUser(
                    event=event).id_.gaia_id) in self.pearl.admins['h']:
                message = "Error: not an admin"
                await self.hangouts.send(message, conversation)
                return

            ident = ident.strip().lower()

            if ident.isnumeric():
                uid = ident
            else:
                matches = await self.hangouts.getContact(ident)

                if len(matches) != 1:
                    self.IDrespond(matches, conversation)
                    return

                uid = str(matches[0].id_.gaia_id)

            if not uid in self.pearl.admins['h']:
                self.pearl.admins['h'].append(uid)
                await self.hangouts.send("Added Hangouts admin with ID " + uid,
                                         conversation)
            else:
                await self.hangouts.send(
                    "User {} is already a Hangouts admin".format(uid),
                    conversation)

        else:
            incoming = re.match(
                '^{}\s+admin(\s.*)?.*$'.format(self.pearl.config['format']),
                event.content)
            if not incoming:
                return

            ident = incoming.group(1)

            if ident is None:
                message = self.usage + "where <user> is an @ mention or UID of the to-be Discord admin"
                await self.pearl.send(message, event.channel)
                return

            if not str(event.author.id) in self.pearl.admins['d']:
                message = "Error: not an admin"
                await self.pearl.send(message, event.channel)
                return

            ident = ident.strip().lower()

            if ident.isnumeric():
                uid = str(ident)
            else:
                uid = str(event.mentions[0].id)
                """
                    message = "Must mention to-be admin"
                    await self.pearl.send(message, event.channel)
                    return

                """
            if not uid in self.pearl.admins['d']:
                self.pearl.admins['d'].append(uid)
                await self.pearl.send(
                    "Added Discord admin with ID `" + uid + "`", event.channel)
            else:
                await self.pearl.send(
                    "User `{}` already a Discord admin".format(uid),
                    event.channel)

        self.pearl.saveAdmins()
Beispiel #7
0
 async def respond(self, event):
     message = self.getCases(hangups.ChatMessageEvent(event).text)
     conversation = self.hangouts.getConversation(event=event)
     await self.hangouts.send(message, conversation)
Beispiel #8
0
 def handle(self, update):
     event = update.event_notification.event
     if event.event_type == utils.EventType.EVENT_TYPE_REGULAR_CHAT_MESSAGE.value:
         message = hangups.ChatMessageEvent(event).text
         if self.pattern.match(message):
             self.execute(message, event)
Beispiel #9
0
    async def respond(self, event, caller=None):
        if caller == 'h':
            incoming = re.match(
                '^(?!{})\s*(.*)$'.format(self.pearl.config['format']),
                hangups.ChatMessageEvent(event).text)

            conversation = self.hangouts.getConversation(event=event)

            conv_id = conversation.id_

            if conv_id in self.pearl.HD.keys():
                toSend = "**{}:** {}".format(
                    self.hangouts.getUser(event=event).full_name,
                    incoming.group(1).strip())

                try:
                    channel = self.pearl.discordClient.get_channel(
                        int(self.pearl.HD[conv_id]))
                    assert channel != None
                except (AssertionError, ValueError):
                    self.pearl.HD.pop(conv_id, 1)
                    self.pearl.DH = {
                        k: v
                        for k, v in self.pearl.HD.items()
                        if str(v) != str(conv_id)
                    }

                    await self.hangouts.send(
                        "Error sending message, bridge has been deleted.",
                        conversation)

                    self.pearl.save()

                    return

                asyncio.run_coroutine_threadsafe(
                    self.pearl.send(toSend, channel),
                    self.pearl.discordClient.loop)

        elif caller == 'd':
            incoming = re.match(
                '^(?!{})\s*(.*)$'.format(self.pearl.config['format']),
                event.content)

            if not incoming:
                return

            conv_id = str(event.channel.id)

            if conv_id in self.pearl.DH.keys():
                toSend = "<b>{}:</b> {}".format(event.author.name,
                                                incoming.group(1).strip())

                try:
                    conversation = self.hangouts.getConversation(
                        cid=self.pearl.DH[conv_id])
                except KeyError:
                    self.pearl.DH.pop(conv_id, 1)
                    self.pearl.HD = {
                        k: v
                        for k, v in self.pearl.HD.items()
                        if str(v) != str(conv_id)
                    }

                    await self.pearl.send(
                        "Error sending message, bridge has been deleted.",
                        event.channel)

                    self.pearl.save()

                    return

                asyncio.run_coroutine_threadsafe(
                    self.hangouts.send(toSend, conversation), self.pearl.loop)