From 2f2a6edf5db934c8658d29fbbe6c3054a1cda840 Mon Sep 17 00:00:00 2001 From: skyjoshua Date: Fri, 27 Feb 2026 23:50:57 +0000 Subject: [PATCH] More consistant channel getting --- .gitignore | 5 ++++ Program.cs | 84 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..304f7ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +SkyBot.sln +.env +Program.cs.old diff --git a/Program.cs b/Program.cs index 270ab87..eaea826 100644 --- a/Program.cs +++ b/Program.cs @@ -2,11 +2,12 @@ using Valour.Sdk.Client; using Valour.Sdk.Models; using DotNetEnv; using SkyBot; +using Valour.Sdk.Services; +using System.Net.NetworkInformation; Env.Load(); var token = Environment.GetEnvironmentVariable("TOKEN"); -var channelCache = new Dictionary(); var allowedUserIds = new List { 15652354820931584 }; var client = new ValourClient("https://api.valour.gg/"); @@ -26,19 +27,48 @@ if (!loginResult.Success) } Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})"); -await client.BotService.JoinAllChannelsAsync(); -foreach (var planet in client.PlanetService.JoinedPlanets) -{ - foreach (var channel in planet.Channels) - { - channelCache[channel.Id] = channel; - Console.WriteLine($"Cached: {channel.Id}"); - } -} - await Utils.UpdateValourUserCountAsync(); Utils.StartValourUserUpdater(); + +//Dictionaries +var channelCache = new Dictionary(); +var InitializedPlanets = new HashSet(); + + + + +_ = Task.Run(async () => +{ + while (true) + { + 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) + { + 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); + } + await Task.Delay(5000); + } +}); + + client.MessageService.MessageReceived += async (message) => { string content = message.Content ?? ""; @@ -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)) { @@ -79,7 +109,7 @@ client.MessageService.MessageReceived += async (message) => await Utils.SendReplyAsync(channelCache, channelId, reply); }; - var echorawprefixes = new[] { "/sky rawecho", "s/rawecho"}; + var echorawprefixes = new[] { "s/rawecho"}; if (Utils.ContainsAny(content, echorawprefixes)) { @@ -109,7 +139,7 @@ client.MessageService.MessageReceived += async (message) => 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: ~~1. Screen sharing~~ @@ -121,34 +151,38 @@ client.MessageService.MessageReceived += async (message) => 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"); }; - 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"); }; - 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: - prefixes can be `/sky` or `s/` - `/sky echo ` - `/sky valourroadmap` - `/sky suggest` - `/sky source - `/sky cmds` - `/sky usercount`"); + `s/echo ` + `s/valourroadmap` + `s/suggest` + `s/source + `s/cmds` + `s/usercount`"); }; - if (Utils.ContainsAny(content, "/sky usercount", "s/usercount")) + if (Utils.ContainsAny(content, "s/usercount")) { await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Current Valour user count is: {Utils.ValourUserCount:N0} 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...");