Skip to content
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YodaTranslation", "YodaTranslation\YodaTranslation.csproj", "{52140338-5323-4301-AA26-9F3322E8B8F1}"
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
{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
Expand Down
19 changes: 19 additions & 0 deletions CSChatBot-Core/YodaTranslation/Models/YodaTranslationClient.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
37 changes: 37 additions & 0 deletions CSChatBot-Core/YodaTranslation/YodaHelper.cs
Original file line number Diff line number Diff line change
@@ -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<YodaTranslationClient> 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<YodaTranslationClient>(apiResponse);
}

}
}
catch (Exception)
{
//Return an empy yoda tranlation client
yodaTranslationClient = new YodaTranslationClient();
}

return yodaTranslationClient;
}
}
}
34 changes: 34 additions & 0 deletions CSChatBot-Core/YodaTranslation/YodaTranslation.cs
Original file line number Diff line number Diff line change
@@ -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<CommandResponse> 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}");

}
}
}
13 changes: 13 additions & 0 deletions CSChatBot-Core/YodaTranslation/YodaTranslation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

</Project>