def tag(self, ctx, name: clean_content, *, value: clean_content=None):
"""
Tag related operations.
If you provide a value, a tag is created if it doesn't exist. If it
does exist, it will be overwritten provided that you can touch that
tag.
If you don't provide a value, the tag's contents are sent.
You may only touch a tag if any of the following conditions are met:
You have the "Manage Server" permission,
you are the owner of the server.
you have created that tag.
you are a Dogbot Moderator.
"""
# a value was provided, create or overwrite a tag
if value:
tag = await self.get_tag(ctx, name)
# tag already exists, check if we can touch it
if tag and not self.can_touch_tag(ctx, tag):
# cannot overwrite
return await ctx.send(
"\N{NO PEDESTRIANS} You can't overwrite that tag's contents."
)
# set a tag
if tag:
await self.edit_tag(name, value)
else:
await self.create_tag(ctx, name, value)
# we good
await ctx.ok('\N{MEMO}' if tag else '\N{DELIVERY TRUCK}')
return
# see the value of a tag
tag = await self.get_tag(ctx, name)
if tag:
# send the tag's value
await ctx.send(tag.value)
# increment usage count
update = """
UPDATE tags
SET uses = uses + 1
WHERE name = $1 AND guild_id = $2
"""
await self.bot.pgpool.execute(update, name, ctx.guild.id)
else:
await ctx.send('Tag not found.')
评论列表
文章目录