From 42bad077c4edeac406e7ddaad2446c5880c48356 Mon Sep 17 00:00:00 2001 From: "sepp.amsl@protonmail.com" Date: Mon, 5 Oct 2020 18:56:14 +0200 Subject: [PATCH] ChuckNorris --- CSChatBot-Core/CSChatBot-Core.sln | 14 +++++++--- CSChatBot-Core/ChuckNorris/ChuckNorris.cs | 26 +++++++++++++++++++ CSChatBot-Core/ChuckNorris/ChuckNorris.csproj | 23 ++++++++++++++++ .../ChuckNorris/ChuckNorrisClient.cs | 26 +++++++++++++++++++ CSChatBot-Core/ChuckNorris/Models/Joke.cs | 13 ++++++++++ 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 CSChatBot-Core/ChuckNorris/ChuckNorris.cs create mode 100644 CSChatBot-Core/ChuckNorris/ChuckNorris.csproj create mode 100644 CSChatBot-Core/ChuckNorris/ChuckNorrisClient.cs create mode 100644 CSChatBot-Core/ChuckNorris/Models/Joke.cs diff --git a/CSChatBot-Core/CSChatBot-Core.sln b/CSChatBot-Core/CSChatBot-Core.sln index 0ed9561..ce4567c 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChuckNorris", "ChuckNorris\ChuckNorris.csproj", "{ED7F760C-8370-4C2A-9941-2E45A4D918CE}" 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 + {ED7F760C-8370-4C2A-9941-2E45A4D918CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED7F760C-8370-4C2A-9941-2E45A4D918CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED7F760C-8370-4C2A-9941-2E45A4D918CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED7F760C-8370-4C2A-9941-2E45A4D918CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CSChatBot-Core/ChuckNorris/ChuckNorris.cs b/CSChatBot-Core/ChuckNorris/ChuckNorris.cs new file mode 100644 index 0000000..9a1bf55 --- /dev/null +++ b/CSChatBot-Core/ChuckNorris/ChuckNorris.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using DB; +using DB.Models; +using ModuleFramework; +using Telegram.Bot; + +namespace ChuckNorris +{ + [ModuleFramework.Module(Author = "AlexGipp", Name = "ChuckNorris", Version = "1.0")] + public class ChuckNorris + { + private TelegramBotClient _bot; + public ChuckNorris(Instance db, Setting settings, TelegramBotClient bot) + { + _bot = bot; + } + + [ChatCommand(Triggers = new[] { "chucknorris", "Joke" }, HelpText = "Gets a random ChuckNorris joke")] + public async Task GetChuckNorrisJoke() + { + var client = new ChuckNorrisClient(); + var joke = await client.GetRandomJoke(); + return new CommandResponse($"{joke.Value}"); + } + } +} \ No newline at end of file diff --git a/CSChatBot-Core/ChuckNorris/ChuckNorris.csproj b/CSChatBot-Core/ChuckNorris/ChuckNorris.csproj new file mode 100644 index 0000000..be5552f --- /dev/null +++ b/CSChatBot-Core/ChuckNorris/ChuckNorris.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + + + + + + + diff --git a/CSChatBot-Core/ChuckNorris/ChuckNorrisClient.cs b/CSChatBot-Core/ChuckNorris/ChuckNorrisClient.cs new file mode 100644 index 0000000..2eb1782 --- /dev/null +++ b/CSChatBot-Core/ChuckNorris/ChuckNorrisClient.cs @@ -0,0 +1,26 @@ +using DB; +using DB.Models; +using HtmlAgilityPack; +using ModuleFramework; +using Newtonsoft.Json; +using System; +using System.Net; +using System.Threading.Tasks; +using ChuckNorris.Models; +using Pathoschild.Http.Client; +using Telegram.Bot; + +namespace ChuckNorris +{ + public class ChuckNorrisClient + { + public async Task GetRandomJoke() + { + Joke joke = await new FluentClient() + .PostAsync("https://api.chucknorris.io/jokes/random") + .As(); + + return joke; + } + } +} diff --git a/CSChatBot-Core/ChuckNorris/Models/Joke.cs b/CSChatBot-Core/ChuckNorris/Models/Joke.cs new file mode 100644 index 0000000..ad8ebee --- /dev/null +++ b/CSChatBot-Core/ChuckNorris/Models/Joke.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace ChuckNorris.Models +{ + public struct Joke + { + [JsonProperty("url")] + public string Url { get; private set; } + + [JsonProperty("value")] + public string Value { get; private set; } + } +} \ No newline at end of file