Пример #1
0
    async def _chat(self, channel, server, message):
        # Check if we're suppressing @here and @everyone mentions

        message = DisplayName.clean_message(message,
                                            bot=self.bot,
                                            server=server)

        if self.settings.getServerStat(server, "SuppressMentions"):
            suppress = True
        else:
            suppress = False
        if message == None:
            return
        if not self.canChat(server):
            return
        await channel.trigger_typing()

        msg = self.chatBot.respond(message)

        if not msg:
            return
        # Check for suppress
        if suppress:
            msg = Nullify.clean(msg)
        await channel.send(msg)
Пример #2
0
	async def _chat(self, ctx, message):
		# Check if we're suppressing @here and @everyone mentions
		message = DisplayName.clean_message(message, bot=self.bot, server=ctx.guild)
		if message == None:
			return
		if not self.canChat(ctx.guild):
			return
		await ctx.trigger_typing()

		msg = self.chatBot.respond(message)
		msg = msg if msg else "I don't know what to say..."
		await ctx.send(msg)
Пример #3
0
    async def clippy(self, ctx, *,text: str = ""):
        """I *know* you wanted some help with something - what was it?"""
        image = Image.open('images/clippy.png')
        image_size = image.size
        image_height = image.size[1]
        image_width = image.size[0]
        draw = ImageDraw.Draw(image)

        text = DisplayName.clean_message(text, bot=self.bot, server=ctx.guild)
        # Remove any non-ascii chars
        text = ''.join([i for i in text if ord(i) < 128])

        clippy_errors = [
            "I guess I couldn't print that... whatever it was.",
            "It looks like you're trying to break things!  Maybe I can help.",
            "Whoops, I guess I wasn't coded to understand that.",
            "After filtering your input, I've come up with... well... nothing.",
            "Nope.",
            "y u du dis to clippy :("
        ]

        if not len(text):
            text = random.choice(clippy_errors)

        for xs in range(30, 2, -1):
            font = ImageFont.truetype('fonts/comic.ttf', size=xs)
            #340 is the width we want to set the image width to
            lines = self.text_wrap(text, font, 340)
            line_height = font.getsize('hg')[1]
            (x, y) = (25, 20)
            color = 'rgb(0, 0, 0)' # black color
            text_size = draw.textsize(text, font=font)

            for line in lines:
                text_size = draw.textsize(line, font=font)
                image_x = (image_width /2 ) - (text_size[0]/2)
                draw.text((image_x, y), line, fill=color, font=font)
                y = y + line_height
            if y < 182: # Check if the text overlaps. 182 was found by trial and error.
                image = Image.open('images/clippy.png')
                draw = ImageDraw.Draw(image)
                (x, y) = (25, 20)
                for line in lines:
                    text_size = draw.textsize(line, font=font)
                    image_x = (image_width /2 ) - (text_size[0]/2)
                    draw.text((image_x, y), line, fill=color, font=font)
                    y = y + line_height
                image.save('images/clippynow.png')
                await ctx.send(file=discord.File(fp='images/clippynow.png'))

                # Remove the png
                os.remove("images/clippynow.png")
                break
