From 86f30b6e17cb8a61fc46ca68a1b0e2bb2d56f619 Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 18 Dec 2023 11:04:48 +0000 Subject: [PATCH 1/8] Various buf fixes noted over the last couple years (see PR for details) --- Floofbot/Modules/Administration.cs | 295 +++++++++++++++++---- Floofbot/Modules/Fun.cs | 66 +++-- Floofbot/Modules/Help.cs | 10 +- Floofbot/Services/RaidProtectionService.cs | 2 +- 4 files changed, 300 insertions(+), 73 deletions(-) diff --git a/Floofbot/Modules/Administration.cs b/Floofbot/Modules/Administration.cs index be1fa5d6..46e962a8 100644 --- a/Floofbot/Modules/Administration.cs +++ b/Floofbot/Modules/Administration.cs @@ -13,6 +13,8 @@ using Serilog; using System.Drawing.Printing; using Discord.Net; +using System.Security.Cryptography; +using Microsoft.Extensions.Configuration.UserSecrets; namespace Floofbot.Modules { @@ -67,6 +69,17 @@ public async Task YeetUser( } } + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot ban myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to ban yourself."); + return; + } + try { //sends message to user @@ -82,17 +95,81 @@ public async Task YeetUser( await Context.Channel.SendMessageAsync("⚠️ | Unable to DM user to notify them of their ban!"); } - //bans the user - await Context.Guild.AddBanAsync(badUser.Id, 0, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); + try + { + //bans the user + await Context.Guild.AddBanAsync(badUser.Id, 0, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); + + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Banned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", badUser.Id); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); + } + catch + { + await Context.Channel.SendMessageAsync("⚠️ | Unable to ban the user! Check my permissions."); + } - EmbedBuilder modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder.Title = (":shield: User Banned"); - modEmbedBuilder.Color = ADMIN_COLOR; - modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; - modEmbedBuilder.AddField("User ID", badUser.Id); - modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); + } + + [Command("unban")] + [Alias("ub")] + [Summary("Unbans a user from the server")] + [RequireContext(ContextType.Guild)] + [RequireUserPermission(GuildPermission.BanMembers)] + public async Task UnYeetUser([Summary("user")] string user) + { + IUser badUser = resolveUser(user); + ulong userId; + if (badUser == null) + { + if (Regex.IsMatch(user, @"\d{16,}")) + { + userId = Convert.ToUInt64(Regex.Match(user, @"\d{16,}").Value); + } + else + { + await Context.Channel.SendMessageAsync($"⚠️ Could not resolve user: \"{user}\""); + return; + } + } + else + { + userId= badUser.Id; + } + + if (userId == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot unban myself."); + return; + } + if (userId == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to unban yourself."); + return; + } + try + { + await Context.Guild.RemoveBanAsync(userId); // unban user + + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Unbanned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{userId} has been unbanned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", userId); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); + } + catch + { + await Context.Channel.SendMessageAsync("⚠️ Unable to unban user! Please check that they are actually banned from the server."); + return; + } } @@ -138,6 +215,17 @@ public async Task pruneBanUser( } } + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot purge and ban myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to purge and ban yourself."); + return; + } + try { //sends message to user @@ -265,6 +353,18 @@ public async Task kickUser( await Context.Channel.SendMessageAsync($"⚠️ Could not resolve user: \"{user}\""); return; } + + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot kick myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to kick yourself."); + return; + } + try { //sends message to user @@ -280,15 +380,23 @@ public async Task kickUser( await Context.Channel.SendMessageAsync("⚠️ | Unable to DM user to notify them of their kick!"); } - //kicks users - await Context.Guild.GetUser(badUser.Id).KickAsync(reason); - EmbedBuilder kickBuilder = new EmbedBuilder(); - kickBuilder.Title = ("🥾 User Kicked"); - kickBuilder.Color = ADMIN_COLOR; - kickBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been kicked from {Context.Guild.Name}"; - kickBuilder.AddField("User ID", badUser.Id); - kickBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, kickBuilder.Build()); + try + { + //kicks users + await Context.Guild.GetUser(badUser.Id).KickAsync(reason); + EmbedBuilder kickBuilder = new EmbedBuilder(); + kickBuilder.Title = ("🥾 User Kicked"); + kickBuilder.Color = ADMIN_COLOR; + kickBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been kicked from {Context.Guild.Name}"; + kickBuilder.AddField("User ID", badUser.Id); + kickBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, kickBuilder.Build()); + } + catch + { + await Context.Channel.SendMessageAsync("⚠️ | Unable to kick user! Check my permissions."); + return; + } } [Command("silentkick")] @@ -307,15 +415,33 @@ public async Task silentKickUser( return; } - //kicks users - await Context.Guild.GetUser(badUser.Id).KickAsync(reason); - EmbedBuilder kickBuilder = new EmbedBuilder(); - kickBuilder.Title = ("🥾 User Silently Kicked"); - kickBuilder.Color = ADMIN_COLOR; - kickBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been silently kicked from {Context.Guild.Name}"; - kickBuilder.AddField("User ID", badUser.Id); - kickBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, kickBuilder.Build()); + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot kick myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to kick yourself."); + return; + } + try + { + //kicks users + await Context.Guild.GetUser(badUser.Id).KickAsync(reason); + EmbedBuilder kickBuilder = new EmbedBuilder(); + kickBuilder.Title = ("🥾 User Silently Kicked"); + kickBuilder.Color = ADMIN_COLOR; + kickBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been silently kicked from {Context.Guild.Name}"; + kickBuilder.AddField("User ID", badUser.Id); + kickBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, kickBuilder.Build()); + } + catch + { + await Context.Channel.SendMessageAsync("⚠️ | Unable to kick user! Check my permissions."); + return; + } } [Command("warn")] @@ -358,6 +484,16 @@ public async Task warnUser( } else { + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot warn myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to warn yourself."); + return; + } uid = badUser.Id; } @@ -395,6 +531,8 @@ public async Task warnUser( builder = new EmbedBuilder(); builder.Title = (":shield: User Warned"); builder.Color = ADMIN_COLOR; + string badUserIdentifier = (badUser != null) ? $"{badUser.Username}#{badUser.Discriminator}" : $"{uid}"; + builder.Description = $"Warning added for {badUserIdentifier} with reason {reason}"; builder.AddField("User ID", uid); builder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); @@ -441,6 +579,16 @@ public async Task userNote( } else { + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot add usernotes for myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to add usernotes to yourself."); + return; + } uid = badUser.Id; } @@ -458,6 +606,8 @@ public async Task userNote( builder = new EmbedBuilder(); builder.Title = (":pencil: User Note Added"); builder.Color = ADMIN_COLOR; + string badUserIdentifier = (badUser != null) ? $"{badUser.Username}#{badUser.Discriminator}" : $"{uid}"; + builder.Description = $"Usernote added for {badUserIdentifier} with reason {reason}"; builder.AddField("User ID", uid); builder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); @@ -480,7 +630,7 @@ public async Task PurgeUserMessages( { userId = Regex.Match(user, @"\d{16,}").Value; } - else + else { await Context.Channel.SendMessageAsync("⚠️ Cannot find user"); return; @@ -488,9 +638,18 @@ public async Task PurgeUserMessages( } else { + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot purge my own messages."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot purge your own messages."); + return; + } userId = badUser.Id.ToString(); } - // retrieve user messages from ALL channels foreach (ISocketMessageChannel channel in Context.Guild.TextChannels) { @@ -501,8 +660,11 @@ public async Task PurgeUserMessages( { if (message.Author.Id.ToString() == userId) { - await channel.DeleteMessageAsync(message); - await Task.Delay(100); // helps reduce the risk of getting rate limited by the API + if (message != null) + { + await channel.DeleteMessageAsync(message); + await Task.Delay(100); // helps reduce the risk of getting rate limited by the API + } } } } @@ -511,6 +673,8 @@ public async Task PurgeUserMessages( EmbedBuilder builder = new EmbedBuilder(); builder.Title = (":shield: Messages Purged"); builder.Color = ADMIN_COLOR; + string badUserIdentifier = (badUser != null) ? $"{badUser.Username}#{badUser.Discriminator}" : $"{userId}"; + builder.Description = $"{badUser.Username}#{badUser.Discriminator}'s messages were purged"; builder.AddField("User ID", badUser.Id); builder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); @@ -537,7 +701,7 @@ public async Task warnlog([Summary("user")] string user = "") } else // a mod { - if (selfUser.GuildPermissions.KickMembers) // want to view their own warnlog + if (selfUser.GuildPermissions.KickMembers) // moderator wants to view a warnlog { IUser badUser = resolveUser(user); if (badUser == null) @@ -549,7 +713,14 @@ public async Task warnlog([Summary("user")] string user = "") return; } else + { + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ You cannot view my warnlog."); + return; + } embed = GetWarnings(badUser.Id, false); + } if (embed == null) { return; @@ -584,6 +755,20 @@ public async Task unforgiveUser([Summary("warning/usernote")] string type = "", await UpdateForgivenStatus("unforgiven", type, badUser); } + [Command("userid")] + [Summary("Displays the ID of the specified user. If no parameters are given, displays the user's own ID")] + [RequireContext(ContextType.Guild)] + [RequireBotPermission(GuildPermission.KickMembers)] + public async Task UserId(IGuildUser usr = null) + { + var user = usr ?? Context.User as IGuildUser; + + if (user == null) + return; + + await Context.Channel.SendMessageAsync(user.Id.ToString()); + } + [Command("mute")] [Summary("Applies a mute role to a user")] [RequireContext(ContextType.Guild)] @@ -596,6 +781,17 @@ public async Task MuteUser([Summary("user")]string user, [Summary("Time")]string return; } + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot mute myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to mute yourself."); + return; + } + IRole muteRole; //check to see if the server exists within the "AdminConfig" Table @@ -748,6 +944,17 @@ public async Task UnmuteUser([Summary("user")]string user) return; } + if (badUser.Id == Context.Client.CurrentUser.Id) + { + await Context.Channel.SendMessageAsync("⚠️ I cannot unmute myself."); + return; + } + if (badUser.Id == Context.User.Id) + { + await Context.Channel.SendMessageAsync("⚠️ For safety reasons, I cannot allow you to unmute yourself."); + return; + } + var muteRole = Context.Guild.GetRole( _floofDB.AdminConfig.AsQueryable() .Where(x => x.ServerId == Context.Guild.Id) @@ -1035,27 +1242,15 @@ private Embed GetWarnings(ulong uid, bool isOwnLog) .Where(u => u.UserId == uid && u.GuildId == Context.Guild.Id) .OrderByDescending(x => x.DateAdded).Take(10); } - + string badUserIdentifier = (badUser != null) ? $"{badUser.Username}#{badUser.Discriminator}" : $"{uid}"; if (!isOwnLog) // mod viewing someones history { - if (badUser == null) // client cant get user - no mutual servers? - { if (formalWarnings.Count() == 0 && userNotes.Count() == 0) { - string message = $"{uid} is a good noodle. They have no warnings or user notes!"; + string message = $"{badUserIdentifier} is a good noodle. They have no warnings or user notes!"; var embed = CreateDescriptionEmbed(message); return embed; } - } - else - { - if (formalWarnings.Count() == 0 && userNotes.Count() == 0) - { - string message = $"{badUser.Username}#{badUser.Discriminator} is a good noodle. They have no warnings or user notes!"; - var embed = CreateDescriptionEmbed(message); - return embed; - } - } } else // own users history { @@ -1072,10 +1267,8 @@ private Embed GetWarnings(ulong uid, bool isOwnLog) int warningCount = 0; int userNoteCount = 0; - if (badUser == null && !isOwnLog) // no user, just id in database - builder.WithTitle($"Warnings for {uid}"); - else if (badUser != null && !isOwnLog) - builder.WithTitle($"Warnings for {badUser.Username}#{badUser.Discriminator}"); + if (!isOwnLog) // no user, just id in database + builder.WithTitle($"Warnings for {badUserIdentifier}"); else builder.WithTitle($"Your Warnings"); diff --git a/Floofbot/Modules/Fun.cs b/Floofbot/Modules/Fun.cs index 1051cce9..a08e9b3a 100644 --- a/Floofbot/Modules/Fun.cs +++ b/Floofbot/Modules/Fun.cs @@ -123,14 +123,22 @@ public async Task RequestFoxFact() [Summary("Responds with a random cat")] public async Task RequestCat() { - string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://aws.random.cat/meow", "file"); - if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + try { - await SendAnimalEmbed(":cat:", fileUrl); + string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://aws.random.cat/meow", "file"); + if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + { + await SendAnimalEmbed(":cat:", fileUrl); + } + else + { + await Context.Channel.SendMessageAsync("The cat command is currently unavailable."); + } } - else + catch { await Context.Channel.SendMessageAsync("The cat command is currently unavailable."); + return; } } @@ -138,14 +146,22 @@ public async Task RequestCat() [Summary("Responds with a random dog")] public async Task RequestDog() { - string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://random.dog/woof.json", "url"); - if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + try { - await SendAnimalEmbed(":dog:", fileUrl); + string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://random.dog/woof.json", "url"); + if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + { + await SendAnimalEmbed(":dog:", fileUrl); + } + else + { + await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); + } } - else + catch { await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); + return; } } @@ -153,14 +169,22 @@ public async Task RequestDog() [Summary("Responds with a random fox")] public async Task RequestFox() { - string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://wohlsoft.ru/images/foxybot/randomfox.php", "file"); - if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + try { - await SendAnimalEmbed(":fox:", fileUrl); + string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://wohlsoft.ru/images/foxybot/randomfox.php", "file"); + if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Absolute)) + { + await SendAnimalEmbed(":fox:", fileUrl); + } + else + { + await Context.Channel.SendMessageAsync("The fox command is currently unavailable."); + } } - else + catch { await Context.Channel.SendMessageAsync("The fox command is currently unavailable."); + return; } } @@ -168,15 +192,23 @@ public async Task RequestFox() [Summary("Responds with a random birb")] public async Task RequestBirb() { - string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://random.birb.pw/tweet.json", "file"); - if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Relative)) + try { - fileUrl = "https://random.birb.pw/img/" + fileUrl; - await SendAnimalEmbed(":bird:", fileUrl); + string fileUrl = await ApiFetcher.RequestEmbeddableUrlFromApi("https://random.birb.pw/tweet.json", "file"); + if (!string.IsNullOrEmpty(fileUrl) && Uri.IsWellFormedUriString(fileUrl, UriKind.Relative)) + { + fileUrl = "https://random.birb.pw/img/" + fileUrl; + await SendAnimalEmbed(":bird:", fileUrl); + } + else + { + await Context.Channel.SendMessageAsync("The birb command is currently unavailable."); + } } - else + catch { await Context.Channel.SendMessageAsync("The birb command is currently unavailable."); + return; } } diff --git a/Floofbot/Modules/Help.cs b/Floofbot/Modules/Help.cs index 6aee036a..1c33b484 100644 --- a/Floofbot/Modules/Help.cs +++ b/Floofbot/Modules/Help.cs @@ -66,11 +66,13 @@ public async Task HelpCommand() } if (fields.Count > 0) // don't show empty pages { + string strCmdAliases = string.Join(", ", module.Aliases.ToList()); + string cmdAliases = (strCmdAliases != "") ? $"Command Usage: {strCmdAliases}\n\n" : ""; pages.Add(new PaginatedMessage.Page { - Author = new EmbedAuthorBuilder { Name = module.Name }, + Author = new EmbedAuthorBuilder { Name = module.Name}, Fields = new List(fields), - Description = module.Summary ?? "No module description available" + Description = cmdAliases + (module.Summary ?? $"No module description available") }); fields.Clear(); } @@ -113,10 +115,10 @@ public async Task HelpCommand([Summary("module name")] string requestedModule) } pages.Add(new PaginatedMessage.Page { - Author = new EmbedAuthorBuilder { Name = cmd.Name }, + Title = "Command Aliases: " + String.Join(", ", cmd.Aliases.ToList()), Fields = new List(fields), Description = cmd.Summary ?? "No command description available" - }); + }); fields.Clear(); } } diff --git a/Floofbot/Services/RaidProtectionService.cs b/Floofbot/Services/RaidProtectionService.cs index fcec2296..8e8d37ab 100644 --- a/Floofbot/Services/RaidProtectionService.cs +++ b/Floofbot/Services/RaidProtectionService.cs @@ -155,7 +155,7 @@ private bool CheckMessageForFilteredWords(SocketMessage msg, ulong guildId) // we run an async task to remove their point after the specified duration UserPunishmentTimeout(guildId, msg.Author.Id); - SendMessageAndDelete($"{msg.Author.Mention} There was a filtered word in that message. Please be mindful of your language!", msg.Channel); + SendMessageAndDelete($"{msg.Author.Mention} I detected a filtered word in that message and have automatically deleted it.", msg.Channel); Log.Information("User ID " + msg.Author.Id + " triggered the word filter."); From 4350c1cb52eeba7ee3b38493a5bdc5b476087509 Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 18 Dec 2023 11:48:36 +0000 Subject: [PATCH 2/8] Added thread support --- Floofbot/Services/EventHandlerService.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Floofbot/Services/EventHandlerService.cs b/Floofbot/Services/EventHandlerService.cs index 4be7de97..e79494bf 100644 --- a/Floofbot/Services/EventHandlerService.cs +++ b/Floofbot/Services/EventHandlerService.cs @@ -54,6 +54,8 @@ public EventHandlerService(DiscordSocketClient client) _client.MessageReceived += OnMessage; _client.MessageReceived += RulesGate; // rfurry rules gate _client.ReactionAdded += _nicknameAlertService.OnReactionAdded; + _client.ThreadCreated += NewThread; + _client.ThreadUpdated += UpdatedThread; // a list of announcement channels for auto publishing announcementChannels = BotConfigFactory.Config.AnnouncementChannels; @@ -147,6 +149,21 @@ public async Task RulesGate(SocketMessage msg) await userMsg.DeleteAsync(); } } + public async Task NewThread(SocketThreadChannel thread) + { + await thread.JoinAsync(); + return; + } + public async Task UpdatedThread(Cacheable channel, SocketThreadChannel thread) + { + if (thread != null) + { + if (thread.HasJoined != true) + { + await thread.JoinAsync(); + } + } + } public Task OnMessage(SocketMessage msg) { if (msg.Channel.GetType() == typeof(SocketDMChannel)) From a20a3ebe84ae969c77115c47775d17467c76ad0e Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 18 Dec 2023 16:21:51 +0000 Subject: [PATCH 3/8] Enforce SFW FA Links --- Floofbot/Services/RaidProtectionService.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Floofbot/Services/RaidProtectionService.cs b/Floofbot/Services/RaidProtectionService.cs index 8e8d37ab..ab338ae4 100644 --- a/Floofbot/Services/RaidProtectionService.cs +++ b/Floofbot/Services/RaidProtectionService.cs @@ -302,6 +302,16 @@ private bool CheckInviteLinks(SocketMessage msg, ulong guildId) } return false; } + private bool CheckFALinks(SocketMessage msg, ulong guildId) // filter out if not sfw domain but no muting + { + var regex = "(? CheckMessage(FloofDataContext _floofDb, SocketMessage ms bool userSpammedInviteLink = CheckInviteLinks(userMsg, guild.Id); // check for spammed emojis bool userSpammedEmojis = CheckEmojiSpam(userMsg, guild.Id); + // check for FA links without sfw domain + bool userWrongFALink = CheckFALinks(userMsg, guild.Id); if (spammedMentions) return false; // user already banned + if (userWrongFALink) + return true; // user already informed to use sfw domain so finished if (filteredWord || userSpammedMessages || userSpammedLetters || userSpammedInviteLink || userSpammedEmojis) { if (userPunishmentCount[guild.Id].ContainsKey(userMsg.Author.Id)) From 5266ee2af4c2c42ee22855d9008e8e5893363cdf Mon Sep 17 00:00:00 2001 From: ishauny Date: Thu, 21 Dec 2023 11:04:51 +0000 Subject: [PATCH 4/8] Update pb to set default number of days to prune as 7 --- Floofbot/Modules/Administration.cs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Floofbot/Modules/Administration.cs b/Floofbot/Modules/Administration.cs index 46e962a8..51b4410f 100644 --- a/Floofbot/Modules/Administration.cs +++ b/Floofbot/Modules/Administration.cs @@ -180,7 +180,6 @@ public async Task UnYeetUser([Summary("user")] string user) [RequireUserPermission(GuildPermission.BanMembers)] public async Task pruneBanUser( [Summary("user")] string user, - [Summary("Number Of Days To Prune")] int pruneDays = 0, [Summary("reason")][Remainder] string reason = "No Reason Provided") { IUser badUser = resolveUser(user); @@ -240,18 +239,25 @@ public async Task pruneBanUser( { await Context.Channel.SendMessageAsync("⚠️ | Unable to DM user to notify them of their ban!"); } + try + { + //bans the user + await Context.Guild.AddBanAsync(badUser.Id, 7, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); // default 7 days prune - //bans the user - await Context.Guild.AddBanAsync(badUser.Id, pruneDays, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); - - EmbedBuilder modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder.Title = (":shield: User Banned"); - modEmbedBuilder.Color = ADMIN_COLOR; - modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; - modEmbedBuilder.AddField("User ID", badUser.Id); - modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Banned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", badUser.Id); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); + } + catch + { + await Context.Channel.SendMessageAsync("⚠️ | Sorry, I was unable to ban that user!"); + return; + } } [Command("viewautobans")] From 986c161343aa6d57e49e9b710f9fd6fe826f6f15 Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 1 Jan 2024 20:39:34 +0000 Subject: [PATCH 5/8] Removing trailing space in help module and update administration to print-out exception errors --- Floofbot/Modules/Administration.cs | 82 ++++++++++++++---------------- Floofbot/Modules/Help.cs | 2 +- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Floofbot/Modules/Administration.cs b/Floofbot/Modules/Administration.cs index 51b4410f..66eadb6a 100644 --- a/Floofbot/Modules/Administration.cs +++ b/Floofbot/Modules/Administration.cs @@ -99,21 +99,20 @@ public async Task YeetUser( { //bans the user await Context.Guild.AddBanAsync(badUser.Id, 0, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); - - EmbedBuilder modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder.Title = (":shield: User Banned"); - modEmbedBuilder.Color = ADMIN_COLOR; - modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; - modEmbedBuilder.AddField("User ID", badUser.Id); - modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } - catch + catch (Exception ex) { - await Context.Channel.SendMessageAsync("⚠️ | Unable to ban the user! Check my permissions."); + await Context.Channel.SendMessageAsync("Command unable to be performed sucessfully: " + ex.ToString()); + return; } - + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Banned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", badUser.Id); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } [Command("unban")] @@ -155,22 +154,20 @@ public async Task UnYeetUser([Summary("user")] string user) try { await Context.Guild.RemoveBanAsync(userId); // unban user - - EmbedBuilder modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder.Title = (":shield: User Unbanned"); - modEmbedBuilder.Color = ADMIN_COLOR; - modEmbedBuilder.Description = $"{userId} has been unbanned from {Context.Guild.Name}"; - modEmbedBuilder.AddField("User ID", userId); - modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } - catch + catch (Exception ex) { - await Context.Channel.SendMessageAsync("⚠️ Unable to unban user! Please check that they are actually banned from the server."); + await Context.Channel.SendMessageAsync("Command unable to be performed sucessfully: " + ex.ToString()); return; } - + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Unbanned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{userId} has been unbanned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", userId); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } [Command("pruneban")] @@ -243,21 +240,20 @@ public async Task pruneBanUser( { //bans the user await Context.Guild.AddBanAsync(badUser.Id, 7, $"{Context.User.Username}#{Context.User.Discriminator} -> {reason}"); // default 7 days prune - - EmbedBuilder modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder = new EmbedBuilder(); - modEmbedBuilder.Title = (":shield: User Banned"); - modEmbedBuilder.Color = ADMIN_COLOR; - modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; - modEmbedBuilder.AddField("User ID", badUser.Id); - modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); - await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } - catch + catch (Exception ex) { - await Context.Channel.SendMessageAsync("⚠️ | Sorry, I was unable to ban that user!"); + await Context.Channel.SendMessageAsync("Command unable to be performed sucessfully: " + ex.ToString()); return; } + EmbedBuilder modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder = new EmbedBuilder(); + modEmbedBuilder.Title = (":shield: User Banned"); + modEmbedBuilder.Color = ADMIN_COLOR; + modEmbedBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been banned from {Context.Guild.Name}"; + modEmbedBuilder.AddField("User ID", badUser.Id); + modEmbedBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); + await Context.Channel.SendMessageAsync("", false, modEmbedBuilder.Build()); } [Command("viewautobans")] @@ -435,19 +431,19 @@ public async Task silentKickUser( { //kicks users await Context.Guild.GetUser(badUser.Id).KickAsync(reason); - EmbedBuilder kickBuilder = new EmbedBuilder(); + } + catch (Exception ex) + { + await Context.Channel.SendMessageAsync("Command unable to be performed sucessfully: " + ex.ToString()); + return; + } + EmbedBuilder kickBuilder = new EmbedBuilder(); kickBuilder.Title = ("🥾 User Silently Kicked"); kickBuilder.Color = ADMIN_COLOR; kickBuilder.Description = $"{badUser.Username}#{badUser.Discriminator} has been silently kicked from {Context.Guild.Name}"; kickBuilder.AddField("User ID", badUser.Id); kickBuilder.AddField("Moderator", $"{Context.User.Username}#{Context.User.Discriminator}"); await Context.Channel.SendMessageAsync("", false, kickBuilder.Build()); - } - catch - { - await Context.Channel.SendMessageAsync("⚠️ | Unable to kick user! Check my permissions."); - return; - } } [Command("warn")] @@ -1210,7 +1206,7 @@ private async Task UpdateForgivenStatus(string function, string type, string bad } catch (Exception ex) { - await Context.Channel.SendMessageAsync(ex.ToString()); + await Context.Channel.SendMessageAsync("Command unable to be performed sucessfully: " + ex.ToString()); } } private async Task SetWarningForgivenStatus(Warning w, bool status, ulong forgivenBy) diff --git a/Floofbot/Modules/Help.cs b/Floofbot/Modules/Help.cs index 1c33b484..91af2bad 100644 --- a/Floofbot/Modules/Help.cs +++ b/Floofbot/Modules/Help.cs @@ -118,7 +118,7 @@ public async Task HelpCommand([Summary("module name")] string requestedModule) Title = "Command Aliases: " + String.Join(", ", cmd.Aliases.ToList()), Fields = new List(fields), Description = cmd.Summary ?? "No command description available" - }); + }); fields.Clear(); } } From 8d63416e8868fb636ad8ff047622e58e1316b917 Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 1 Jan 2024 20:46:20 +0000 Subject: [PATCH 6/8] update command to log exception error --- Floofbot/Modules/Fun.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Floofbot/Modules/Fun.cs b/Floofbot/Modules/Fun.cs index a08e9b3a..d29dc712 100644 --- a/Floofbot/Modules/Fun.cs +++ b/Floofbot/Modules/Fun.cs @@ -1,6 +1,7 @@ using Discord; using Discord.Commands; using Floofbot.Modules.Helpers; +using Serilog; using System; using System.Linq; using System.Text.Json; @@ -135,9 +136,10 @@ public async Task RequestCat() await Context.Channel.SendMessageAsync("The cat command is currently unavailable."); } } - catch + catch (Exception ex) { - await Context.Channel.SendMessageAsync("The cat command is currently unavailable."); + await Context.Channel.SendMessageAsync("The cat command is currently unavailable"); + Log.Error(ex.ToString()); return; } } @@ -158,9 +160,10 @@ public async Task RequestDog() await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); } } - catch + catch (Exception ex) { await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); + Log.Error(ex.ToString()); return; } } From 92c6e5c6508b6c7ced2081621be7363e3a9e4cea Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 1 Jan 2024 20:49:29 +0000 Subject: [PATCH 7/8] Added additional exception handlers to other fun commands --- Floofbot/Modules/Fun.cs | 42 ++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Floofbot/Modules/Fun.cs b/Floofbot/Modules/Fun.cs index d29dc712..886d5b37 100644 --- a/Floofbot/Modules/Fun.cs +++ b/Floofbot/Modules/Fun.cs @@ -94,14 +94,23 @@ public async Task RollDice([Summary("dice")] string diceStr = "") [Summary("Responds with a random cat fact")] public async Task RequestCatFact() { - string fact = await ApiFetcher.RequestStringFromApi("https://catfact.ninja/fact", "fact"); - if (!string.IsNullOrEmpty(fact)) + try { - await Context.Channel.SendMessageAsync(fact); + string fact = await ApiFetcher.RequestStringFromApi("https://catfact.ninja/fact", "fact"); + if (!string.IsNullOrEmpty(fact)) + { + await Context.Channel.SendMessageAsync(fact); + } + else + { + await Context.Channel.SendMessageAsync("The catfact command is currently unavailable."); + } } - else + catch (Exception ex) { await Context.Channel.SendMessageAsync("The catfact command is currently unavailable."); + Log.Error(ex.ToString()); + return; } } @@ -109,14 +118,23 @@ public async Task RequestCatFact() [Summary("Responds with a random fox fact")] public async Task RequestFoxFact() { - string fact = await ApiFetcher.RequestStringFromApi("https://some-random-api.ml/facts/fox", "fact"); - if (!string.IsNullOrEmpty(fact)) + try { - await Context.Channel.SendMessageAsync(fact); + string fact = await ApiFetcher.RequestStringFromApi("https://some-random-api.ml/facts/fox", "fact"); + if (!string.IsNullOrEmpty(fact)) + { + await Context.Channel.SendMessageAsync(fact); + } + else + { + await Context.Channel.SendMessageAsync("The foxfact command is currently unavailable."); + } } - else + catch (Exception ex) { await Context.Channel.SendMessageAsync("The foxfact command is currently unavailable."); + Log.Error(ex.ToString()); + return; } } @@ -163,7 +181,7 @@ public async Task RequestDog() catch (Exception ex) { await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); - Log.Error(ex.ToString()); + Log.Error(ex.ToString()) return; } } @@ -184,9 +202,10 @@ public async Task RequestFox() await Context.Channel.SendMessageAsync("The fox command is currently unavailable."); } } - catch + catch (Exception ex) { await Context.Channel.SendMessageAsync("The fox command is currently unavailable."); + Log.Error(ex.ToString()); return; } } @@ -208,9 +227,10 @@ public async Task RequestBirb() await Context.Channel.SendMessageAsync("The birb command is currently unavailable."); } } - catch + catch (Exception ex) { await Context.Channel.SendMessageAsync("The birb command is currently unavailable."); + Log.Error(ex.ToString()); return; } } From 7d13fc31a657eefe352304f4c595c6220e7b255c Mon Sep 17 00:00:00 2001 From: ishauny Date: Mon, 1 Jan 2024 20:49:54 +0000 Subject: [PATCH 8/8] Fix missing semi-colon --- Floofbot/Modules/Fun.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Floofbot/Modules/Fun.cs b/Floofbot/Modules/Fun.cs index 886d5b37..9257aba9 100644 --- a/Floofbot/Modules/Fun.cs +++ b/Floofbot/Modules/Fun.cs @@ -181,7 +181,7 @@ public async Task RequestDog() catch (Exception ex) { await Context.Channel.SendMessageAsync("The dog command is currently unavailable."); - Log.Error(ex.ToString()) + Log.Error(ex.ToString()); return; } }