More consistant channel getting

This commit is contained in:
2026-02-27 23:50:57 +00:00
parent 9155c72070
commit 2f2a6edf5d
2 changed files with 64 additions and 25 deletions

5
.gitignore vendored Normal file
View File

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

View File

@@ -2,11 +2,12 @@ using Valour.Sdk.Client;
using Valour.Sdk.Models; using Valour.Sdk.Models;
using DotNetEnv; using DotNetEnv;
using SkyBot; using SkyBot;
using Valour.Sdk.Services;
using System.Net.NetworkInformation;
Env.Load(); Env.Load();
var token = Environment.GetEnvironmentVariable("TOKEN"); var token = Environment.GetEnvironmentVariable("TOKEN");
var channelCache = new Dictionary<long, Channel>();
var allowedUserIds = new List<long> { 15652354820931584 }; var allowedUserIds = new List<long> { 15652354820931584 };
var client = new ValourClient("https://api.valour.gg/"); var client = new ValourClient("https://api.valour.gg/");
@@ -26,18 +27,47 @@ if (!loginResult.Success)
} }
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})"); Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
await client.BotService.JoinAllChannelsAsync(); await Utils.UpdateValourUserCountAsync();
Utils.StartValourUserUpdater();
//Dictionaries
var channelCache = new Dictionary<long, Channel>();
var InitializedPlanets = new HashSet<long>();
_ = Task.Run(async () =>
{
while (true)
{
foreach (var planet in client.PlanetService.JoinedPlanets) foreach (var planet in client.PlanetService.JoinedPlanets)
{ {
if (InitializedPlanets.Contains(planet.Id)) return;
Console.WriteLine($"Initializing Planet: {planet.Name}");
await planet.EnsureReadyAsync();
await planet.FetchInitialDataAsync();
foreach (var channel in planet.Channels) foreach (var channel in planet.Channels)
{ {
channelCache[channel.Id] = channel; channelCache[channel.Id] = channel;
Console.WriteLine($"Cached: {channel.Id}");
}
}
await Utils.UpdateValourUserCountAsync(); if (channel.ChannelType == Valour.Shared.Models.ChannelTypeEnum.PlanetChat)
Utils.StartValourUserUpdater(); {
await channel.OpenWithResult("SkyBot");
Console.WriteLine($"Realtime opened for: ${planet.Name} -> {channel.Name}");
}
}
InitializedPlanets.Add(planet.Id);
}
await Task.Delay(5000);
}
});
client.MessageService.MessageReceived += async (message) => client.MessageService.MessageReceived += async (message) =>
{ {
@@ -59,7 +89,7 @@ client.MessageService.MessageReceived += async (message) =>
} }
}; };
var echoprefixes = new[] { "/sky echo", "s/echo"}; var echoprefixes = new[] { "s/echo"};
if (Utils.ContainsAny(content, echoprefixes)) if (Utils.ContainsAny(content, echoprefixes))
{ {
@@ -79,7 +109,7 @@ client.MessageService.MessageReceived += async (message) =>
await Utils.SendReplyAsync(channelCache, channelId, reply); await Utils.SendReplyAsync(channelCache, channelId, reply);
}; };
var echorawprefixes = new[] { "/sky rawecho", "s/rawecho"}; var echorawprefixes = new[] { "s/rawecho"};
if (Utils.ContainsAny(content, echorawprefixes)) if (Utils.ContainsAny(content, echorawprefixes))
{ {
@@ -109,7 +139,7 @@ client.MessageService.MessageReceived += async (message) =>
await Utils.SendReplyAsync(channelCache, channelId, reply); await Utils.SendReplyAsync(channelCache, channelId, reply);
}; };
if (Utils.ContainsAny(content, "/sky valourroadmap", "s/valourroadmap")) if (Utils.ContainsAny(content, "s/valourroadmap"))
{ {
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is the up-to-date roadmap for Valour: await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is the up-to-date roadmap for Valour:
~~1. Screen sharing~~ ~~1. Screen sharing~~
@@ -121,34 +151,38 @@ client.MessageService.MessageReceived += async (message) =>
7. Automod/planet moderation"); 7. Automod/planet moderation");
}; };
if (Utils.ContainsAny(content, "/sky suggest", "s/suggest")) if (Utils.ContainsAny(content, "s/suggest"))
{ {
await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can suggest a command to be added here: https://docs.google.com/spreadsheets/d/1CzcpLAuMiPL_RODrZ5x25cPj8yE-rR3mEnqrd_2Fbmk"); await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can suggest a command to be added here: https://docs.google.com/spreadsheets/d/1CzcpLAuMiPL_RODrZ5x25cPj8yE-rR3mEnqrd_2Fbmk");
}; };
if (Utils.ContainsAny(content, "/sky source", "s/source")) if (Utils.ContainsAny(content, "s/source"))
{ {
await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can see my source code here: https://github.com/SkyJoshua/SkyBot"); await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can see my source code here: https://github.com/SkyJoshua/SkyBot");
}; };
if (Utils.ContainsAny(content, "/sky cmds", "s/cmds")) if (Utils.ContainsAny(content, "s/cmds"))
{ {
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is a list of my commands: await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is a list of my commands:
prefixes can be `/sky` or `s/` `s/echo <text>`
`/sky echo <text>` `s/valourroadmap`
`/sky valourroadmap` `s/suggest`
`/sky suggest` `s/source
`/sky source `s/cmds`
`/sky cmds` `s/usercount`");
`/sky usercount`");
}; };
if (Utils.ContainsAny(content, "/sky usercount", "s/usercount")) if (Utils.ContainsAny(content, "s/usercount"))
{ {
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember}
Current Valour user count is: {Utils.ValourUserCount:N0} Current Valour user count is: {Utils.ValourUserCount:N0}
You can see a graph of the user count here: /meow"); You can see a graph of the user count here: /meow");
}; };
if (Utils.ContainsAny(content, "s/botdev"))
{
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} you can join the Bot Development planet here: ");
}
}; };
Console.WriteLine("Listening for messages..."); Console.WriteLine("Listening for messages...");