diff --git a/CSChatBot-Core/CSChatBot-Core.sln b/CSChatBot-Core/CSChatBot-Core.sln index 0ed9561..40837ce 100644 --- a/CSChatBot-Core/CSChatBot-Core.sln +++ b/CSChatBot-Core/CSChatBot-Core.sln @@ -11,13 +11,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logger", "Logger\Logger.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleFramework", "ModuleFramework\ModuleFramework.csproj", "{FEEFC395-A20A-4958-8D20-C1F9507DBE88}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleTemplate", "ModuleTemplate\ModuleTemplate.csproj", "{40A9F17D-9066-4AD3-9D45-D718DB892B7E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleTemplate", "ModuleTemplate\ModuleTemplate.csproj", "{40A9F17D-9066-4AD3-9D45-D718DB892B7E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XKCD", "XKCD\XKCD.csproj", "{5D6248BB-58D7-44AF-BCB3-9E0EC3854190}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XKCD", "XKCD\XKCD.csproj", "{5D6248BB-58D7-44AF-BCB3-9E0EC3854190}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giveaway", "Giveaway\Giveaway.csproj", "{00348DF6-8A41-428D-9885-955E29A1AF6A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Giveaway", "Giveaway\Giveaway.csproj", "{00348DF6-8A41-428D-9885-955E29A1AF6A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steam", "Steam\Steam.csproj", "{11A27980-2EAF-45A9-9954-FBCB6A99B143}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steam", "Steam\Steam.csproj", "{11A27980-2EAF-45A9-9954-FBCB6A99B143}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YodaTranslation", "YodaTranslation\YodaTranslation.csproj", "{52140338-5323-4301-AA26-9F3322E8B8F1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,6 +59,10 @@ Global {11A27980-2EAF-45A9-9954-FBCB6A99B143}.Debug|Any CPU.Build.0 = Debug|Any CPU {11A27980-2EAF-45A9-9954-FBCB6A99B143}.Release|Any CPU.ActiveCfg = Release|Any CPU {11A27980-2EAF-45A9-9954-FBCB6A99B143}.Release|Any CPU.Build.0 = Release|Any CPU + {52140338-5323-4301-AA26-9F3322E8B8F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52140338-5323-4301-AA26-9F3322E8B8F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52140338-5323-4301-AA26-9F3322E8B8F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52140338-5323-4301-AA26-9F3322E8B8F1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CSChatBot-Core/YodaTranslation/Models/YodaTranslationClient.cs b/CSChatBot-Core/YodaTranslation/Models/YodaTranslationClient.cs new file mode 100644 index 0000000..ae7901a --- /dev/null +++ b/CSChatBot-Core/YodaTranslation/Models/YodaTranslationClient.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace YodaTranslation.Models +{ + public class YodaTranslationClient + { + [JsonProperty("contents")] + public Contents contents { get; set; } + } + + public class Contents + { + public string translated { get; set; } + + public string text { get; set; } + + public string translation { get; set; } + } +} diff --git a/CSChatBot-Core/YodaTranslation/YodaHelper.cs b/CSChatBot-Core/YodaTranslation/YodaHelper.cs new file mode 100644 index 0000000..27d0064 --- /dev/null +++ b/CSChatBot-Core/YodaTranslation/YodaHelper.cs @@ -0,0 +1,37 @@ +using Newtonsoft.Json; +using System; +using System.Net.Http; +using System.Threading.Tasks; +using YodaTranslation.Models; + +namespace YodaTranslation +{ + public class YodaHelper + { + public async Task GetTranslation(string originalText) + { + YodaTranslationClient yodaTranslationClient; + + try + { + + using (var httpClient = new HttpClient()) + { + using (var response = await httpClient.GetAsync("https://api.funtranslations.com/translate/yoda.json?text=" + originalText)) + { + string apiResponse = await response.Content.ReadAsStringAsync(); + yodaTranslationClient = JsonConvert.DeserializeObject(apiResponse); + } + + } + } + catch (Exception) + { + //Return an empy yoda tranlation client + yodaTranslationClient = new YodaTranslationClient(); + } + + return yodaTranslationClient; + } + } +} diff --git a/CSChatBot-Core/YodaTranslation/YodaTranslation.cs b/CSChatBot-Core/YodaTranslation/YodaTranslation.cs new file mode 100644 index 0000000..9095077 --- /dev/null +++ b/CSChatBot-Core/YodaTranslation/YodaTranslation.cs @@ -0,0 +1,34 @@ +using DB; +using DB.Models; +using ModuleFramework; +using System; +using System.Threading.Tasks; +using Telegram.Bot; +using YodaTranslation.Models; + +namespace YodaTranslation +{ + [ModuleFramework.Module(Author = "C3sxr", Name = "YodaTranslation", Version = "1.0")] + public class YodaTranslation + { + private TelegramBotClient _telegramBotClient; + + public YodaTranslation(Instance db, Setting setting, TelegramBotClient telegramBotClient) + { + _telegramBotClient = telegramBotClient; + } + + [ChatCommand(Triggers = new [] { "yodatranslation", "Translate"}, HelpText = "Translate your phrase to a Yoda phrase")] + public async Task GetYodaTranslation() + { + var yodaHelper = new YodaHelper(); + Console.Write("What text you want to translato to Yoda? "); + var originalText = Console.ReadLine(); + + var yodaTranslation = await yodaHelper.GetTranslation(originalText); + + return new CommandResponse($"{yodaTranslation.contents.translated}"); + + } + } +} diff --git a/CSChatBot-Core/YodaTranslation/YodaTranslation.csproj b/CSChatBot-Core/YodaTranslation/YodaTranslation.csproj new file mode 100644 index 0000000..e328c72 --- /dev/null +++ b/CSChatBot-Core/YodaTranslation/YodaTranslation.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp3.1 + + + + + + + + +