From 9589447019d54513e82ae6fb4d9fc38c64b8bfee Mon Sep 17 00:00:00 2001 From: skyjoshua Date: Thu, 26 Feb 2026 22:25:14 +0000 Subject: [PATCH] Added a few things. --- Program.cs | 88 +++++++++++++++++++++++++++++++++++++++++------------- utils.cs | 35 ++++++++++++++++++++++ 2 files changed, 102 insertions(+), 21 deletions(-) diff --git a/Program.cs b/Program.cs index ee637b4..f4485f2 100644 --- a/Program.cs +++ b/Program.cs @@ -5,10 +5,13 @@ using SkyBot; Env.Load(); +var token = Environment.GetEnvironmentVariable("TOKEN"); +var channelCache = new Dictionary(); +var allowedUserIds = new List { 15652354820931584 }; + var client = new ValourClient("https://api.valour.gg/"); client.SetupHttpClient(); -var token = Environment.GetEnvironmentVariable("TOKEN"); if (string.IsNullOrWhiteSpace(token)) { Console.WriteLine("TOKEN environment variable not set."); @@ -21,11 +24,9 @@ if (!loginResult.Success) Console.WriteLine($"Login Failed: {loginResult.Message}"); return; } +Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})"); await client.BotService.JoinAllChannelsAsync(); - -var channelCache = new Dictionary(); - foreach (var planet in client.PlanetService.JoinedPlanets) { foreach (var channel in planet.Channels) @@ -35,39 +36,70 @@ foreach (var planet in client.PlanetService.JoinedPlanets) } } -Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})"); - -var allowedUserIds = new List { 15652354820931584 }; +await Utils.UpdateValourUserCountAsync(); +Utils.StartValourUserUpdater(); client.MessageService.MessageReceived += async (message) => { - string content = message.Content ?? ""; long channelId = message.ChannelId; var member = await message.FetchAuthorMemberAsync(); + var pingMember = $"«@m-{member.Id}»"; if (content is null) return; if (message.AuthorUserId == client.Me.Id) return; + if (allowedUserIds.Contains(message.AuthorUserId)) { if (Utils.IsSingleEmoji(content)) { await message.AddReactionAsync(content); } - } + }; - if (content.StartsWith("/sky echo")) + var echoprefixes = new[] { "/sky echo", "s/echo"}; + if (Utils.ContainsAny(content, echoprefixes)) { - // if (message.AuthorUserId != 15652354820931584) await Utils.SendReplyAsync(channelCache, channelId, "You dont have permission to use this command."); + var matchedPrefix = echoprefixes.First(p => content.StartsWith(p, StringComparison.OrdinalIgnoreCase)); - var reply = content.Substring(10); + var reply = content.Substring(matchedPrefix.Length).TrimStart(); - if (reply is null) await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» Enter a message to echo."); + if (string.IsNullOrWhiteSpace(reply)) await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} Enter a message to echo."); - reply = $"«@m-{member.Id}» {reply}"; + reply = $"{pingMember} {reply}"; + + if (reply.Length > 2048) + { + reply = reply.Substring(0, 2048); + } + + await Utils.SendReplyAsync(channelCache, channelId, reply); + }; + + var echorawprefixes = new[] { "/sky rawecho", "s/rawecho"}; + if (Utils.ContainsAny(content, echorawprefixes)) + { + + if (message.AuthorUserId != 15652354820931584) + { + await Utils.SendReplyAsync(channelCache, channelId, "You do not have permission to execute this command."); + return; + } + + var matchedPrefix = echorawprefixes.First(p => content.StartsWith(p, StringComparison.OrdinalIgnoreCase)); + + var reply = content.Substring(matchedPrefix.Length).TrimStart(); + + if (string.IsNullOrWhiteSpace(reply)) + { + await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} Enter a message to echo."); + return; + } + + reply = $"{reply}"; if (reply.Length > 2048) { @@ -79,7 +111,7 @@ client.MessageService.MessageReceived += async (message) => if (Utils.ContainsAny(content, "/sky valourroadmap", "s/valourroadmap")) { - await Utils.SendReplyAsync(channelCache, channelId, @$"«@m-{member.Id}» 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~~ 2. Documentation 3. Themes Improvements @@ -87,21 +119,35 @@ client.MessageService.MessageReceived += async (message) => 5. Windows native bugs 6. Tab system bugs 7. Automod/planet moderation"); - } + }; - if (Utils.ContainsAny(content, "/sky suggestcommand", "/sky suggestcommands", "/sky suggest", "s/suggestcommand", "s/suggestcommands", "s/suggest")) + if (Utils.ContainsAny(content, "/sky suggestcommand", "/sky suggest", "s/suggestcommand", "s/suggest")) { - await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» 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", "/sky github", "s/source", "s/github")) { - await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» 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 test")) + if (Utils.ContainsAny(content, "/sky commands", "/sky cmds", "s/commands", "s/cmds")) { - await Utils.SendReplyAsync(channelCache, channelId, "test"); + 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|suggestcommand` + `/sky source|github` + `/sky commands|cmds` + `/sky usercount`"); + }; + + if (Utils.ContainsAny(content, "/sky usercount", "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"); }; }; diff --git a/utils.cs b/utils.cs index a814de7..5858b5a 100644 --- a/utils.cs +++ b/utils.cs @@ -1,10 +1,21 @@ using System.Globalization; +using System.Net.NetworkInformation; +using System.Security.Cryptography.X509Certificates; +using System.Text.Json; using Valour.Sdk.Models; namespace SkyBot { public static class Utils { + + private static readonly HttpClient _http = new HttpClient(); + private static long _valourUserCount; + + public static long ValourUserCount => _valourUserCount; + + + public static bool IsSingleEmoji(string input) { if (string.IsNullOrWhiteSpace(input)) @@ -45,5 +56,29 @@ namespace SkyBot Console.WriteLine($"Channel {channel} was not found in the cache."); }; } + + public static async Task UpdateValourUserCountAsync() + { + try + { + var response = await _http.GetStringAsync("https://api.valour.gg/api/users/count"); + + _valourUserCount = JsonSerializer.Deserialize(response); + + Console.WriteLine($"Valour user count updated: {_valourUserCount}"); + } + catch (Exception ex) + { + Console.WriteLine($"Failed to update Valour user count: {ex.Message}"); + } + } + + public static void StartValourUserUpdater() + { + var timer = new System.Timers.Timer(300_000); + timer.Elapsed += async (_, _) => await UpdateValourUserCountAsync(); + timer.AutoReset = true; + timer.Start(); + } }; }; \ No newline at end of file