More common refactorings like renaming variables, removing empty statements and unused variables, etc

This commit is contained in:
Kwoth
2022-01-09 16:46:08 +01:00
parent 2ce3262d59
commit f07a855912
75 changed files with 447 additions and 465 deletions

View File

@@ -48,7 +48,7 @@ public class ChatterBotService : IEarlyBehavior
{
if (!string.IsNullOrWhiteSpace(_creds.CleverbotApiKey))
return new OfficialCleverbotSession(_creds.CleverbotApiKey, _httpFactory);
return new CleverbotIOSession("GAh3wUfzDCpDpdpT", "RStKgqn7tcO9blbrv4KbXM8NDlb7H37C", _httpFactory);
return new CleverbotIoSession("GAh3wUfzDCpDpdpT", "RStKgqn7tcO9blbrv4KbXM8NDlb7H37C", _httpFactory);
}
public string PrepareMessage(IUserMessage msg, out IChatterBotSession cleverbot)

View File

@@ -7,13 +7,13 @@ public class CleverbotResponse
public string Output { get; set; }
}
public class CleverbotIOCreateResponse
public class CleverbotIoCreateResponse
{
public string Status { get; set; }
public string Nick { get; set; }
}
public class CleverbotIOAskResponse
public class CleverbotIoAskResponse
{
public string Status { get; set; }
public string Response { get; set; }

View File

@@ -10,7 +10,7 @@ public class OfficialCleverbotSession : IChatterBotSession
private readonly string _apiKey;
private readonly IHttpClientFactory _httpFactory;
private string _cs;
private string cs;
public OfficialCleverbotSession(string apiKey, IHttpClientFactory factory)
{
@@ -21,12 +21,12 @@ public class OfficialCleverbotSession : IChatterBotSession
public async Task<string> Think(string input)
{
using var http = _httpFactory.CreateClient();
var dataString = await http.GetStringAsync(string.Format(QueryString, input, _cs ?? ""));
var dataString = await http.GetStringAsync(string.Format(QueryString, input, cs ?? ""));
try
{
var data = JsonConvert.DeserializeObject<CleverbotResponse>(dataString);
_cs = data?.Cs;
cs = data?.Cs;
return data?.Output;
}
catch
@@ -37,7 +37,7 @@ public class OfficialCleverbotSession : IChatterBotSession
}
}
public class CleverbotIOSession : IChatterBotSession
public class CleverbotIoSession : IChatterBotSession
{
private readonly string _key;
private readonly string _user;
@@ -47,7 +47,7 @@ public class CleverbotIOSession : IChatterBotSession
private readonly string _createEndpoint = "https://cleverbot.io/1.0/create";
private readonly string _askEndpoint = "https://cleverbot.io/1.0/ask";
public CleverbotIOSession(string user, string key, IHttpClientFactory factory)
public CleverbotIoSession(string user, string key, IHttpClientFactory factory)
{
_key = key;
_user = user;
@@ -58,14 +58,14 @@ public class CleverbotIOSession : IChatterBotSession
private async Task<string> GetNick()
{
using var _http = _httpFactory.CreateClient();
using var http = _httpFactory.CreateClient();
using var msg = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("user", _user), new KeyValuePair<string, string>("key", _key)
});
using var data = await _http.PostAsync(_createEndpoint, msg);
using var data = await http.PostAsync(_createEndpoint, msg);
var str = await data.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject<CleverbotIOCreateResponse>(str);
var obj = JsonConvert.DeserializeObject<CleverbotIoCreateResponse>(str);
if (obj.Status != "success")
throw new OperationCanceledException(obj.Status);
@@ -74,15 +74,15 @@ public class CleverbotIOSession : IChatterBotSession
public async Task<string> Think(string input)
{
using var _http = _httpFactory.CreateClient();
using var http = _httpFactory.CreateClient();
using var msg = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("user", _user), new KeyValuePair<string, string>("key", _key),
new KeyValuePair<string, string>("nick", await _nick), new KeyValuePair<string, string>("text", input)
});
using var data = await _http.PostAsync(_askEndpoint, msg);
using var data = await http.PostAsync(_askEndpoint, msg);
var str = await data.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject<CleverbotIOAskResponse>(str);
var obj = JsonConvert.DeserializeObject<CleverbotIoAskResponse>(str);
if (obj.Status != "success")
throw new OperationCanceledException(obj.Status);