Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChuckNorris Module #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CSChatBot-Core/CSChatBot-Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions CSChatBot-Core/ChuckNorris/ChuckNorris.cs
Original file line number Diff line number Diff line change
@@ -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<CommandResponse> GetChuckNorrisJoke()
{
var client = new ChuckNorrisClient();
var joke = await client.GetRandomJoke();
return new CommandResponse($"{joke.Value}");
}
}
}
23 changes: 23 additions & 0 deletions CSChatBot-Core/ChuckNorris/ChuckNorris.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.24" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.0.0" />
<PackageReference Include="Telegram.Bot" Version="15.7.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DB\DB.csproj" />
<ProjectReference Include="..\Logger\Logger.csproj" />
<ProjectReference Include="..\ModuleFramework\ModuleFramework.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo F|xcopy /y $(TargetPath) &quot;$(SolutionDir)CSChatBot-Core\$(OutDir)Addon Modules\$(TargetFileName)&quot;" />
</Target>

</Project>
26 changes: 26 additions & 0 deletions CSChatBot-Core/ChuckNorris/ChuckNorrisClient.cs
Original file line number Diff line number Diff line change
@@ -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<Joke> GetRandomJoke()
{
Joke joke = await new FluentClient()
.PostAsync("https://api.chucknorris.io/jokes/random")
.As<Joke>();

return joke;
}
}
}
13 changes: 13 additions & 0 deletions CSChatBot-Core/ChuckNorris/Models/Joke.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}