Using new stopwatch, some cleanup. No functional change
This commit is contained in:
parent
a6e891fc92
commit
a2890195a9
6 changed files with 16 additions and 21 deletions
|
@ -93,7 +93,7 @@ public sealed class Bot : IBot
|
||||||
private void AddServices()
|
private void AddServices()
|
||||||
{
|
{
|
||||||
var startingGuildIdList = GetCurrentGuildIds();
|
var startingGuildIdList = GetCurrentGuildIds();
|
||||||
var sw = Stopwatch.StartNew();
|
var startTime = Stopwatch.GetTimestamp();
|
||||||
var bot = Client.CurrentUser;
|
var bot = Client.CurrentUser;
|
||||||
|
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
|
@ -161,8 +161,7 @@ public sealed class Bot : IBot
|
||||||
LoadTypeReaders(a);
|
LoadTypeReaders(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Stop();
|
Log.Information("All services loaded in {ServiceLoadTime:F2}s", Stopwatch.GetElapsedTime(startTime).TotalSeconds);
|
||||||
Log.Information("All services loaded in {ServiceLoadTime:F2}s", sw.Elapsed.TotalSeconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadTypeReaders(Assembly assembly)
|
private void LoadTypeReaders(Assembly assembly)
|
||||||
|
@ -259,7 +258,7 @@ public sealed class Bot : IBot
|
||||||
if (ShardId == 0)
|
if (ShardId == 0)
|
||||||
await _db.SetupAsync();
|
await _db.SetupAsync();
|
||||||
|
|
||||||
var sw = Stopwatch.StartNew();
|
var startTime = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
await LoginAsync(_creds.Token);
|
await LoginAsync(_creds.Token);
|
||||||
|
|
||||||
|
@ -274,8 +273,7 @@ public sealed class Bot : IBot
|
||||||
Helpers.ReadErrorAndExit(9);
|
Helpers.ReadErrorAndExit(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Stop();
|
Log.Information("Shard {ShardId} connected in {Elapsed:F2}s", Client.ShardId, Stopwatch.GetElapsedTime(startTime).TotalSeconds);
|
||||||
Log.Information("Shard {ShardId} connected in {Elapsed:F2}s", Client.ShardId, sw.Elapsed.TotalSeconds);
|
|
||||||
var commandHandler = Services.GetRequiredService<CommandHandler>();
|
var commandHandler = Services.GetRequiredService<CommandHandler>();
|
||||||
|
|
||||||
// start handling messages received in commandhandler
|
// start handling messages received in commandhandler
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class ChatterBotService : IExecOnMessage
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Warning("Error in chatterbot: {Error}", error);
|
Log.Warning("Error in chatterbot: {Error}", error.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Information("""
|
Log.Information("""
|
||||||
|
|
|
@ -103,6 +103,8 @@ public class OfficialGptSession : IChatterBotSession
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString);
|
var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString);
|
||||||
|
|
||||||
|
Log.Information("Received response: {response}", dataString);
|
||||||
var res = response?.Choices?[0];
|
var res = response?.Choices?[0];
|
||||||
var message = res?.Message?.Content;
|
var message = res?.Message?.Content;
|
||||||
|
|
||||||
|
|
|
@ -32,20 +32,21 @@ public sealed class SearxSearchService : SearchServiceBase, IEService
|
||||||
var instanceUrl = GetRandomInstance();
|
var instanceUrl = GetRandomInstance();
|
||||||
|
|
||||||
Log.Information("Using {Instance} instance for web search...", instanceUrl);
|
Log.Information("Using {Instance} instance for web search...", instanceUrl);
|
||||||
var sw = Stopwatch.StartNew();
|
var startTime = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
using var http = _http.CreateClient();
|
using var http = _http.CreateClient();
|
||||||
await using var res = await http.GetStreamAsync($"{instanceUrl}"
|
await using var res = await http.GetStreamAsync($"{instanceUrl}"
|
||||||
+ $"?q={Uri.EscapeDataString(query)}"
|
+ $"?q={Uri.EscapeDataString(query)}"
|
||||||
+ $"&format=json"
|
+ $"&format=json"
|
||||||
+ $"&strict=2");
|
+ $"&strict=2");
|
||||||
|
|
||||||
sw.Stop();
|
var elapsed = Stopwatch.GetElapsedTime(startTime);
|
||||||
var dat = await JsonSerializer.DeserializeAsync<SearxSearchResult>(res);
|
var dat = await JsonSerializer.DeserializeAsync<SearxSearchResult>(res);
|
||||||
|
|
||||||
if (dat is null)
|
if (dat is null)
|
||||||
return new SearxSearchResult();
|
return new SearxSearchResult();
|
||||||
|
|
||||||
dat.SearchTime = sw.Elapsed.TotalSeconds.ToString("N2", CultureInfo.InvariantCulture);
|
dat.SearchTime = elapsed.TotalSeconds.ToString("N2", CultureInfo.InvariantCulture);
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ public sealed class SearxSearchService : SearchServiceBase, IEService
|
||||||
var instanceUrl = GetRandomInstance();
|
var instanceUrl = GetRandomInstance();
|
||||||
|
|
||||||
Log.Information("Using {Instance} instance for img search...", instanceUrl);
|
Log.Information("Using {Instance} instance for img search...", instanceUrl);
|
||||||
var sw = Stopwatch.StartNew();
|
var startTime = Stopwatch.GetTimestamp();
|
||||||
using var http = _http.CreateClient();
|
using var http = _http.CreateClient();
|
||||||
await using var res = await http.GetStreamAsync($"{instanceUrl}"
|
await using var res = await http.GetStreamAsync($"{instanceUrl}"
|
||||||
+ $"?q={Uri.EscapeDataString(query)}"
|
+ $"?q={Uri.EscapeDataString(query)}"
|
||||||
|
@ -64,13 +65,13 @@ public sealed class SearxSearchService : SearchServiceBase, IEService
|
||||||
+ $"&category_images=on"
|
+ $"&category_images=on"
|
||||||
+ $"&strict=2");
|
+ $"&strict=2");
|
||||||
|
|
||||||
sw.Stop();
|
var elapsed = Stopwatch.GetElapsedTime(startTime);
|
||||||
var dat = await JsonSerializer.DeserializeAsync<SearxImageSearchResult>(res);
|
var dat = await JsonSerializer.DeserializeAsync<SearxImageSearchResult>(res);
|
||||||
|
|
||||||
if (dat is null)
|
if (dat is null)
|
||||||
return new SearxImageSearchResult();
|
return new SearxImageSearchResult();
|
||||||
|
|
||||||
dat.SearchTime = sw.Elapsed.TotalSeconds.ToString("N2", CultureInfo.InvariantCulture);
|
dat.SearchTime = elapsed.TotalSeconds.ToString("N2", CultureInfo.InvariantCulture);
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,9 +8,9 @@ public sealed class CommandPromptResultModel
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("arguments")]
|
[JsonPropertyName("arguments")]
|
||||||
public required Dictionary<string, string> Arguments { get; set; }
|
public Dictionary<string, string> Arguments { get; set; } = new();
|
||||||
|
|
||||||
[JsonPropertyName("remaining")]
|
[JsonPropertyName("remaining")]
|
||||||
[JsonConverter(typeof(NumberToStringConverter))]
|
[JsonConverter(typeof(NumberToStringConverter))]
|
||||||
public required string Remaining { get; set; }
|
public string Remaining { get; set; } = string.Empty;
|
||||||
}
|
}
|
|
@ -229,10 +229,4 @@ public static class Extensions
|
||||||
public static IEnumerable<IRole> GetRoles(this IGuildUser user)
|
public static IEnumerable<IRole> GetRoles(this IGuildUser user)
|
||||||
=> user.RoleIds.Select(r => user.Guild.GetRole(r)).Where(r => r is not null);
|
=> user.RoleIds.Select(r => user.Guild.GetRole(r)).Where(r => r is not null);
|
||||||
|
|
||||||
// todo remove
|
|
||||||
public static void Lap(this Stopwatch sw, string checkpoint)
|
|
||||||
{
|
|
||||||
Log.Information("Checkpoint {CheckPoint}: {Time}ms", checkpoint, sw.Elapsed.TotalMilliseconds);
|
|
||||||
sw.Restart();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue