diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs deleted file mode 100644 index 1daa9be..0000000 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Geekbot.Bot.Commands.Integrations.UbranDictionary -{ - internal class UrbanListItemDto - { - - [JsonPropertyName("definition")] - public string Definition { get; set; } - - [JsonPropertyName("permalink")] - public string Permalink { get; set; } - - [JsonPropertyName("thumbs_up")] - public int ThumbsUp { get; set; } - - [JsonPropertyName("word")] - public string Word { get; set; } - - [JsonPropertyName("example")] - public string Example { get; set; } - - [JsonPropertyName("thumbs_down")] - public int ThumbsDown { get; set; } - } -} \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs deleted file mode 100644 index 042b779..0000000 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; - -namespace Geekbot.Bot.Commands.Integrations.UbranDictionary -{ - internal class UrbanResponseDto - { - [JsonPropertyName("tags")] - public string[] Tags { get; set; } - - [JsonPropertyName("list")] - public List List { get; set; } - } -} \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs b/src/Bot/Commands/Integrations/UrbanDictionary.cs similarity index 73% rename from src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs rename to src/Bot/Commands/Integrations/UrbanDictionary.cs index c009f69..c0ae96a 100644 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs +++ b/src/Bot/Commands/Integrations/UrbanDictionary.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; @@ -7,7 +6,7 @@ using Geekbot.Core; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -namespace Geekbot.Bot.Commands.Integrations.UbranDictionary +namespace Geekbot.Bot.Commands.Integrations { public class UrbanDictionary : TransactionModuleBase { @@ -24,22 +23,21 @@ namespace Geekbot.Bot.Commands.Integrations.UbranDictionary { try { - var definitions = await HttpAbstractions.Get(new Uri($"https://api.urbandictionary.com/v0/define?term={word}")); - if (definitions.List.Count == 0) + var definition = await Geekbot.Commands.UrbanDictionary.UrbanDictionary.Run(word); + if (definition == null) { await ReplyAsync("That word hasn't been defined..."); return; } - var definition = definitions.List.First(e => !string.IsNullOrWhiteSpace(e.Example)); - var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder { Name = definition.Word, Url = definition.Permalink }); - eb.WithColor(new Color(239, 255, 0)); + var c = System.Drawing.Color.Gold; + eb.WithColor(new Color(c.R, c.G, c.B)); static string ShortenIfToLong(string str, int maxLength) => str.Length > maxLength ? $"{str.Substring(0, maxLength - 5)}[...]" : str; @@ -47,9 +45,8 @@ namespace Geekbot.Bot.Commands.Integrations.UbranDictionary if (!string.IsNullOrEmpty(definition.Example)) eb.AddField("Example", ShortenIfToLong(definition.Example, 1024)); if (definition.ThumbsUp != 0) eb.AddInlineField("Upvotes", definition.ThumbsUp); if (definition.ThumbsDown != 0) eb.AddInlineField("Downvotes", definition.ThumbsDown); - if (definitions.Tags?.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.Tags)); - await ReplyAsync("", false, eb.Build()); + await ReplyAsync(string.Empty, false, eb.Build()); } catch (Exception e) { diff --git a/src/Commands/UrbanDictionary/UrbanDictionary.cs b/src/Commands/UrbanDictionary/UrbanDictionary.cs new file mode 100644 index 0000000..a437daf --- /dev/null +++ b/src/Commands/UrbanDictionary/UrbanDictionary.cs @@ -0,0 +1,20 @@ +using Geekbot.Core; + +namespace Geekbot.Commands.UrbanDictionary; + +public class UrbanDictionary +{ + public static async Task Run(string term) + { + var definitions = await HttpAbstractions.Get(new Uri($"https://api.urbandictionary.com/v0/define?term={term}")); + + if (definitions.List.Count == 0) + { + return null; + } + + var definition = definitions.List.First(e => !string.IsNullOrWhiteSpace(e.Example)); + + return definition; + } +} \ No newline at end of file diff --git a/src/Commands/UrbanDictionary/UrbanDictionaryListItem.cs b/src/Commands/UrbanDictionary/UrbanDictionaryListItem.cs new file mode 100644 index 0000000..822ca8a --- /dev/null +++ b/src/Commands/UrbanDictionary/UrbanDictionaryListItem.cs @@ -0,0 +1,24 @@ +using System.Text.Json.Serialization; + +namespace Geekbot.Commands.UrbanDictionary; + +public record UrbanDictionaryListItem +{ + [JsonPropertyName("definition")] + public string Definition { get; set; } + + [JsonPropertyName("permalink")] + public string Permalink { get; set; } + + [JsonPropertyName("thumbs_up")] + public int ThumbsUp { get; set; } + + [JsonPropertyName("word")] + public string Word { get; set; } + + [JsonPropertyName("example")] + public string Example { get; set; } + + [JsonPropertyName("thumbs_down")] + public int ThumbsDown { get; set; } +} diff --git a/src/Commands/UrbanDictionary/UrbanDictionaryResponse.cs b/src/Commands/UrbanDictionary/UrbanDictionaryResponse.cs new file mode 100644 index 0000000..42861c3 --- /dev/null +++ b/src/Commands/UrbanDictionary/UrbanDictionaryResponse.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Geekbot.Commands.UrbanDictionary; + +public struct UrbanDictionaryResponse +{ + [JsonPropertyName("tags")] + public string[] Tags { get; set; } + + [JsonPropertyName("list")] + public List List { get; set; } +} \ No newline at end of file diff --git a/src/Web/Commands/UrbanDictionary.cs b/src/Web/Commands/UrbanDictionary.cs new file mode 100644 index 0000000..ca5794f --- /dev/null +++ b/src/Web/Commands/UrbanDictionary.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Threading.Tasks; +using Geekbot.Core.Interactions; +using Geekbot.Core.Interactions.ApplicationCommand; +using Geekbot.Core.Interactions.Embed; +using Geekbot.Core.Interactions.Request; +using Geekbot.Core.Interactions.Response; + +namespace Geekbot.Web.Commands; + +public class UrbanDictionary : InteractionBase +{ + private struct Options + { + internal const string Term = "term"; + } + + public override Command GetCommandInfo() + { + return new Command() + { + Name = "urban", + Description = "Lookup something on urban dictionary", + Type = CommandType.ChatInput, + Options = new List