示例#1
0
    async def on_guild_member_remove(self, member: interactions.GuildMember):
        embed = interactions.Embed(
            title="User left",
            color=0xED4245,
            thumbnail=interactions.EmbedImageStruct(url=member.user.avatar_url, height=256, width=256)._json,
            author=interactions.EmbedAuthor(
                name=f"{member.user.username}#{member.user.discriminator}",
                icon_url=member.user.avatar_url,
            ),
            fields=[
                interactions.EmbedField(name="ID", value=str(member.user.id)),
                interactions.EmbedField(
                    name="Timestamps",
                    value="\n".join(
                        [
                            f"Joined: <t:{round(member.joined_at.timestamp())}:R>.",
                            f"Created: <t:{round(member.id.timestamp.timestamp())}:R>.",
                        ]
                    ),
                ),
            ]
        )
        _channel: dict = await self.bot._http.get_channel(src.const.METADATA["channels"]["mod-logs"])
        channel = interactions.Channel(**_channel, _client=self.bot._http)

        await channel.send(embeds=embed)
示例#2
0
async def add_role_menu(ctx: interactions.CommandContext):
    if str(ctx.author.id) == "242351388137488384":
        _channel: dict = await bot._http.get_channel(METADATA["channels"]["information"])
        _roles: list[str] = [
            role for role in METADATA["roles"] if role not in [
                "Changelog pings", "Helper", "Moderator", "External Changelog pings"
            ]
        ]

        channel = interactions.Channel(**_channel, _client=bot._http)
        role_menu = interactions.SelectMenu(
            options=[
                interactions.SelectOption(
                    label=lang,
                    value=lang,
                    emoji=interactions.Emoji(
                        id=None,
                        name=METADATA["roles"][lang]["emoji"],
                        animated=False,
                    )
                )
                for lang in _roles
            ],
            placeholder="Choose a language.",
            custom_id="language_role",
            max_values=1
        )
        await channel.send(components=role_menu)
        await ctx.send(":heavy_check_mark:", ephemeral=True)
示例#3
0
 async def get_channel(self, channel_id):
     """
 Get a discord channel given its id
 --
 input:
   channel_id: int
 """
     data = await self._http.get_channel(channel_id)
     return interactions.Channel(_client=self._http, **data)
示例#4
0
 async def __report_user(self, ctx: interactions.CommandContext,
                         reason: str):
     _channel: dict = await self.bot._http.get_channel(
         src.const.METADATA["channels"]["action-logs"])
     channel = interactions.Channel(**_channel, _client=self.bot._http)
     await channel.send(
         f"{ctx.author.mention} reported {self.reported_user.mention} for:\n```\n{reason}\n```"
     )
     await ctx.send(":heavy_check_mark: User reported.", ephemeral=True)
示例#5
0
    async def _untimeout_member(self, ctx: interactions.CommandContext, member: interactions.Member, reason: str = "N/A"):
        """Untimeouts a member in the server and logs into the database."""
        await ctx.defer(ephemeral=True)
        db = self._actions
        id = len(list(db.items())) + 1
        action = src.model.Action(
            id=id,
            type=src.model.ActionType.TIMEOUT,
            moderator=ctx.author,
            user=member.user,
            reason=reason
        )
        db.update({str(id): action._json})
        self.actions.find_one_and_update({"id": MOD_ID}, {"$set": {"actions": db}})
        await self.get_actions()
        embed = interactions.Embed(
            title="User untimed out",
            color=0xFEE75C,
            author=interactions.EmbedAuthor(
                name=f"{member.user.username}#{member.user.discriminator}",
                icon_url=member.user.avatar_url,
            ),
            fields=[
                interactions.EmbedField(
                    name="Moderator",
                    value=f"{ctx.author.mention} ({ctx.author.user.username}#{ctx.author.user.discriminator})",
                    inline=True,
                ),
                interactions.EmbedField(
                    name="Timestamps",
                    value="\n".join(
                        [
                            f"Joined: <t:{round(member.joined_at.timestamp())}:R>.",
                            f"Created: <t:{round(member.id.timestamp.timestamp())}:R>.",
                        ]
                    ),
                ),
                interactions.EmbedField(name="Reason", value="N/A" if reason is None else reason),
            ]
        )
        _channel: dict = await self.bot._http.get_channel(src.const.METADATA["channels"]["action-logs"])
        channel = interactions.Channel(**_channel, _client=self.bot._http)

        if member.communication_disabled_until is None:
            return await ctx.send(f":x: {member.mention} is not timed out.", ephemeral=True)

        await member.modify(guild_id=ctx.guild_id, communication_disabled_until=None)
        await channel.send(embeds=embed)
        await ctx.send(f":heavy_check_mark: {member.mention} has been untimed out.", ephemeral=True)
