Better startup

This commit is contained in:
2026-02-28 01:35:18 +00:00
parent 350301c63d
commit 76da69ce1f
3 changed files with 40 additions and 14 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
bin/
obj/
SkyAI.sln
Program.cs.old
.env

View File

@@ -20,8 +20,9 @@ public class Program
const int MaxResponseLength = 2048; const int MaxResponseLength = 2048;
const string ModelName = "llama3.1:latest"; const string ModelName = "llama3.1:latest";
private static readonly Dictionary<long, Channel> ChannelCache = new(); private static readonly Dictionary<long, Channel> channelCache = new();
private static readonly Dictionary<long, List<ChatMessage>> ChatHistory = new(); private static readonly Dictionary<long, List<ChatMessage>> ChatHistory = new();
private static readonly HashSet<long> InitializedPlanets = new();
public static async Task Main() public static async Task Main()
{ {
@@ -51,15 +52,7 @@ public class Program
Console.WriteLine($"Logged in as {client.Me.Name}"); Console.WriteLine($"Logged in as {client.Me.Name}");
await client.BotService.JoinAllChannelsAsync(); await Utils.InitializePlanetsAsync(client, channelCache, InitializedPlanets);
foreach (var planet in client.PlanetService.JoinedPlanets)
{
foreach (var channel in planet.Channels)
{
ChannelCache[channel.Id] = channel;
}
}
var httpClient = new HttpClient var httpClient = new HttpClient
{ {
@@ -82,13 +75,13 @@ public class Program
if (content.StartsWith("s.cm")) if (content.StartsWith("s.cm"))
{ {
ChatHistory.Remove(channelId); ChatHistory.Remove(channelId);
await Utils.SendReplyAsync(ChannelCache, channelId, $"{ping} Channel memory cleared."); await Utils.SendReplyAsync(channelCache, channelId, $"{ping} Channel memory cleared.");
return; return;
} }
if (content.StartsWith("s.source")) if (content.StartsWith("s.source"))
{ {
await Utils.SendReplyAsync(ChannelCache, channelId, $"{ping} You can find my source code here: https://github.com/SkyJoshua/SkyAI"); await Utils.SendReplyAsync(channelCache, channelId, $"{ping} You can find my source code here: https://github.com/SkyJoshua/SkyAI");
} }
if (!content.StartsWith("s.ai")) if (!content.StartsWith("s.ai"))
@@ -97,7 +90,7 @@ public class Program
var prompt = content.Substring(5).Trim(); var prompt = content.Substring(5).Trim();
if (string.IsNullOrWhiteSpace(prompt)) if (string.IsNullOrWhiteSpace(prompt))
{ {
await Utils.SendReplyAsync(ChannelCache, channelId, $"{ping} Enter a question."); await Utils.SendReplyAsync(channelCache, channelId, $"{ping} Enter a question.");
return; return;
} }
@@ -137,7 +130,7 @@ public class Program
output = Truncate(output); output = Truncate(output);
await Utils.SendReplyAsync(ChannelCache, channelId, output); await Utils.SendReplyAsync(channelCache, channelId, output);
}; };
Console.WriteLine("Listening..."); Console.WriteLine("Listening...");

View File

@@ -1,6 +1,7 @@
using System.Globalization; using System.Globalization;
using System.Text.Json; using System.Text.Json;
using Valour.Sdk.Models; using Valour.Sdk.Models;
using Valour.Sdk.Client;
namespace SkyAI namespace SkyAI
{ {
@@ -78,5 +79,32 @@ namespace SkyAI
timer.AutoReset = true; timer.AutoReset = true;
timer.Start(); timer.Start();
} }
public static async Task InitializePlanetsAsync(ValourClient client, Dictionary<long, Channel> channelCache, HashSet<long> initializedPlanets)
{
foreach (var planet in client.PlanetService.JoinedPlanets)
{
if (initializedPlanets.Contains(planet.Id))
continue;
Console.WriteLine($"Initializing Planet: {planet.Name}");
await planet.EnsureReadyAsync();
await planet.FetchInitialDataAsync();
foreach (var channel in planet.Channels)
{
channelCache[channel.Id] = channel;
if (channel.ChannelType == Valour.Shared.Models.ChannelTypeEnum.PlanetChat)
{
await channel.OpenWithResult("SkyBot");
Console.WriteLine($"Realtime opened for: {planet.Name} -> {channel.Name}");
}
}
initializedPlanets.Add(planet.Id);
}
}
}; };
}; };