Пример #1
0
    async def _get_data(self, ctx: Context):
        """DM a `json` file with all your data.

        You can request data once every 6 hours.
        """

        data = await self.config.user(ctx.author).all()

        data_json = json.dumps(data)

        file = text_to_file(
            data_json,
            filename=f"{ctx.author.name.lower()}_brawlcord_data.json")

        try:
            await ctx.author.send(file=file)
        except discord.Forbidden:
            await ctx.send("Unable to DM you.")

        await ctx.send("Sent you the file!")
Пример #2
0
 async def _list(self, ctx: commands.Context):
     """
     Génère les listes de participants à partir du rôle défini.
     """
     guild = ctx.guild
     try:
         role = await self.get_participant_role(guild)
     except UserInputError as e:
         await ctx.send(e.args[0])
         return
     async with ctx.typing():
         text = "Liste des membres avec le rôle participant:\n\n"
         for member in role.members:
             text += str(member) + "\n"
         text += f"\nNombre de participants : {len(role.members)}"
         file = text_to_file(text, filename="participants.txt")
         await ctx.send(
             f"Liste des {len(role.members)} membres participants.",
             file=file,
         )
Пример #3
0
    async def uptimeexport(self, ctx: commands.Context):
        """
        Export my uptime data to CSV

        The numbers represent uptime, so 86400 means 100% for that day (86400 seconds in 1 day).

        Everything is in UTC.

        Connected is the bot being connected to Discord.

        Cog loaded is the cog being loaded but not necessarily connected to Discord.

        Therefore, connected should always be equal to or lower than cog loaded.
        """
        df = pandas.concat([self.connected_cache, self.cog_loaded_cache],
                           axis=1)
        data = df.to_csv(index_label="Date",
                         header=["Connected", "Cog loaded"])
        await ctx.send("Here is your file.",
                       file=text_to_file(str(data), "betteruptime.csv"))
Пример #4
0
async def send_output(ctx: commands.Context, text: str, changed_input: bool):
    """Send output as a codeblock or file, depending on file limits. Handles no attachment perm."""
    if changed_input:
        extra = (
            "You inputted a Python dictionary. **Python dictionaries are not compatible with the "
            "JSON specification.** I've tried to change your data to make it compatible but I "
            "might have accidentally edited some of your data, so don't rely on this output.\n\n"
        )
    else:
        extra = ""

    if (len(text) + len(extra)) < 1980 and text.count("\n") < 20:  # limit long messages
        await ctx.send(extra + box(text, lang="json"))
    else:
        if ctx.guild and not ctx.channel.permissions_for(ctx.me).attach_files:  # type:ignore
            return await ctx.send(
                f"{extra}The output is big and I don't have permission to attach files. "
                "You could try again in my DMs."
            )

        file = text_to_file(text, "output.json")
        await ctx.send(f"{extra}The output is big, so I've attached it as a file.", file=file)
Пример #5
0
 async def mh_q_getasset(self, ctx, game_id, asset):
     """Get a match asset by game_id and asset name"""
     await ctx.send(file=text_to_file(
         (await self.api.get_asset(game_id, asset)).decode('utf-8'),  # TODO: Send PR to red to allow bytes
         filename=asset + '.json'))
Пример #6
0
 async def raw_bulk_message_deleted(self, payload: discord.RawBulkMessageDeleteEvent):
     # sourcery skip: comprehension-to-generator
     if not payload.guild_id:
         return
     if await self.bot.cog_disabled_in_guild_raw(self.qualified_name, payload.guild_id):
         return
     guild = self.bot.get_guild(payload.guild_id)
     channel = self.bot.get_channel(payload.channel_id)
     logchannel = guild.get_channel(await self.config.guild(guild).bulk_delete_channel())
     if not logchannel:
         return
     if (
         channel.category
         and channel.category.id in await self.config.guild(guild).ignored_categories()
     ):
         return
     if any(
         [
             not await self.config.guild(guild).deletion(),
             channel.id in await self.config.guild(guild).ignored_channels(),
             channel.nsfw and not logchannel.nsfw,
         ]
     ):
         return
     await set_contextual_locales_from_guild(self.bot, guild)
     save_bulk = await self.config.guild(guild).save_bulk()
     messages_dump = None
     if payload.cached_messages and save_bulk:
         n = "\n"
         messages_dump = chat.text_to_file(
             "\n\n".join(
                 [
                     f"[{m.id}]\n"
                     f"[Author]:     {m.author}\n"
                     f"[Channel]:    {m.channel.name} ({m.channel.id})\n"
                     f"[Created at]: {m.created_at}\n"
                     f"[Content]:\n"
                     f"{m.system_content}\n"
                     f"[Embeds]:\n"
                     f"{n.join([pformat(e.to_dict()) for e in m.embeds])}"
                     async for m in AsyncIter(payload.cached_messages)
                     if m.guild.id == guild.id
                 ]
             ),
             filename=f"{guild.id}.txt",
         )
     embed = discord.Embed(
         title=_("Multiple messages deleted"),
         description=_("{} messages removed").format(len(payload.message_ids))
         + (
             "\n" + _("{} messages saved to file above").format(len(payload.cached_messages))
             if payload.cached_messages and save_bulk
             else ""
         ),
         timestamp=datetime.now(timezone.utc),
         color=await self.bot.get_embed_colour(channel),
     )
     embed.add_field(name=_("Channel"), value=channel.mention)
     try:
         await logchannel.send(embed=embed, file=messages_dump)
     except discord.Forbidden:
         pass