Beispiel #1
0
        public async Task ExecuteGroupAsync(CommandContext ctx,
                                            [RemainingText, Description("Query.")] string query)
        {
            UrbanDictData data = await UrbanDictService.GetDefinitionForTermAsync(query);

            if (data == null)
            {
                await this.InformFailureAsync(ctx, "No results found!");

                return;
            }

            await ctx.SendCollectionInPagesAsync(
                $"Urban Dictionary search results for \"{query}\"",
                data.List,
                res => {
                var sb = new StringBuilder("Definition by ");
                sb.Append(Formatter.Bold(res.Author)).AppendLine().AppendLine();
                sb.Append(Formatter.Bold(res.Word)).Append(" :");
                sb.AppendLine(Formatter.BlockCode(res.Definition.Trim().Truncate(1000)));
                if (!string.IsNullOrWhiteSpace(res.Example))
                {
                    sb.Append("Examples:").AppendLine(Formatter.BlockCode(res.Example.Trim().Truncate(250)));
                }
                sb.Append(res.Permalink);
                return(sb.ToString());
            },
                this.ModuleColor,
                1
                );
        }
Beispiel #2
0
        public async Task ExecuteGroupAsync(CommandContext ctx,
                                            [RemainingText, Description("desc-query")] string query)
        {
            UrbanDictData?data = await UrbanDictService.GetDefinitionForTermAsync(query);

            if (data is null)
            {
                await ctx.FailAsync("cmd-err-res-none");

                return;
            }

            await ctx.PaginateAsync(
                "fmt-ud",
                data.List,
                res => {
                var sb = new StringBuilder(this.Localization.GetString(ctx.Guild?.Id, "str-def-by"));
                sb.Append(Formatter.Bold(res.Author)).AppendLine().AppendLine();
                sb.Append(Formatter.Bold(res.Word)).Append(" :");
                sb.AppendLine(Formatter.BlockCode(res.Definition.Trim().Truncate(1000)));
                if (!string.IsNullOrWhiteSpace(res.Example))
                {
                    sb.Append(this.Localization.GetString(ctx.Guild?.Id, "str-examples")).AppendLine(Formatter.BlockCode(res.Example.Trim().Truncate(250)));
                }
                sb.Append(res.Permalink);
                return(sb.ToString());
            },
                this.ModuleColor,
                1,
                query
                );
        }
Beispiel #3
0
        public async Task GetDefinitionForTermAsyncTest()
        {
            Assert.IsNotNull(await UrbanDictService.GetDefinitionForTermAsync("umbrella"));
            Assert.IsNotNull(await UrbanDictService.GetDefinitionForTermAsync("jewnazi"));
            Assert.IsNotNull(await UrbanDictService.GetDefinitionForTermAsync("machine learning"));
            Assert.IsNotNull(await UrbanDictService.GetDefinitionForTermAsync("banzai!"));

            Assert.IsNull(await UrbanDictService.GetDefinitionForTermAsync("SDSANDJKSANDkJSANDKJSANDKAJND"));

            Assert.ThrowsAsync(typeof(ArgumentException), () => UrbanDictService.GetDefinitionForTermAsync(null));
            Assert.ThrowsAsync(typeof(ArgumentException), () => UrbanDictService.GetDefinitionForTermAsync(""));
            Assert.ThrowsAsync(typeof(ArgumentException), () => UrbanDictService.GetDefinitionForTermAsync(" "));
            Assert.ThrowsAsync(typeof(ArgumentException), () => UrbanDictService.GetDefinitionForTermAsync("\n"));
        }
Beispiel #4
0
        public async Task ExecuteGroupAsync(CommandContext ctx,
                                            [RemainingText, Description("Query.")] string query)
        {
            UrbanDictData data = await UrbanDictService.GetDefinitionForTermAsync(query);

            if (data is null)
            {
                await this.InformFailureAsync(ctx, "No results found!");

                return;
            }

            await ctx.SendCollectionInPagesAsync(
                $"Urban Dictionary search results for \"{query}\"",
                data.List,
                res => res.ToInfoString(),
                this.ModuleColor,
                1
                );
        }