Beispiel #1
0
        public async Task <DiscordCommandResult> AddTagAsync(
            [Name("Tag Name"), Description("The tag name to create")] string tagName,
            [Description("The content of the new tag"), Remainder] string content)
        {
            if (await _tagService.RetrieveTagAsync(tagName, Context.GuildId) is not null)
            {
                return(Response("It seems a tag with this name already exists."));
            }
            if (!IsTagNameValid(tagName))
            {
                return(Response($"The tag name \"{tagName}\" is forbidden, please choose another name."));
            }
            if (content.Length > 2000)
            {
                return(Response("A tag's content can't be longer than 200 characters long."));
            }

            var tag = new Tag
            {
                GuildId   = Context.GuildId,
                OwnerId   = Context.Message.Author.Id,
                Name      = tagName,
                Content   = content,
                CreatedAt = DateTimeOffset.UtcNow
            };
            await _tagService.AddTagAsync(tag);

            return(Response($"I have successfully added {tagName}."));
        }