Better startup
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
SkyAI.sln
|
||||
Program.cs.old
|
||||
.env
|
||||
21
Program.cs
21
Program.cs
@@ -20,8 +20,9 @@ public class Program
|
||||
const int MaxResponseLength = 2048;
|
||||
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 HashSet<long> InitializedPlanets = new();
|
||||
|
||||
public static async Task Main()
|
||||
{
|
||||
@@ -51,15 +52,7 @@ public class Program
|
||||
|
||||
Console.WriteLine($"Logged in as {client.Me.Name}");
|
||||
|
||||
await client.BotService.JoinAllChannelsAsync();
|
||||
|
||||
foreach (var planet in client.PlanetService.JoinedPlanets)
|
||||
{
|
||||
foreach (var channel in planet.Channels)
|
||||
{
|
||||
ChannelCache[channel.Id] = channel;
|
||||
}
|
||||
}
|
||||
await Utils.InitializePlanetsAsync(client, channelCache, InitializedPlanets);
|
||||
|
||||
var httpClient = new HttpClient
|
||||
{
|
||||
@@ -82,13 +75,13 @@ public class Program
|
||||
if (content.StartsWith("s.cm"))
|
||||
{
|
||||
ChatHistory.Remove(channelId);
|
||||
await Utils.SendReplyAsync(ChannelCache, channelId, $"{ping} Channel memory cleared.");
|
||||
await Utils.SendReplyAsync(channelCache, channelId, $"{ping} Channel memory cleared.");
|
||||
return;
|
||||
}
|
||||
|
||||
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"))
|
||||
@@ -97,7 +90,7 @@ public class Program
|
||||
var prompt = content.Substring(5).Trim();
|
||||
if (string.IsNullOrWhiteSpace(prompt))
|
||||
{
|
||||
await Utils.SendReplyAsync(ChannelCache, channelId, $"{ping} Enter a question.");
|
||||
await Utils.SendReplyAsync(channelCache, channelId, $"{ping} Enter a question.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -137,7 +130,7 @@ public class Program
|
||||
|
||||
output = Truncate(output);
|
||||
|
||||
await Utils.SendReplyAsync(ChannelCache, channelId, output);
|
||||
await Utils.SendReplyAsync(channelCache, channelId, output);
|
||||
};
|
||||
|
||||
Console.WriteLine("Listening...");
|
||||
|
||||
28
utils.cs
28
utils.cs
@@ -1,6 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Valour.Sdk.Models;
|
||||
using Valour.Sdk.Client;
|
||||
|
||||
namespace SkyAI
|
||||
{
|
||||
@@ -78,5 +79,32 @@ namespace SkyAI
|
||||
timer.AutoReset = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user