Ejemplo n.º 1
0
        private async Task HelpAsync(string query, HelpDataType type)
        {
            var sanitizedQuery = FormatUtilities.SanitizeAllMentions(query);

            if (TryGetEmbed(query, type, out var embed))
            {
                await ReplyAsync($"Results for \"{sanitizedQuery}\":", embed : embed.Build());

                return;
            }

            await ReplyAsync($"Sorry, I couldn't find help related to \"{sanitizedQuery}\".");
        }
Ejemplo n.º 2
0
        public async Task HelpAsync(
            [Remainder]
            [Summary("The module name or related query to use to search for the help module.")]
            string query)
        {
            var foundModule    = _commandHelpService.GetModuleHelpData(query);
            var sanitizedQuery = FormatUtilities.SanitizeAllMentions(query);

            if (foundModule is null)
            {
                await ReplyAsync($"Sorry, I couldn't find help related to \"{sanitizedQuery}\".");

                return;
            }

            var embed = GetEmbedForModule(foundModule);

            await ReplyAsync($"Results for \"{sanitizedQuery}\":", embed : embed.Build());
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public async Task UseTagAsync(ulong guildId, ulong channelId, string name)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.UseTag);

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The tag name cannot be blank or whitespace.", nameof(name));
            }

            name = name.Trim().ToLower();

            using (var transaction = await TagRepository.BeginUseTransactionAsync())
            {
                var tag = await TagRepository.ReadSummaryAsync(guildId, name);

                if (tag is null)
                {
                    throw new InvalidOperationException($"The tag '{name}' does not exist.");
                }

                var channel = await DiscordClient.GetChannelAsync(channelId);

                if (!(channel is IMessageChannel messageChannel))
                {
                    throw new InvalidOperationException($"The channel '{channel.Name}' is not a message channel.");
                }

                var sanitizedContent = FormatUtilities.SanitizeAllMentions(tag.Content);

                try
                {
                    await messageChannel.SendMessageAsync(sanitizedContent);
                }
                finally
                {
                    await TagRepository.TryIncrementUsesAsync(guildId, name);
                }

                transaction.Commit();
            }
        }
Ejemplo n.º 4
0
        public async Task UseTagAsync(ulong guildId, ulong channelId, string name)
        {
            _authorizationService.RequireClaims(AuthorizationClaim.UseTag);

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The tag name cannot be blank or whitespace.", nameof(name));
            }

            name = name.Trim().ToLower();

            var channel = await _discordClient.GetChannelAsync(channelId);

            if (!(channel is IMessageChannel messageChannel))
            {
                throw new InvalidOperationException($"The channel '{channel.Name}' is not a message channel.");
            }

            var tag = await _modixContext
                      .Set <TagEntity>()
                      .Where(x => x.GuildId == guildId)
                      .Where(x => x.DeleteActionId == null)
                      .Where(x => x.Name == name)
                      .SingleOrDefaultAsync();

            if (tag is null)
            {
                return;
            }

            var sanitizedContent = FormatUtilities.SanitizeAllMentions(tag.Content);

            await messageChannel.SendMessageAsync(sanitizedContent);

            tag.IncrementUse();

            await _modixContext.SaveChangesAsync();
        }