示例#6
0
    async def _kick_member(self, ctx: interactions.CommandContext, member: interactions.Member, reason: str = "N/A"):
        """Bans a member from the server and logs into the database."""
        await ctx.defer(ephemeral=True)
        db = self._actions
        id = len(list(db.items())) + 1
        action = src.model.Action(
            id=id,
            type=src.model.ActionType.KICK,
            moderator=ctx.author,
            user=member.user,
            reason=reason
        )
        db.update({str(id): action._json})
        self.actions.find_one_and_update({"id": MOD_ID}, {"$set": {"actions": db}})
        await self.get_actions()
        embed = interactions.Embed(
            title="User kicked",
            color=0xED4245,
            author=interactions.EmbedAuthor(
                name=f"{member.user.username}#{member.user.discriminator}",
                icon_url=member.user.avatar_url,
            ),
            fields=[
                interactions.EmbedField(
                    name="Moderator",
                    value=f"{ctx.author.mention} ({ctx.author.user.username}#{ctx.author.user.discriminator})",
                    inline=True,
                ),
                interactions.EmbedField(
                    name="Timestamps",
                    value="\n".join(
                        [
                            f"Joined: <t:{round(member.joined_at.timestamp())}:R>.",
                            f"Created: <t:{round(member.id.timestamp.timestamp())}:R>.",
                        ]
                    ),
                ),
                interactions.EmbedField(name="Reason", value=reason),
            ]
        )
        _channel: dict = await self.bot._http.get_channel(src.const.METADATA["channels"]["action-logs"])
        channel = interactions.Channel(**_channel, _client=self.bot._http)

        await member.kick(guild_id=src.const.METADATA["guild"], reason=reason)
        await channel.send(embeds=embed)
        await ctx.send(f":heavy_check_mark: {member.mention} has been kicked.", ephemeral=True)
示例#7
0
    async def on_message_delete(self, message: interactions.Message):
        embed = interactions.Embed(
            title="Message deleted",
            color=0xED4245,
            author=interactions.EmbedAuthor(
                name=f"{message.author.username}#{message.author.discriminator}",
                icon_url=message.author.avatar_url
            ),
            fields=[
                interactions.EmbedField(name="ID", value=str(message.author.id), inline=True),
                interactions.EmbedField(
                    name="Message",
                    value=message.content if message.content else "**Message could not be retrieved.**"
                ),
            ],
        )
        _channel: dict = await self.bot._http.get_channel(src.const.METADATA["channels"]["mod-logs"])
        channel = interactions.Channel(**_channel, _client=self.bot._http)

        await channel.send(embeds=embed)
