示例#1
0
 async def ginfo(self, ctx: AnsuraContext, guild_id: int):
     async with ctx.typing():
         if guild_id not in [g.id for g in self.bot.guilds]:
             await ctx.send("I'm not in a guild with that ID")
             return
         m: discord.User
         g: discord.Guild = self.bot.get_guild(guild_id)
         users, bots = 0, 0
         for m in g.members:
             if m.bot:
                 bots += 1
             else:
                 users += 1
         e = discord.Embed()
         e.title = g.name
         e.set_thumbnail(url=g.icon_url)
         e.description = g.description
         e.add_field(name="Total Members", value=g.member_count)
         e.add_field(name="Users/Bots", value=f"{users}/{bots}")
         e.add_field(name="Region", value=str(g.region))
         e.add_field(name="ID", value=str(g.id), inline=False)
         u: discord.User = g.owner
         e.add_field(name="Owner",
                     value=f"{u.name}#{u.discriminator} ({g.owner_id})",
                     inline=False)
     await ctx.send(embed=e)
示例#2
0
 async def guilds(self, ctx: AnsuraContext):
     g: discord.Guild
     m: discord.Message = await ctx.send("Building list...")
     s = """```"""
     async with ctx.typing():
         for g in self.bot.guilds:
             s += f"{g.id} - {g.name}\n"
     await m.edit(content=s + "```")
示例#3
0
    async def xchat(self, message: discord.Message):  # noqa c901
        channel: discord.TextChannel = message.channel
        if channel.id not in self.channels.values():
            return
        if message.type in (discord.MessageType.pins_add,
                            discord.MessageType.new_member):
            return
        if message.author.id in self.banned or message.guild.id in self.banned:
            try:
                await message.delete()
            except discord.errors.Forbidden:
                pass
            return
        time = self._cd.get_bucket(message).update_rate_limit()
        if time and message.author.id not in self.exempt:
            try:
                await message.delete()
            except discord.errors.Forbidden:
                pass
            await message.channel.send(
                f"{message.author.mention}, you're sending messages too fast! "
                f"Try again in {round(time)} seconds.",
                delete_after=30)
            return
        guild: discord.Guild = channel.guild
        author: discord.Member = message.author
        e = discord.Embed()
        dev = ""
        e.colour = self.colors[int(guild.id)]
        e.set_author(name=guild.name, icon_url=str(guild.icon_url))
        if self.bot.user.id in [791266463305957377, 804791983884992608]:
            g: discord.Guild = self.bot.get_guild(788661880343363625)
            m: discord.Member = g.get_member(author.id)
            if m and 788661880431312906 in [r.id for r in m.roles]:
                dev = " | "
                dev += "Developer" if author.id == 569362627935862784 else "Crosschat Moderator"
                e.colour = self.ansura_color
            elif m and 788661880343363632 in [r.id for r in m.roles]:
                dev = " | Aoi Contributor"
                e.colour = self.ansura_color
            elif m and 803034721595424798 in [r.id for r in m.roles]:
                dev = " | Ansura Contributor"
                e.colour = self.ansura_color
        user: discord.User = message.author
        e.description = AnsuraContext.escape(message.content, message)
        err_s = ""
        file = None
        reference: Optional[discord.MessageReference] = message.reference
        messages = None
        author_id = None
        content = None
        cache = {}
        found = False
        if reference:
            ref_id = reference.message_id
            # find message in xchat cache
            for i in self.messages:
                # guild_id = i[0]
                # channel_id = i[1]
                author_id = i[2]
                content = i[4]
                messages = i[3]

                for m in i[3]:
                    if m[1] == ref_id:
                        found = True
                        break
                if found:
                    break
        if messages:
            for m in messages:
                c: discord.TextChannel = self.bot.get_channel(m[0])
                if c:
                    cache[c.guild.id] = (c.id, m[1])

        if message.attachments:
            if self._is_image(message.attachments[0].filename):
                with open(f"attachments/{message.attachments[0].filename}",
                          "wb") as fp:
                    await message.attachments[0].save(fp)
                file = True
                e.set_image(
                    url=f"attachment://{message.attachments[0].filename}")
        else:
            file = False
        try:
            await message.delete()
        except discord.errors.Forbidden as err:
            if err.status == 403:
                err_s = " | Could not delete original message. Make sure I have manage messages in this channel."
        except discord.errors.NotFound:
            pass
        sent = []
        desc = e.description
        content = "\n".join(
            f"> {line}" for line in content.splitlines()) if content else None
        for k in self.channels.keys():
            c: discord.TextChannel = self.bot.get_channel(self.channels[k])
            if cache and k in cache:
                e.description = f"Reply to [{self.bot.get_user(author_id).name}#" \
                                f"{str(self.bot.get_user(author_id).discriminator)[:2]}xx]" \
                                f"(https://discord.com/channels/{k}/{c.id}/{cache[k][1]})\n{content}\n\n" + desc
            else:
                e.description = desc
            if k == message.guild.id:
                e.set_footer(text=user.name + "#" +
                             str(user.discriminator)[0:2] + "xx" + err_s + dev,
                             icon_url=user.avatar_url)
            else:
                e.set_footer(text=user.name + "#" +
                             str(user.discriminator)[0:2] + "xx" + dev,
                             icon_url=user.avatar_url)
            if c is not None:
                if file:
                    with open(f"attachments/{message.attachments[0].filename}",
                              "rb") as fp:
                        msg = await c.send(
                            embed=e,
                            file=discord.File(fp,
                                              message.attachments[0].filename))
                else:
                    msg = await c.send(embed=e)
                sent.append((c.id, msg.id))
        self.messages.append([
            message.guild.id, message.channel.id, message.author.id, sent,
            message.content
        ])
        if len(self.messages) > 250:
            del self.messages[0]
        if file:
            os.remove(f"attachments/{message.attachments[0].filename}")