From 4659da224b4ae6214293e78adc7a6ae91eda9ccb Mon Sep 17 00:00:00 2001 From: Toastie Date: Sun, 22 Sep 2024 14:42:16 +1200 Subject: [PATCH] Updated changelog, version upped to 5.1.9 --- CHANGELOG.md | 13 +++ src/EllieBot/EllieBot.csproj | 6 +- .../Administration/GreetBye/GreetService.cs | 99 ++++++++++--------- 3 files changed, 72 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a217553..321f172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except date format. a-c-f-r-o +## [5.1.9] - 21.09.2024 + +### Fixed + +- Fixed `.greettest`, and other `.*test` commands if you didn't have them enabled. +- Fixed `.greetdmtest` sending messages twice. +- Fixed a serious bug which caused greet messages to be jumbled up, and wrong ones to be sent for the wrong events. + - There is no database issue, all greet messages are safe, the cache was caching any setting every 3 seconds with no regard for the type of the event + - This also caused `.greetdm` messages to not be sent if `.greet` is enabled + - This bug was introduced in 5.1.8. PLEASE UPDATE if you are on 5.1.8 +- Selfhosters only: Fixed marmalade dependency loading + - Note: Make sure to not publish any other DLLs besides the ones you are sure you will need, as there can be version conflicts which didn't happen before. + ## [5.1.8] - 20.09.2024 ### Added diff --git a/src/EllieBot/EllieBot.csproj b/src/EllieBot/EllieBot.csproj index b5ebc03..e68f011 100644 --- a/src/EllieBot/EllieBot.csproj +++ b/src/EllieBot/EllieBot.csproj @@ -4,7 +4,7 @@ enable true en - 5.1.8 + 5.1.9 $(MSBuildProjectDirectory) @@ -129,6 +129,10 @@ Always + + + + diff --git a/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs b/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs index 3d96ce1..70db21f 100644 --- a/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs +++ b/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs @@ -75,11 +75,19 @@ public class GreetService : IEService, IReadyExecutor _client.GuildMemberUpdated += ClientOnGuildMemberUpdated; - var timer = new PeriodicTimer(TimeSpan.FromSeconds(2)); - while (await timer.WaitForNextTickAsync()) + while (true) { - var (conf, user, ch) = await _greetQueue.Reader.ReadAsync(); - await GreetUsers(conf, ch, user); + try + { + var (conf, user, ch) = await _greetQueue.Reader.ReadAsync(); + await GreetUsers(conf, ch, user); + } + catch (Exception ex) + { + Log.Error(ex, "Greet Loop almost crashed. Please report this!"); + } + + await Task.Delay(2016); } } @@ -155,10 +163,11 @@ public class GreetService : IEService, IReadyExecutor return Task.CompletedTask; } - private readonly TypedKey _greetSettingsKey = new("greet_settings"); + private TypedKey GreetSettingsKey(GreetType type) + => new($"greet_settings:{type}"); public async Task GetGreetSettingsAsync(ulong gid, GreetType type) - => await _cache.GetOrAddAsync(_greetSettingsKey, + => await _cache.GetOrAddAsync(GreetSettingsKey(type), () => InternalGetGreetSettingsAsync(gid, type), TimeSpan.FromSeconds(3)); @@ -217,14 +226,6 @@ public class GreetService : IEService, IReadyExecutor } } - - private async Task GreetDmUser(GreetSettings conf, IGuildUser user) - { - var completionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await _greetQueue.Writer.WriteAsync((conf, user, null)); - return await completionSource.Task; - } - private async Task GreetDmUserInternal(GreetSettings conf, IGuildUser user) { try @@ -280,9 +281,9 @@ public class GreetService : IEService, IReadyExecutor { // if there is less than 10 embeds, add an embed with footer only seta.Embeds = seta.Embeds.Append(new SmartEmbedArrayElementText() - { - Footer = CreateFooterSource(user) - }) + { + Footer = CreateFooterSource(user) + }) .ToArray(); } } @@ -311,21 +312,28 @@ public class GreetService : IEService, IReadyExecutor { try { - var conf = await GetGreetSettingsAsync(user.GuildId, GreetType.Greet); - - if (conf is not null && conf.IsEnabled && conf.ChannelId is { } channelId) + if (_enabled[GreetType.Greet].Contains(user.GuildId)) { - var channel = await user.Guild.GetTextChannelAsync(channelId); - if (channel is not null) + var conf = await GetGreetSettingsAsync(user.GuildId, GreetType.Greet); + if (conf?.ChannelId is ulong cid) { - await _greetQueue.Writer.WriteAsync((conf, user, channel)); + var channel = await user.Guild.GetTextChannelAsync(cid); + if (channel is not null) + { + await _greetQueue.Writer.WriteAsync((conf, user, channel)); + } } } - var confDm = await GetGreetSettingsAsync(user.GuildId, GreetType.GreetDm); - if (confDm?.IsEnabled ?? false) - await GreetDmUser(confDm, user); + if (_enabled[GreetType.GreetDm].Contains(user.GuildId)) + { + var confDm = await GetGreetSettingsAsync(user.GuildId, GreetType.GreetDm); + if (confDm is not null) + { + await _greetQueue.Writer.WriteAsync((confDm, user, null)); + } + } } catch { @@ -354,20 +362,20 @@ public class GreetService : IEService, IReadyExecutor { await using var uow = _db.GetDbContext(); var q = uow.GetTable(); - - if(value is null) + + if (value is null) value = !_enabled[greetType].Contains(guildId); if (value is { } v) { await q .InsertOrUpdateAsync(() => new() - { - GuildId = guildId, - GreetType = greetType, - IsEnabled = v, - ChannelId = channelId, - }, + { + GuildId = guildId, + GreetType = greetType, + IsEnabled = v, + ChannelId = channelId, + }, (old) => new() { IsEnabled = v, @@ -397,11 +405,11 @@ public class GreetService : IEService, IReadyExecutor { await uow.GetTable() .InsertOrUpdateAsync(() => new() - { - GuildId = guildId, - GreetType = greetType, - MessageText = message - }, + { + GuildId = guildId, + GreetType = greetType, + MessageText = message + }, x => new() { MessageText = message @@ -427,11 +435,11 @@ public class GreetService : IEService, IReadyExecutor { await uow.GetTable() .InsertOrUpdateAsync(() => new() - { - GuildId = guildId, - GreetType = greetType, - AutoDeleteTimer = timer, - }, + { + GuildId = guildId, + GreetType = greetType, + AutoDeleteTimer = timer, + }, x => new() { AutoDeleteTimer = timer @@ -477,7 +485,8 @@ public class GreetService : IEService, IReadyExecutor { if (conf.GreetType == GreetType.GreetDm) { - return await GreetDmUser(conf, user); + await _greetQueue.Writer.WriteAsync((conf, user, null)); + return true; } if (channel is not ITextChannel ch)