From e13c2390a6d6767bcf9eea4fd8cf4179de8f027f Mon Sep 17 00:00:00 2001 From: FloatingMilkshake Date: Mon, 28 Oct 2024 08:21:36 -0400 Subject: [PATCH 01/13] Convert Cyrillic lookalikes to Latin in everyone/here check --- Checks/ListChecks.cs | 2 +- Events/MessageEvent.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Checks/ListChecks.cs b/Checks/ListChecks.cs index adba8e64..6e75a749 100644 --- a/Checks/ListChecks.cs +++ b/Checks/ListChecks.cs @@ -6,7 +6,7 @@ public class ListChecks { // Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes // is - static Dictionary alphabetMap = new() + public static Dictionary alphabetMap = new() { { "А", "A" }, { "В", "B" }, diff --git a/Events/MessageEvent.cs b/Events/MessageEvent.cs index 0fb32154..5ffbe772 100644 --- a/Events/MessageEvent.cs +++ b/Events/MessageEvent.cs @@ -640,7 +640,10 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe } // attempted to ping @everyone/@here - if (Program.cfgjson.EveryoneFilter && !member.Roles.Any(role => Program.cfgjson.EveryoneExcludedRoles.Contains(role.Id)) && !Program.cfgjson.EveryoneExcludedChannels.Contains(channel.Id) && (message.Content.Contains("@everyone") || message.Content.Contains("@here"))) + var msgContent = message.Content; + foreach (var letter in Checks.ListChecks.alphabetMap) + msgContent = msgContent.Replace(letter.Key, letter.Value); + if (Program.cfgjson.EveryoneFilter && !member.Roles.Any(role => Program.cfgjson.EveryoneExcludedRoles.Contains(role.Id)) && !Program.cfgjson.EveryoneExcludedChannels.Contains(channel.Id) && (msgContent.Contains("@everyone") || msgContent.Contains("@here"))) { if (wasAutoModBlock) { From a4e2c46709d08fb7ab659866130c26c2343fce89 Mon Sep 17 00:00:00 2001 From: FloatingMilkshake Date: Mon, 28 Oct 2024 15:12:33 -0400 Subject: [PATCH 02/13] /warn: Handle invalid reply msg ID --- Commands/InteractionCommands/WarningInteractions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Commands/InteractionCommands/WarningInteractions.cs b/Commands/InteractionCommands/WarningInteractions.cs index 6684968b..7b16fda5 100644 --- a/Commands/InteractionCommands/WarningInteractions.cs +++ b/Commands/InteractionCommands/WarningInteractions.cs @@ -48,7 +48,14 @@ public async Task WarnSlashCommand(InteractionContext ctx, .WithContent($"{Program.cfgjson.Emoji.Warning} {user.Mention} was warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**"); if (replyMsgId != "0") - messageBuild.WithReply(Convert.ToUInt64(replyMsgId), true, false); + { + if (!ulong.TryParse(replyMsgId, out var msgId)) + { + await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} Invalid reply message ID! Please try again.").AsEphemeral(true)); + return; + } + messageBuild.WithReply(msgId, true, false); + } var msg = await channel.SendMessageAsync(messageBuild); From c3aab31b824432d57d9d7c43bb5b8f17d98646ea Mon Sep 17 00:00:00 2001 From: GitHub Actions via Discord user floatingmilkshake <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:24:05 +0000 Subject: [PATCH 03/13] floatingmilkshake: Update scams.txt --- Lists/scams.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lists/scams.txt b/Lists/scams.txt index ef6f9feb..2b3ea568 100644 --- a/Lists/scams.txt +++ b/Lists/scams.txt @@ -526,3 +526,7 @@ I'm looking for someone who can help my work. To make massive sales like $10k weekly with this wonderful opportunity reach out to me to know more about it. Together we succeed $Become the best Trader with us +📊Become a successful trader.📊 +TradingView Premium +AtlasVPN+IPTVPlayer +repackme8 From 14460d6c097de7c2ebd939b4ceadebc9c99ead04 Mon Sep 17 00:00:00 2001 From: Erisa A Date: Fri, 1 Nov 2024 20:10:20 +0000 Subject: [PATCH 04/13] DiscordSink: wait for exceptions to propagate Fixes #237 --- Helpers/DiscordSink.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Helpers/DiscordSink.cs b/Helpers/DiscordSink.cs index a7a3042e..35d0a6e0 100644 --- a/Helpers/DiscordSink.cs +++ b/Helpers/DiscordSink.cs @@ -19,6 +19,11 @@ public DiscordSink(ITextFormatter textFormatter) public async void Emit(LogEvent logEvent) { + // wait for exceptions to propagate + // TODO(erisa): find a better way to do this + if (logEvent.Exception is not null ) + await Task.Delay(100); + if (logEvent is null) throw new ArgumentNullException(nameof(logEvent)); lock (_syncRoot) { From d4ba0c4a3ef0e3626e1afac8050c3a30ec6e035c Mon Sep 17 00:00:00 2001 From: Erisa A Date: Sun, 3 Nov 2024 21:07:17 +0000 Subject: [PATCH 05/13] Remove in-memory logger --- Commands/Debug.cs | 17 +---------------- Program.cs | 7 ------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Commands/Debug.cs b/Commands/Debug.cs index 83ff050b..4382dc54 100644 --- a/Commands/Debug.cs +++ b/Commands/Debug.cs @@ -168,22 +168,7 @@ public async Task Shell(CommandContext ctx, [RemainingText] string command) [Command("logs")] public async Task Logs(CommandContext ctx) { - if (Program.cfgjson.LogLevel is Level.Verbose) - { - await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Verbose logging is enabled, so the in-memory logger is disabled. Please access the logs through another method."); - return; - } - - await DiscordHelpers.SafeTyping(ctx.Channel); - - string result = Regex.Replace(Program.outputCapture.ToString(), "ghp_[0-9a-zA-Z]{36}", "ghp_REDACTED").Replace(Environment.GetEnvironmentVariable("CLIPTOK_TOKEN"), "REDACTED"); - - if (Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT") is not null) - { - result = result.Replace(Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT"), "REDACTED"); - } - - await ctx.RespondAsync(await StringHelpers.CodeOrHasteBinAsync(result)); + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command has been removed! Please find logs through other means."); } [Command("dumpwarnings"), Description("Dump all warning data. EXTREMELY computationally expensive, use with caution.")] diff --git a/Program.cs b/Program.cs index 7aa3c6f6..c17bef67 100644 --- a/Program.cs +++ b/Program.cs @@ -56,9 +56,6 @@ class Program : BaseCommandModule public static Random rand = new(); public static HasteBinClient hasteUploader; - public static StringBuilder outputStringBuilder = new(16, 200000000); - public static StringWriter outputCapture; - static public readonly HttpClient httpClient = new(); public static List serverApiList = new(); @@ -77,7 +74,6 @@ public static void UpdateLists() static async Task Main(string[] _) { Console.OutputEncoding = Encoding.UTF8; - outputCapture = new(outputStringBuilder); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var logFormat = "[{Timestamp:yyyy-MM-dd HH:mm:ss zzz}] [{Level}] {Message}{NewLine}{Exception}"; @@ -125,9 +121,6 @@ static async Task Main(string[] _) break; } - if (cfgjson.LogLevel is not Level.Verbose) - loggerConfig.WriteTo.TextWriter(outputCapture, outputTemplate: logFormat); - if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null) { loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]); From 1e181dec21466fced2b9314e4b574118b80f6ee0 Mon Sep 17 00:00:00 2001 From: Stratos Date: Mon, 4 Nov 2024 22:00:43 +0200 Subject: [PATCH 06/13] Feat: Accept timestamps as valid date format for the !remindme command (#238) --- Commands/Reminders.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Commands/Reminders.cs b/Commands/Reminders.cs index c152e95a..8e7c31aa 100644 --- a/Commands/Reminders.cs +++ b/Commands/Reminders.cs @@ -36,7 +36,24 @@ public async Task RemindMe( [RemainingText, Description("The text to send when the reminder triggers.")] string reminder ) { - DateTime t = HumanDateParser.HumanDateParser.Parse(timetoParse); + string discordTimestampRegexExp = @"^$"; + Match matchesDiscordTimestamp = Regex.Match(timetoParse, discordTimestampRegexExp); + + + DateTime t; + if (matchesDiscordTimestamp.Success) + { + // parse as timestamp + // Extract the Unix timestamp from the matched pattern + long unixTimestamp = long.Parse(matchesDiscordTimestamp.Groups[1].Value); + // Convert the Unix timestamp to a DateTime object + t = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).DateTime; + } + else + { + t = HumanDateParser.HumanDateParser.Parse(timetoParse); + } + if (t <= DateTime.Now) { await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time can't be in the past!"); @@ -49,6 +66,7 @@ public async Task RemindMe( return; } #endif + string guildId; if (ctx.Channel.IsPrivate) From bb00220ee2eca56de6af659c5b79f5009b2efaee Mon Sep 17 00:00:00 2001 From: Stratos Date: Mon, 4 Nov 2024 23:56:03 +0200 Subject: [PATCH 07/13] Feat: Accept multiple timestamp formats in the remindme cmd (#240) --- Commands/Reminders.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/Reminders.cs b/Commands/Reminders.cs index 8e7c31aa..fba9d24b 100644 --- a/Commands/Reminders.cs +++ b/Commands/Reminders.cs @@ -36,7 +36,7 @@ public async Task RemindMe( [RemainingText, Description("The text to send when the reminder triggers.")] string reminder ) { - string discordTimestampRegexExp = @"^$"; + string discordTimestampRegexExp = @"(?:)?"; Match matchesDiscordTimestamp = Regex.Match(timetoParse, discordTimestampRegexExp); From f3ab43f93e1d4511f78c3569b0ce556e7a76b7ce Mon Sep 17 00:00:00 2001 From: FloatingMilkshake Date: Tue, 5 Nov 2024 17:39:59 -0500 Subject: [PATCH 08/13] Revert PRs #238 and #240 This reverts commits bb00220ee2eca56de6af659c5b79f5009b2efaee and 1e181dec21466fced2b9314e4b574118b80f6ee0. --- Commands/Reminders.cs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Commands/Reminders.cs b/Commands/Reminders.cs index fba9d24b..c152e95a 100644 --- a/Commands/Reminders.cs +++ b/Commands/Reminders.cs @@ -36,24 +36,7 @@ public async Task RemindMe( [RemainingText, Description("The text to send when the reminder triggers.")] string reminder ) { - string discordTimestampRegexExp = @"(?:)?"; - Match matchesDiscordTimestamp = Regex.Match(timetoParse, discordTimestampRegexExp); - - - DateTime t; - if (matchesDiscordTimestamp.Success) - { - // parse as timestamp - // Extract the Unix timestamp from the matched pattern - long unixTimestamp = long.Parse(matchesDiscordTimestamp.Groups[1].Value); - // Convert the Unix timestamp to a DateTime object - t = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).DateTime; - } - else - { - t = HumanDateParser.HumanDateParser.Parse(timetoParse); - } - + DateTime t = HumanDateParser.HumanDateParser.Parse(timetoParse); if (t <= DateTime.Now) { await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time can't be in the past!"); @@ -66,7 +49,6 @@ public async Task RemindMe( return; } #endif - string guildId; if (ctx.Channel.IsPrivate) From 00026ef8b6120605115f029bae7f32346471340e Mon Sep 17 00:00:00 2001 From: Milkshake Date: Tue, 5 Nov 2024 22:32:58 -0500 Subject: [PATCH 09/13] !delwarn: Add aliases !removewarning & !removewarn --- Commands/Warnings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/Warnings.cs b/Commands/Warnings.cs index 196dc199..5f19c08a 100644 --- a/Commands/Warnings.cs +++ b/Commands/Warnings.cs @@ -110,7 +110,7 @@ public async Task WarningCmd( [ Command("delwarn"), Description("Delete a warning that was issued by mistake or later became invalid."), - Aliases("delwarm", "delwam", "deletewarn", "delwarning", "deletewarning"), + Aliases("delwarm", "delwam", "deletewarn", "delwarning", "deletewarning", "removewarning", "removewarn"), HomeServer, RequireHomeserverPerm(ServerPermLevel.TrialModerator) ] public async Task DelwarnCmd( From b8519f556cf0cf724b3db77fddf4344bd981308c Mon Sep 17 00:00:00 2001 From: FloatingMilkshake Date: Thu, 7 Nov 2024 14:34:55 -0500 Subject: [PATCH 10/13] DM relay: Ignore bots; still send autoresponse to blocked users and bots --- Events/DirectMessageEvent.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Events/DirectMessageEvent.cs b/Events/DirectMessageEvent.cs index a91efa3d..abb83616 100644 --- a/Events/DirectMessageEvent.cs +++ b/Events/DirectMessageEvent.cs @@ -4,9 +4,6 @@ public class DirectMessageEvent { public static async void DirectMessageEventHandler(DiscordMessage message) { - // Ignore message if user is blocked - if (await Program.db.SetContainsAsync("dmRelayBlocklist", message.Author.Id)) return; - // Auto-response to contact modmail if DM follows warn/mute and is within configured time limit bool sentAutoresponse = false; @@ -36,6 +33,12 @@ await message.RespondAsync( } } + // Don't relay message if user is a bot (user apps) + if (message.Author.IsBot) return; + + // Don't relay message if user is blocked + if (await Program.db.SetContainsAsync("dmRelayBlocklist", message.Author.Id)) return; + // Log DMs to DM log channel, include note about auto-response if applicable await LogChannelHelper.LogMessageAsync("dms", await DiscordHelpers.GenerateMessageRelay(message, sentAutoresponse: sentAutoresponse)); } From 175a8c640c15ad09d3f3a108bac75656542b4a3f Mon Sep 17 00:00:00 2001 From: GitHub Actions via Discord user erisachu <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:42:26 +0000 Subject: [PATCH 11/13] erisachu: Update scams.txt --- Lists/scams.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lists/scams.txt b/Lists/scams.txt index 2b3ea568..71ff5007 100644 --- a/Lists/scams.txt +++ b/Lists/scams.txt @@ -530,3 +530,6 @@ $Become the best Trader with us TradingView Premium AtlasVPN+IPTVPlayer repackme8 +JPYVouTegYI +nolerawin.com +?promo=TOWER10 From f824f9798da90afda6daac1bb54496903c84d7e8 Mon Sep 17 00:00:00 2001 From: Erisa A Date: Tue, 12 Nov 2024 19:31:58 +0000 Subject: [PATCH 12/13] Retarget to .NET 9.0.0 --- Cliptok.csproj | 13 +++++++++---- Dockerfile | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cliptok.csproj b/Cliptok.csproj index a4c9f6a0..1ecafdd9 100644 --- a/Cliptok.csproj +++ b/Cliptok.csproj @@ -2,8 +2,8 @@ Exe - net8.0 - 12.0 + net9.0 + 13.0 d9345310-5908-4697-8613-28a24d06d183