From a02ed2d38981e9653f00de43075d923199ae8dc1 Mon Sep 17 00:00:00 2001 From: skyjoshua Date: Sun, 29 Mar 2026 03:39:14 +0100 Subject: [PATCH] final github release --- SkyBot/Commands/CommandTemplate.cs | 11 ++-- SkyBot/Commands/Dev/React.cs | 72 +++++++++++++++++++++++++ SkyBot/Commands/Info/BotGuide.cs | 2 +- SkyBot/Config.cs | 1 - SkyBot/Helpers/MessageHelper.cs | 18 +++++++ SkyBot/Helpers/ValourUsercountHelper.cs | 1 + SkyBot/Services/Messages/Create.cs | 20 +++++-- 7 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 SkyBot/Commands/Dev/React.cs diff --git a/SkyBot/Commands/CommandTemplate.cs b/SkyBot/Commands/CommandTemplate.cs index 9758d30..0a0574f 100644 --- a/SkyBot/Commands/CommandTemplate.cs +++ b/SkyBot/Commands/CommandTemplate.cs @@ -1,6 +1,6 @@ using System.Collections.Concurrent; -using SkyBot.Helpers; using SkyBot.Models; +using Valour.Sdk.Client; using Valour.Sdk.Models; namespace SkyBot.Commands @@ -15,8 +15,13 @@ namespace SkyBot.Commands public async Task Execute(CommandContext ctx) { - ConcurrentDictionary channelCache = ctx.ChannelCache; - long channelId = ctx.ChannelId; + ValourClient Client = ctx.Client; + ConcurrentDictionary channelCache = ctx.ChannelCache; + PlanetMember Member = ctx.Member; + Message Message = ctx.Message; + Planet Planet = ctx.Planet; + long channelId = ctx.ChannelId; + string[] Args = ctx.Args; if (!channelCache.TryGetValue(channelId, out var channel)) return; diff --git a/SkyBot/Commands/Dev/React.cs b/SkyBot/Commands/Dev/React.cs new file mode 100644 index 0000000..e33b6a5 --- /dev/null +++ b/SkyBot/Commands/Dev/React.cs @@ -0,0 +1,72 @@ +using System.Collections.Concurrent; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class React : ICommand + { + public string Name => "react"; + public string[] Aliases => []; + public string Description => "Send a message with a reaction at a set count."; + public string Section => "Dev"; + public string Usage => "react "; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + if (!PermissionHelper.IsOwner(ctx.Member)) + { + await MessageHelper.ReplyAsync(ctx, channel, "This is a Dev only command."); + return; + } + + string[] args = ctx.Args; + + if (args.Length < 3) + { + await MessageHelper.ReplyAsync(ctx, channel, $"Usage: `{Config.Prefix}react `"); + return; + } + + string emoji = args[0]; + + if (!int.TryParse(args[1], out int amount) || amount < 1) + { + await MessageHelper.ReplyAsync(ctx, channel, "Amount must be a number between 1 and 100."); + return; + } + + string content = string.Join(" ", args.Skip(2)); + + var reactions = Enumerable.Range(0, amount) + .Select(_ => new MessageReaction + { + Emoji = emoji, + AuthorUserId = ctx.Client.Me.Id, + AuthorMemberId = ctx.Planet.MyMember?.Id, + CreatedAt = DateTime.UtcNow + }) + .ToList(); + + var msg = new Message(ctx.Client) + { + Content = content, + ChannelId = channelId, + PlanetId = ctx.Planet.Id, + AuthorUserId = ctx.Client.Me.Id, + AuthorMemberId = ctx.Planet.MyMember?.Id, + Reactions = reactions, + Fingerprint = Guid.NewGuid().ToString() + }; + + await ctx.Client.MessageService.SendMessage(msg); + } + } +} diff --git a/SkyBot/Commands/Info/BotGuide.cs b/SkyBot/Commands/Info/BotGuide.cs index c77af39..d928389 100644 --- a/SkyBot/Commands/Info/BotGuide.cs +++ b/SkyBot/Commands/Info/BotGuide.cs @@ -27,7 +27,7 @@ namespace SkyBot.Commands if (!channelCache.TryGetValue(channelId, out var channel)) return; string msg = @"Here is a link to a Bot Guide that SkyJoshua has made (WIP): - https://github.com/SkyJoshua/Valour-Bot-Guide"; + https://git.skyjoshua.xyz/SkyJoshua/Valour-Bot-Guide"; await MessageHelper.ReplyAsync(ctx, channel, msg); } diff --git a/SkyBot/Config.cs b/SkyBot/Config.cs index 62c1c94..6d7142f 100644 --- a/SkyBot/Config.cs +++ b/SkyBot/Config.cs @@ -5,6 +5,5 @@ namespace SkyBot public static readonly long OwnerId = 15652354820931584; public static readonly string Prefix = "s/"; public static readonly string SourceLink = "https://github.com/SkyJoshua/SkyBot"; - } } \ No newline at end of file diff --git a/SkyBot/Helpers/MessageHelper.cs b/SkyBot/Helpers/MessageHelper.cs index bdb543a..7455e79 100644 --- a/SkyBot/Helpers/MessageHelper.cs +++ b/SkyBot/Helpers/MessageHelper.cs @@ -1,3 +1,4 @@ +using System.Globalization; using SkyBot.Models; using Valour.Sdk.Models; using Valour.Shared; @@ -10,6 +11,7 @@ namespace SkyBot.Helpers public static string Mention(this PlanetMember member) => $"«@m-{member.Id}»"; public static string Mention(this User user) => $"«@u-{user.Id}»"; public static string ToTitleCase(this string str) => System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str); + public static async Task> ReplyAsync(CommandContext ctx, Channel channel, string content) { long? replyToId = ctx.Message.ReplyToId.HasValue ? ctx.Message.ReplyToId : ctx.Message.Id; @@ -26,11 +28,13 @@ namespace SkyBot.Helpers }; return await ctx.Client.MessageService.SendMessage(msg); } + public static async Task> EditAsync(Channel channel, Message message, string content) { message.Content = content; return await channel.Planet.Node.PutAsyncWithResponse($"api/messages/{message.Id}", message); } + public static DateTime? ParseDuration(string input) { if (string.IsNullOrWhiteSpace(input)) return null; @@ -49,5 +53,19 @@ namespace SkyBot.Helpers _ => null }; } + + public static bool IsSingleEmoji(string input) + { + if (string.IsNullOrWhiteSpace(input)) return false; + + input = input.Trim(); + + var enumerator = StringInfo.GetTextElementEnumerator(input); + int count = 0; + + while (enumerator.MoveNext()) count++; + + return count == 1; + } } } \ No newline at end of file diff --git a/SkyBot/Helpers/ValourUsercountHelper.cs b/SkyBot/Helpers/ValourUsercountHelper.cs index 514ae6c..2c6948a 100644 --- a/SkyBot/Helpers/ValourUsercountHelper.cs +++ b/SkyBot/Helpers/ValourUsercountHelper.cs @@ -6,6 +6,7 @@ namespace SkyBot.Helpers private static readonly HttpClient _http = new HttpClient(); private static long _valourUsercount; public static long ValourUsercount => _valourUsercount; + public static async Task UpdateUsercount() { try diff --git a/SkyBot/Services/Messages/Create.cs b/SkyBot/Services/Messages/Create.cs index 4fed14d..eca7d5b 100644 --- a/SkyBot/Services/Messages/Create.cs +++ b/SkyBot/Services/Messages/Create.cs @@ -23,16 +23,13 @@ namespace SkyBot.Services.Messages string prefix = Config.Prefix; string content = message.Content ?? ""; if (string.IsNullOrWhiteSpace(content)) return; - if (!content.ToLower().StartsWith(prefix)) return; - long channelId = message.ChannelId; PlanetMember member = await message.FetchAuthorMemberAsync(); + noPrefixMessages(message, content); var parts = content.Substring(prefix.Length).Split(' ', StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) return; - string command = parts[0].ToLower(); string[] args = parts[1..]; - CommandContext ctx = new CommandContext { ChannelCache = channelCache, @@ -44,6 +41,21 @@ namespace SkyBot.Services.Messages Client = client }; + async void noPrefixMessages(Message message, string content) + { + if (message.AuthorUserId == Config.OwnerId) + { + if (MessageHelper.IsSingleEmoji(content)) + { + await message.AddReactionAsync(content); + } + } + + // await message.AddReactionAsync("🫃"); + } + + + if (!content.ToLower().StartsWith(prefix)) return; if (_cooldowns.TryGetValue(message.AuthorUserId, out var lastUsed) && DateTime.UtcNow - lastUsed < _cooldown) return;