Пример #1
0
    async def _find_from_channel(self, channel):
        """
        Tries to find a thread from a channel channel topic,
        if channel topic doesnt exist for some reason, falls back to
        searching channel history for genesis embed and
        extracts user_id from that.
        """
        user_id = -1

        if channel.topic:
            user_id = match_user_id(channel.topic)

        if user_id == -1:
            return None

        if user_id in self.cache:
            return self.cache[user_id]

        try:
            recipient = self.bot.get_user(
                user_id) or await self.bot.fetch_user(user_id)
        except discord.NotFound:
            recipient = None

        if recipient is None:
            thread = Thread(self, user_id, channel)
        else:
            self.cache[user_id] = thread = Thread(self, recipient, channel)
        thread.ready = True

        return thread
Пример #2
0
    async def _find_from_channel(self, channel):
        """
        Tries to find a thread from a channel channel topic,
        if channel topic doesnt exist for some reason, falls back to
        searching channel history for genesis embed and
        extracts user_id from that.
        """
        user_id = -1

        if channel.topic:
            user_id = match_user_id(channel.topic)

        # BUG: When discord fails to create channel topic.
        # search through message history
        elif channel.topic is None:
            try:
                async for message in channel.history(limit=100):
                    if message.author != self.bot.user:
                        continue
                    if message.embeds:
                        embed = message.embeds[0]
                        if embed.footer.text:
                            user_id = match_user_id(embed.footer.text)
                            if user_id != -1:
                                break
            except discord.NotFound:
                # When the channel's deleted.
                pass

        if user_id != -1:
            if user_id in self.cache:
                return self.cache[user_id]

            recipient = self.bot.get_user(user_id)
            if recipient is None:
                self.cache[user_id] = thread = Thread(self, user_id, channel)
            else:
                self.cache[user_id] = thread = Thread(self, recipient, channel)
            thread.ready = True

            return thread
Пример #3
0
 async def unrole(self, ctx, role: discord.Role, member: discord.Member=None):
     """Remove a role from a member."""
     if member is None:
         member = ctx.guild.get_member(match_user_id(ctx.channel.topic))
         if member is None:
             raise commands.MissingRequiredArgument(SimpleNamespace(name="unrole"))
         
     if role.position > ctx.author.roles[-1].position:
         return await ctx.send("You do not have permissions to remove this role.")
     
     await member.remove_roles(role)
     await ctx.send(f"Successfully removed the role from {member.name}!")
Пример #4
0
    def _find_from_channel(self, channel):
        """
        Tries to find a thread from a channel channel topic,
        if channel topic doesnt exist for some reason, falls back to
        searching channel history for genesis embed and
        extracts user_id from that.
        """
        user_id = -1

        if channel.topic:
            # logger.info(
            #     f"Finding Thread from Channel, Encrypted Topic: {channel.topic}")
            try:
                encrypted_channel_id = int(channel.topic[9:])
            except ValueError:
                # logger.error(
                #     f"Thread: {channel} with topic {channel.topic} is invalid. Closing.")
                for user_id in self.cache:
                    user_channel = self.cache[user_id]
                    if channel == user_channel:
                        self.cache.pop(user_id)
                        break
                return None
            decrypted_channel_id = encrypt_decrypt_username(
                encrypted_channel_id)
            decrypted_channel_topic = f"User ID: {decrypted_channel_id}"
            logger.info(f"Decrypted Channel Topic: {decrypted_channel_topic}")
            user_id = match_user_id(decrypted_channel_topic)

        if user_id == -1:
            return None

        if user_id in self.cache:
            return self.cache[user_id]

        recipient = self.bot.get_user(user_id)
        if recipient is None:
            self.cache[user_id] = thread = Thread(self, user_id, channel)
        else:
            self.cache[user_id] = thread = Thread(self, recipient, channel)
        thread.ready = True

        return thread
Пример #5
0
 async def set_title(self, title) -> None:
     user_id = match_user_id(self.channel.topic)
     await self.channel.edit(topic=f"Title: {title}\nUser ID: {user_id}")