Пример #4
0
    async def _ring(self, caller, receiver, hidden, dial_hide):
        # This should be called when he have a valid caller, receiver, and no one is busy
        receiver_chan = self._gettelechannel(receiver)
        caller_chan = self._gettelechannel(caller)

        if receiver_chan == None or caller_chan == None:
            # No dice
            return

        # Add both to the call list
        self.switchboard.append({
            "Members": [caller, receiver],
            "Hidden": hidden,
            "Connected": False
        })
        our_call = self.switchboard[len(self.switchboard) - 1]

        # Let the caller know we're dialing
        msg = ":telephone: Dialing... "
        teleNum = self.settings.getServerStat(receiver, "TeleNumber")
        msg_add = []
        if hidden:
            msg_add.append("*67 ")
        if dial_hide:
            msg_add.append("###-")
            msg_add.append("####")
        else:
            msg_add.append(teleNum[:3] + "-")
            msg_add.append(teleNum[3:])

        # Send dialing
        message = await caller_chan.send(msg)
        # Dialing edits
        for i in msg_add:
            msg += i
            await message.edit(content=msg)
            await asyncio.sleep(0.5)

        # Here - we should have "dialed"
        # Send a message to the other channel that there's a call incoming
        # Save last call
        self.settings.setServerStat(
            receiver, "LastCall",
            self.settings.getServerStat(caller, "TeleNumber"))
        if hidden:
            caller_number = "UNKNOWN CALLER"
            self.settings.setServerStat(receiver, "LastCallHidden", True)
        else:
            self.settings.setServerStat(receiver, "LastCallHidden", False)
            caller_number = self.settings.getServerStat(caller, "TeleNumber")
            caller_number = caller_number[:3] + "-" + caller_number[3:]
        await receiver_chan.send(
            ":telephone: Incoming call from: *{}*\nType *pickup* to answer.".
            format(caller_number))

        # Ring for 30 seconds - then report no answer
        # Setup the check
        def check(ctx, msg):
            # This now catches the message and the context
            # print(ctx)
            if msg.author.bot:
                return False
            m_cont = msg.content.lower()
            if msg.channel == receiver_chan and m_cont == "pickup":
                return True
            if msg.channel == caller_chan and m_cont == "hangup":
                return True
            return False

        # Wait for a response
        try:
            talk = await self.bot.wait_for('message_context',
                                           check=check,
                                           timeout=30)
        except Exception:
            talk = None
        if talk:
            talk = talk[1]

        if talk == None:
            # No answer - hangup
            self._hangup(caller)
            await caller_chan.send(":telephone: No answer...")
            await receiver_chan.send(":telephone: Ringing stops.")
            return
        elif talk.content.lower() == "hangup":
            # You hung up the call
            self._hangup(caller)
            await caller_chan.send(":telephone: You have hung up.")
            await receiver_chan.send(":telephone: Ringing stops.")
            return

        # Connect the call:
        our_call["Connected"] = True
        # They answered!
        await caller_chan.send(
            ":telephone_receiver: Connected.\nType *hangup* to end the call.")
        await receiver_chan.send(
            ":telephone_receiver: Connected.\nType *hangup* to end the call.")
        # Wait on the call
        while True:
            # Setup the check
            def check_in_call(msg):
                if msg.author.bot:
                    return False
                if msg.channel == receiver_chan or msg.channel == caller_chan:
                    return True
                return False

            try:
                # 1 minute timeout
                talk = await self.bot.wait_for('message',
                                               check=check_in_call,
                                               timeout=60)
            except Exception:
                talk = None
            if talk == None:
                # Timed out
                self._hangup(caller)
                self._hangup(receiver)
                await caller_chan.send(":telephone: Disconnected.")
                await receiver_chan.send(":telephone: Disconnected.")
                return
            elif talk.content.lower() == "hangup":
                # One side hung up
                self._hangup(caller)
                self._hangup(receiver)
                if talk.channel == caller_chan:
                    # The caller disconnected
                    await receiver_chan.send(
                        ":telephone: The other phone was hung up.")
                    await caller_chan.send(":telephone: You have hung up.")
                else:
                    # The receiver disconnected
                    await caller_chan.send(
                        ":telephone: The other phone was hung up.")
                    await receiver_chan.send(":telephone: You have hung up.")
                return
            else:
                talk_msg = talk.content  # Nullify.clean(talk.content)
                # Let's make sure we strip links out - and nullify discord.gg links to patch a spam loophole
                # Create a set of all matches (to avoid duplicates in case of spam)
                if self.settings.getServerStat(
                        receiver if talk.channel == caller_chan else caller,
                        "TeleBlockLinks", True):
                    # Remove links only if the target channel chooses to
                    matches = [
                        x.group(0) for x in re.finditer(self.regex, talk_msg)
                    ]
                    dmatches = [
                        x.group(0) for x in re.finditer(self.dregex, talk_msg)
                    ]
                    matches.extend(dmatches)
                    matches = OrderedDict.fromkeys(
                        matches)  # Use an OrderedDict to avoid duplicates
                    # Now we iterate that list and replace all links with `link removed`
                    for x in matches:
                        talk_msg = talk_msg.replace(x, "`link removed`")
                # Clean out mentions from the message
                talk_msg = DisplayName.clean_message(talk_msg,
                                                     bot=self.bot,
                                                     server=talk.guild)
                # Must be conversation
                if talk.channel == caller_chan:
                    # Coming from the talking channel
                    if hidden:
                        await receiver_chan.send(":telephone_receiver: " +
                                                 talk_msg)
                    else:
                        user = Nullify.clean(
                            DisplayName.name(talk.author)
                        ).replace(
                            "`", ""
                        )  # Remove @here and @everyone mentions in username
                        await receiver_chan.send(
                            ":telephone_receiver: `{}`: {}".format(
                                user, talk_msg))
                else:
                    user = Nullify.clean(DisplayName.name(
                        talk.author)).replace(
                            "`", ""
                        )  # Remove @here and @everyone mentions in username
                    await caller_chan.send(
                        ":telephone_receiver: `{}`: {}".format(user, talk_msg))