示例#8
0
    async def _unban_member(self, ctx: interactions.CommandContext, id: int, reason: str = "N/A"):
        """Unbans a user from the server and logs into the database."""
        await ctx.defer(ephemeral=True)
        db = self._actions
        _id = len(list(db.items())) + 1
        _user: dict = await self.bot._http.get_user(id=id)
        user = interactions.User(**_user)
        action = src.model.Action(
            id=_id,
            type=src.model.ActionType.KICK,
            moderator=ctx.author,
            user=user,
            reason=reason
        )
        db.update({str(_id): action._json})
        self.actions.find_one_and_update({"id": MOD_ID}, {"$set": {"actions": db}})
        await self.get_actions()
        embed = interactions.Embed(
            title="User unbanned",
            color=0x57F287,
            author=interactions.EmbedAuthor(
                name=f"{user.username}#{user.discriminator}",
                icon_url=user.avatar_url,
            ),
            fields=[
                interactions.EmbedField(
                    name="Moderator",
                    value=f"{ctx.author.mention} ({ctx.author.user.username}#{ctx.author.user.discriminator})",
                    inline=True,
                ),
                interactions.EmbedField(name="Reason", value=reason),
            ]
        )
        _guild: dict = await self.bot._http.get_guild(src.const.METADATA["guild"])
        guild = interactions.Guild(**_guild, _client=self.bot._http)
        _channel: dict = await self.bot._http.get_channel(src.const.METADATA["channels"]["action-logs"])
        channel = interactions.Channel(**_channel, _client=self.bot._http)

        await guild.remove_ban(user_id=id, reason=reason)
        await channel.send(embeds=embed)
        await ctx.send(f":heavy_check_mark: {user.mention} has been unbanned.", ephemeral=True)
示例#9
0
    async def _help_thread_modal(
        self,
        ctx: interactions.CommandContext,
        thread_name: str,
        content: str,
        extra_content: str | None = None,
    ):

        target: interactions.Message = self.targets.pop(int(ctx.author.id))

        target._json["content"] = content
        attachments = False
        if target._json["attachments"]:
            del target._json["attachments"]
            attachments = True

        _thread: dict = await self.bot._http.create_forum_thread(
            self=self.bot._http,
            auto_archive_duration=1440,
            name=thread_name,
            channel_id=src.const.METADATA["channels"]["help"],
            applied_tags=["996215708595794071"],
            message_payload=target._json,
            reason="Auto help thread creation"
        )

        ch = await interactions.get(self.bot, interactions.Channel, object_id=src.const.METADATA["channels"]["help"])
        _tags = ch._extras["available_tags"]
        _options: list[interactions.SelectOption] = [
            interactions.SelectOption(
                label=tag["name"],
                value=tag["id"],
                emoji=interactions.Emoji(
                    name=tag["emoji_name"],
                ) if tag["emoji_name"] else None
            ) for tag in _tags
        ]

        select = interactions.SelectMenu(
            custom_id="TAG_SELECTION",
            placeholder="Select the tags you want",
            options=_options,
            min_values=0,
            max_values=len(_options),
        )

        thread = interactions.Channel(**_thread, _client=self.bot._http)

        await thread.add_member(int(ctx.author.id))
        await thread.add_member(int(target.author.id))

        embed = None

        if extra_content:
            embed = interactions.Embed(
                title="Additional Information:",
                color=0xFEE75C,
                timestamp=target.timestamp,
                description=extra_content
            )
            embed.set_footer(text="Please create a thread in #help to ask questions!")

        button = interactions.Button(
            style=interactions.ButtonStyle.LINK, label="Original message", url=target.url
        )

        _ars = [interactions.ActionRow.new(button), interactions.ActionRow.new(select)]

        await thread.send(
            "This help thread was automatically generated. Read the message above for more information.",
            embeds=embed,
            components=_ars
        )

        if attachments:
            await thread.send(
                f"Hey {target.author.mention}! We detected an attachment on your message! Due to discord being buggy, "
                f"we could not automatically transfer it to this thread. Please re-upload it here!"
            )

        await ctx.send(
            f"Hey, {target.author.mention}! At this time, we only help with support-related questions in our help "
            f"channel. Please redirect to {thread.mention} in order to receive help."
        )
        await ctx.send(":white_check_mark: Thread created.", ephemeral=True)