Removed module projects because it can't work like that atm. Commented out package commands.
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
namespace NadekoBot.Modules.Games.Common.ChatterBot
|
||||
{
|
||||
public class ChatterBotResponse
|
||||
{
|
||||
public string Convo_id { get; set; }
|
||||
public string BotSay { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common.ChatterBot
|
||||
{
|
||||
public class ChatterBotSession : IChatterBotSession
|
||||
{
|
||||
private static NadekoRandom Rng { get; } = new NadekoRandom();
|
||||
|
||||
private readonly string _chatterBotId;
|
||||
private int _botId = 6;
|
||||
|
||||
public ChatterBotSession()
|
||||
{
|
||||
_chatterBotId = Rng.Next(0, 1000000).ToString().ToBase64();
|
||||
}
|
||||
|
||||
private string apiEndpoint => "http://api.program-o.com/v2/chatbot/" +
|
||||
$"?bot_id={_botId}&" +
|
||||
"say={0}&" +
|
||||
$"convo_id=nadekobot_{_chatterBotId}&" +
|
||||
"format=json";
|
||||
|
||||
public async Task<string> Think(string message)
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = await http.GetStringAsync(string.Format(apiEndpoint, message)).ConfigureAwait(false);
|
||||
var cbr = JsonConvert.DeserializeObject<ChatterBotResponse>(res);
|
||||
return cbr.BotSay.Replace("<br/>", "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common.ChatterBot
|
||||
{
|
||||
public class CleverbotResponse
|
||||
{
|
||||
public string Cs { get; set; }
|
||||
public string Output { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common.ChatterBot
|
||||
{
|
||||
public interface IChatterBotSession
|
||||
{
|
||||
Task<string> Think(string input);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common.ChatterBot
|
||||
{
|
||||
public class OfficialCleverbotSession : IChatterBotSession
|
||||
{
|
||||
private readonly string _apiKey;
|
||||
private string _cs = null;
|
||||
|
||||
private string queryString => $"https://www.cleverbot.com/getreply?key={_apiKey}" +
|
||||
"&wrapper=nadekobot" +
|
||||
"&input={0}" +
|
||||
"&cs={1}";
|
||||
|
||||
public OfficialCleverbotSession(string apiKey)
|
||||
{
|
||||
this._apiKey = apiKey;
|
||||
}
|
||||
|
||||
public async Task<string> Think(string input)
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var dataString = await http.GetStringAsync(string.Format(queryString, input, _cs ?? "")).ConfigureAwait(false);
|
||||
var data = JsonConvert.DeserializeObject<CleverbotResponse>(dataString);
|
||||
_cs = data?.Cs;
|
||||
return data?.Output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user