Beispiel #1
0
    async def tag_info(self, ctx: core.Context, name: TagName()):
        _("""Displays tag information""")
        tag = await self.get_tag(name, ctx.guild, {"content": False})
        if not tag:
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        embed = discord.Embed(colour=self.colour, title=tag["name"])
        if tag["aliases"]:
            embed.add_field(
                name=_("Aliases"),
                value="\n".join([alias["alias"] for alias in tag["aliases"]]),
            )
        embed.add_field(
            name=_("Created at"),
            value=format_datetime(tag["created_at"], locale=ctx.locale),
        )
        embed.add_field(name=_("Uses"), value=str(tag["uses"]))
        try:
            member = ctx.guild.get_member(
                tag["owner_id"]) or await ctx.guild.fetch_member(
                    tag["owner_id"])
            embed.set_author(name=str(member), icon_url=member.avatar_url)
        except discord.HTTPException:
            embed.set_author(name=_("Owner not found"))
        await ctx.send(embed=embed)
Beispiel #2
0
    async def tag_edit(
            self,
            ctx: core.Context,
            name: TagName(),
            *,
            new_content: commands.clean_content(),
    ):
        _("""Edits content of your tag
        
        Be careful, the command completely replaces the content of the tag.
        You must enclose the name in double quotation marks if it consists of more than \
        one word.""")
        tag = await self.get_tag(name, ctx.guild, {"name": True})
        if not tag:
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        if not await self._bypass_check(ctx) and not await self.is_tag_owner(
                tag["name"], ctx.guild, ctx.author):
            return await ctx.inform(_("You are not the owner of this tag."))

        await ctx.db.tags.update_one({"name": tag["name"]},
                                     {"$set": {
                                         "content": new_content
                                     }})
        await ctx.inform(_("Tag content changed."))
Beispiel #3
0
    async def tag(self, ctx: core.Context, *, name: TagName() = None):
        _("""Returns the text with the specified tag
        
        If a tag with the specified name is not found, a search will be performed by \
        the names, aliases and contents of the tags.""")
        if not name:
            return await ctx.send_help()
        tag = await self.get_tag(name,
                                 ctx.guild, {"content": True},
                                 inc_uses=True)
        if tag:
            return await ctx.send(tag["content"])

        pages = menus.MenuPages(
            source=TagSource(
                self.search_tags(name, ctx.guild, ctx.locale, {"name": True}),
                _("Did you mean:"),
                ctx.colour,
                per_page=20,
            ),
            clear_reactions_after=True,
        )
        try:
            await pages.start(ctx)
        except IndexError:
            await ctx.inform(_("Tag `{0}` not found.").format(name))
Beispiel #4
0
    async def tag_raw(self, ctx: core.Context, *, name: TagName()):
        _("""Returns the raw content with the specified tag
        
        The command can be useful when editing tags to preserve formatting.""")
        tag = await self.get_tag(name,
                                 ctx.guild, {"content": True},
                                 inc_uses=True)
        if not tag:
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        return await ctx.send(discord.utils.escape_markdown(tag["content"]))
Beispiel #5
0
    async def tag_alias(self, ctx: core.Context, name: TagName(), *,
                        alias: TagName()):
        _("""Creates new tag alias
        
        This alias will belong to you and will be available only in this guild.
        Removing the original tag will also remove the alias.
        You must enclose the name in double quotation marks if it consists of more than \
        one word.""")
        if await self.is_tag_exists(alias, ctx.guild):
            return await ctx.inform(
                _("Tag `{0}` already exists.").format(alias))

        if not await self.is_tag_exists(name, ctx.guild):
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        tag = TagAlias(created_at=ctx.message.created_at,
                       owner_id=ctx.author.id,
                       alias=alias).dict()
        await ctx.db.tags.update_one(
            {
                "guild_id":
                ctx.guild.id,
                "$or": [{
                    "name": name
                }, {
                    "aliases": {
                        "$elemMatch": {
                            "alias": name
                        }
                    }
                }],
            },
            {"$addToSet": {
                "aliases": tag
            }},
        )
        await ctx.inform(
            _("Tag alias `{alias}` that points to `{tag}` successfully created."
              ).format(alias=alias, tag=name))
Beispiel #6
0
    async def tag_pass(self, ctx: core.Context, member: discord.Member, *,
                       name: TagName()):
        _("""Passes your tag to another member
        
        Example:
        - tag pass @Member example tag""")
        tag = await self.get_tag(name, ctx.guild, {"name": True})
        if not tag:
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        if not await self.is_tag_owner(tag["name"], ctx.guild, ctx.author):
            return await ctx.inform(_("You are not the owner of this tag."))

        await ctx.db.tags.update_one({"name": tag["name"]},
                                     {"$set": {
                                         "owner_id": member.id
                                     }})
        await ctx.inform(_("Tag owner changed."))
Beispiel #7
0
    async def tag_add(self, ctx: core.Context, name: TagName(), *,
                      content: commands.clean_content()):
        _("""Creates new tag

        This tag will belong to you and will be available only in this guild.
        You must enclose the name in double quotation marks if it consists of more than \
        one word.""")
        if await self.is_tag_exists(name, ctx.guild):
            return await ctx.inform(
                _("Tag `{0}` already exists.").format(name))

        tag = Tag(
            created_at=ctx.message.created_at,
            owner_id=ctx.author.id,
            name=name,
            content=content,
            guild_id=ctx.guild.id,
            language=ctx.locale[:2],
        ).dict()
        await ctx.db.tags.insert_one(tag)
        await ctx.inform(_("Tag `{0}` successfully created.").format(name))
Beispiel #8
0
    async def tag_delete(self, ctx: core.Context, *, name: TagName()):
        _("""Deletes your tag or alias""")
        is_alias = await self.is_alias_exists(name, ctx.guild)
        if not await self.is_tag_exists(name, ctx.guild) and not is_alias:
            return await ctx.inform(_("Tag `{0}` not found.").format(name))

        bypass_check = await self._bypass_check(ctx)
        if is_alias:
            if bypass_check or await self.is_alias_owner(
                    name, ctx.guild, ctx.author):
                await ctx.db.tags.update_one(
                    {
                        "guild_id": ctx.guild.id,
                        "aliases": {
                            "$elemMatch": {
                                "alias": name
                            }
                        },
                    },
                    {"$pull": {
                        "aliases": {
                            "alias": name
                        }
                    }},
                )
                await ctx.inform(
                    _("Tag alias `{0}` successfully deleted.").format(name))
            else:
                await ctx.inform(_("You are not the owner of this tag alias."))
        else:
            if bypass_check or await self.is_tag_owner(name, ctx.guild,
                                                       ctx.author):
                await ctx.db.tags.delete_one({
                    "guild_id": ctx.guild.id,
                    "name": name
                })
                await ctx.inform(
                    _("Tag `{0}` successfully deleted.").format(name))
            else:
                await ctx.inform(_("You are not the owner of this tag."))