diff --git a/CHANGELOG.md b/CHANGELOG.md index bb9de9696..4bf72b020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o +## [4.3.16] - 24.05.2023 + +### Fixed + +- Fixed missing events from `.logevents` +- Fixed `.log` thread deleted and thread created events not working properly + +## [4.3.15] - 21.05.2023 + +### Fixed + +- Fixed -w 0 in trivia +- Fixed `.rps` amount field in the response +- Fixed `.showembed` output +- Fixed bank award's incorrect output message + ## [4.3.14] - 02.04.2023 ### Fixed diff --git a/docs/placeholders.md b/docs/placeholders.md index 441503c57..2b8a23f93 100644 --- a/docs/placeholders.md +++ b/docs/placeholders.md @@ -68,12 +68,7 @@ Some features have their own specific placeholders which are noted in that featu - `%ban.reason%` - Reason for the ban, if provided - `%ban.duration%` - Duration of the ban in the form Days.Hours:Minutes (6.05:04) -### Bot stats placeholders - -- `%servers%` - Server count bot has joined -- `%users%` - Combined user count on servers the bot has joined - -### Shard stats placeholders +### Shard stats placeholders - `%shard.servercount%` - Server count on current shard - `%shard.usercount%` - Combined user count on current shard @@ -89,6 +84,5 @@ Some features have their own specific placeholders which are noted in that featu - `%rngX-Y%` - Returns a random number between X and Y - `%target%` - Returns anything the user has written after the trigger (only works on Expressions) -- `%img:stuff%` - Returns an `imgur.com` search for "stuff" (only works on Expressions) ![img](https://puu.sh/B7mgI.png) diff --git a/src/Nadeko.Bot.Common/SmartText/SmartEmbedText.cs b/src/Nadeko.Bot.Common/SmartText/SmartEmbedText.cs index f117fb734..ce1f765fc 100644 --- a/src/Nadeko.Bot.Common/SmartText/SmartEmbedText.cs +++ b/src/Nadeko.Bot.Common/SmartText/SmartEmbedText.cs @@ -1,5 +1,6 @@ #nullable disable warnings using SixLabors.ImageSharp.PixelFormats; +using System.Text.Json.Serialization; namespace NadekoBot; @@ -7,14 +8,14 @@ public sealed record SmartEmbedArrayElementText : SmartEmbedTextBase { public string Color { get; init; } = string.Empty; - public SmartEmbedArrayElementText() : base() + public SmartEmbedArrayElementText() { } public SmartEmbedArrayElementText(IEmbed eb) : base(eb) { - + Color = eb.Color is { } c ? new Rgba32(c.R, c.G, c.B).ToHex() : string.Empty; } protected override EmbedBuilder GetEmbedInternal() @@ -63,6 +64,7 @@ public abstract record SmartEmbedTextBase : SmartText public SmartTextEmbedFooter Footer { get; init; } public SmartTextEmbedField[] Fields { get; init; } + [JsonIgnore] public bool IsValid => !string.IsNullOrWhiteSpace(Title) || !string.IsNullOrWhiteSpace(Description) @@ -100,7 +102,7 @@ public abstract record SmartEmbedTextBase : SmartText IconUrl = ef.IconUrl } : null; - + if (eb.Fields.Length > 0) { Fields = eb.Fields.Select(field diff --git a/src/Nadeko.Bot.Common/SmartText/SmartEmbedTextArray.cs b/src/Nadeko.Bot.Common/SmartText/SmartEmbedTextArray.cs index 90e9f6696..889c59f03 100644 --- a/src/Nadeko.Bot.Common/SmartText/SmartEmbedTextArray.cs +++ b/src/Nadeko.Bot.Common/SmartText/SmartEmbedTextArray.cs @@ -1,4 +1,6 @@ #nullable disable +using System.Text.Json.Serialization; + namespace NadekoBot; public sealed record SmartEmbedTextArray : SmartText @@ -6,6 +8,7 @@ public sealed record SmartEmbedTextArray : SmartText public string Content { get; set; } public SmartEmbedArrayElementText[] Embeds { get; set; } + [JsonIgnore] public bool IsValid => Embeds?.All(x => x.IsValid) ?? false; diff --git a/src/Nadeko.Bot.Common/SmartText/SmartText.cs b/src/Nadeko.Bot.Common/SmartText/SmartText.cs index 2fb9f5ac0..daf05b476 100644 --- a/src/Nadeko.Bot.Common/SmartText/SmartText.cs +++ b/src/Nadeko.Bot.Common/SmartText/SmartText.cs @@ -1,16 +1,20 @@ #nullable disable using Newtonsoft.Json.Linq; +using System.Text.Json.Serialization; namespace NadekoBot; public abstract record SmartText { + [JsonIgnore] public bool IsEmbed => this is SmartEmbedText; + [JsonIgnore] public bool IsPlainText => this is SmartPlainText; + [JsonIgnore] public bool IsEmbedArray => this is SmartEmbedTextArray; diff --git a/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommandService.cs b/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommandService.cs index a36ac814f..21a489835 100644 --- a/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommandService.cs +++ b/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommandService.cs @@ -149,9 +149,11 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor { try { - if (sch.HasValue || sch.Value is not IGuildChannel ch) + if (!sch.HasValue) return; + var ch = sch.Value; + if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) || logSetting.ThreadDeletedId is null) return; @@ -164,7 +166,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor await logChannel.EmbedAsync(_eb.Create() .WithOkColor() - .WithTitle("🆕 " + title) + .WithTitle("🗑 " + title) .WithDescription($"{ch.Name} | {ch.Id}") .WithFooter(CurrentTime(ch.Guild))); } @@ -176,15 +178,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor return Task.CompletedTask; } - private Task _client_ThreadCreated(SocketThreadChannel sch) + private Task _client_ThreadCreated(SocketThreadChannel ch) { _ = Task.Run(async () => { try { - if (sch.Guild is not IGuildChannel ch) - return; - if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) || logSetting.ThreadCreatedId is null) return; @@ -455,6 +454,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor case LogType.UserWarned: channelId = logSetting.LogWarnsId = logSetting.LogWarnsId is null ? cid : default; break; + case LogType.ThreadDeleted: + channelId = logSetting.ThreadDeletedId = logSetting.ThreadDeletedId is null ? cid : default; + break; + case LogType.ThreadCreated: + channelId = logSetting.ThreadCreatedId = logSetting.ThreadCreatedId is null ? cid : default; + break; } uow.SaveChanges(); @@ -1266,6 +1271,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor case LogType.UserWarned: id = logSetting.LogWarnsId; break; + case LogType.ThreadCreated: + id = logSetting.ThreadCreatedId; + break; + case LogType.ThreadDeleted: + id = logSetting.ThreadDeletedId; + break; } if (id is null or 0) diff --git a/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommands.cs b/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommands.cs index cec700537..e597b71e0 100644 --- a/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommands.cs +++ b/src/Nadeko.Bot.Modules.Administration/ServerLog/ServerLogCommands.cs @@ -143,6 +143,12 @@ public partial class Administration return l.LogVoicePresenceTTSId; case LogType.UserMuted: return l.UserMutedId; + case LogType.UserWarned: + return l.LogWarnsId; + case LogType.ThreadDeleted: + return l.ThreadDeletedId; + case LogType.ThreadCreated: + return l.ThreadCreatedId; default: return null; } diff --git a/src/Nadeko.Bot.Modules.Gambling/Gambling/Gambling.cs b/src/Nadeko.Bot.Modules.Gambling/Gambling/Gambling.cs index dc8cb7102..5fc6dc089 100644 --- a/src/Nadeko.Bot.Modules.Gambling/Gambling/Gambling.cs +++ b/src/Nadeko.Bot.Modules.Gambling/Gambling/Gambling.cs @@ -841,7 +841,7 @@ public partial class Gambling : GamblingModule else if (result.Result == RpsResultType.Win) { if ((long)result.Won > 0) - embed.AddField(GetText(strs.won), N(amount)); + embed.AddField(GetText(strs.won), N((long)result.Won)); msg = GetText(strs.rps_win(ctx.User.Mention, GetRpsPick(pick), diff --git a/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/Games.cs b/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/Games.cs index a9d4d8b9d..b83d9aa3f 100644 --- a/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/Games.cs +++ b/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/Games.cs @@ -36,7 +36,7 @@ public partial class Games var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args); var config = _gamesConfig.Data; - if (config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement) + if (opts.WinRequirement != 0 && config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement) return; var trivia = new TriviaGame(opts, _cache); diff --git a/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/TriviaGame.cs b/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/TriviaGame.cs index fc463f5e2..45d603a2a 100644 --- a/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/TriviaGame.cs +++ b/src/Nadeko.Bot.Modules.Gambling/Games/Trivia/TriviaGame.cs @@ -157,7 +157,7 @@ public sealed class TriviaGame var isWin = false; // if user won the game, tell the game to stop - if (val >= _opts.WinRequirement) + if (_opts.WinRequirement != 0 && val >= _opts.WinRequirement) { _isStopped = true; isWin = true; diff --git a/src/Nadeko.Bot.Modules.Utility/Utility.cs b/src/Nadeko.Bot.Modules.Utility/Utility.cs index 131ce47e8..5db752068 100644 --- a/src/Nadeko.Bot.Modules.Utility/Utility.cs +++ b/src/Nadeko.Bot.Modules.Utility/Utility.cs @@ -91,7 +91,7 @@ public partial class Utility : NadekoModule var rng = new NadekoRandom(); var arr = await Task.Run(() => socketGuild.Users - .Where(u => u.Activities.FirstOrDefault()?.Name?.ToUpperInvariant() + .Where(u => u.Activities.FirstOrDefault()?.Name?.Trim().ToUpperInvariant() == game) .Select(u => u.Username) .OrderBy(_ => rng.Next()) @@ -547,15 +547,20 @@ public partial class Utility : NadekoModule return; } - var embed = msg.Embeds.FirstOrDefault(); - if (embed is null) + if (!msg.Embeds.Any()) { await ReplyErrorLocalizedAsync(strs.not_found); return; } - var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson(_showEmbedSerializerOptions); - await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\(")); + var json = new SmartEmbedTextArray() + { + Content = msg.Content, + Embeds = msg.Embeds + .Map(x => new SmartEmbedArrayElementText(x)) + }.ToJson(_showEmbedSerializerOptions); + + await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\(")); } [Cmd] @@ -631,4 +636,4 @@ public partial class Utility : NadekoModule else await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled); } -} \ No newline at end of file +}