1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 20:13:13 +00:00

Merge branch 'v4' into v5

This commit is contained in:
Kwoth 2023-07-03 05:02:56 +02:00
commit be1d14d095
11 changed files with 66 additions and 25 deletions

View file

@ -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 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 ## [4.3.14] - 02.04.2023
### Fixed ### Fixed

View file

@ -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.reason%` - Reason for the ban, if provided
- `%ban.duration%` - Duration of the ban in the form Days.Hours:Minutes (6.05:04) - `%ban.duration%` - Duration of the ban in the form Days.Hours:Minutes (6.05:04)
### Bot stats placeholders ### Shard stats placeholders
- `%servers%` - Server count bot has joined
- `%users%` - Combined user count on servers the bot has joined
### Shard stats placeholders
- `%shard.servercount%` - Server count on current shard - `%shard.servercount%` - Server count on current shard
- `%shard.usercount%` - Combined user 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 - `%rngX-Y%` - Returns a random number between X and Y
- `%target%` - Returns anything the user has written after the trigger (only works on Expressions) - `%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) ![img](https://puu.sh/B7mgI.png)

View file

@ -1,5 +1,6 @@
#nullable disable warnings #nullable disable warnings
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using System.Text.Json.Serialization;
namespace NadekoBot; namespace NadekoBot;
@ -7,14 +8,14 @@ public sealed record SmartEmbedArrayElementText : SmartEmbedTextBase
{ {
public string Color { get; init; } = string.Empty; public string Color { get; init; } = string.Empty;
public SmartEmbedArrayElementText() : base() public SmartEmbedArrayElementText()
{ {
} }
public SmartEmbedArrayElementText(IEmbed eb) : base(eb) 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() protected override EmbedBuilder GetEmbedInternal()
@ -63,6 +64,7 @@ public abstract record SmartEmbedTextBase : SmartText
public SmartTextEmbedFooter Footer { get; init; } public SmartTextEmbedFooter Footer { get; init; }
public SmartTextEmbedField[] Fields { get; init; } public SmartTextEmbedField[] Fields { get; init; }
[JsonIgnore]
public bool IsValid public bool IsValid
=> !string.IsNullOrWhiteSpace(Title) => !string.IsNullOrWhiteSpace(Title)
|| !string.IsNullOrWhiteSpace(Description) || !string.IsNullOrWhiteSpace(Description)
@ -100,7 +102,7 @@ public abstract record SmartEmbedTextBase : SmartText
IconUrl = ef.IconUrl IconUrl = ef.IconUrl
} }
: null; : null;
if (eb.Fields.Length > 0) if (eb.Fields.Length > 0)
{ {
Fields = eb.Fields.Select(field Fields = eb.Fields.Select(field

View file

@ -1,4 +1,6 @@
#nullable disable #nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot; namespace NadekoBot;
public sealed record SmartEmbedTextArray : SmartText public sealed record SmartEmbedTextArray : SmartText
@ -6,6 +8,7 @@ public sealed record SmartEmbedTextArray : SmartText
public string Content { get; set; } public string Content { get; set; }
public SmartEmbedArrayElementText[] Embeds { get; set; } public SmartEmbedArrayElementText[] Embeds { get; set; }
[JsonIgnore]
public bool IsValid public bool IsValid
=> Embeds?.All(x => x.IsValid) ?? false; => Embeds?.All(x => x.IsValid) ?? false;

View file

@ -1,16 +1,20 @@
#nullable disable #nullable disable
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Text.Json.Serialization;
namespace NadekoBot; namespace NadekoBot;
public abstract record SmartText public abstract record SmartText
{ {
[JsonIgnore]
public bool IsEmbed public bool IsEmbed
=> this is SmartEmbedText; => this is SmartEmbedText;
[JsonIgnore]
public bool IsPlainText public bool IsPlainText
=> this is SmartPlainText; => this is SmartPlainText;
[JsonIgnore]
public bool IsEmbedArray public bool IsEmbedArray
=> this is SmartEmbedTextArray; => this is SmartEmbedTextArray;

View file

@ -149,9 +149,11 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
{ {
try try
{ {
if (sch.HasValue || sch.Value is not IGuildChannel ch) if (!sch.HasValue)
return; return;
var ch = sch.Value;
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|| logSetting.ThreadDeletedId is null) || logSetting.ThreadDeletedId is null)
return; return;
@ -164,7 +166,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
await logChannel.EmbedAsync(_eb.Create() await logChannel.EmbedAsync(_eb.Create()
.WithOkColor() .WithOkColor()
.WithTitle("🆕 " + title) .WithTitle("🗑 " + title)
.WithDescription($"{ch.Name} | {ch.Id}") .WithDescription($"{ch.Name} | {ch.Id}")
.WithFooter(CurrentTime(ch.Guild))); .WithFooter(CurrentTime(ch.Guild)));
} }
@ -176,15 +178,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
return Task.CompletedTask; return Task.CompletedTask;
} }
private Task _client_ThreadCreated(SocketThreadChannel sch) private Task _client_ThreadCreated(SocketThreadChannel ch)
{ {
_ = Task.Run(async () => _ = Task.Run(async () =>
{ {
try try
{ {
if (sch.Guild is not IGuildChannel ch)
return;
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|| logSetting.ThreadCreatedId is null) || logSetting.ThreadCreatedId is null)
return; return;
@ -455,6 +454,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
case LogType.UserWarned: case LogType.UserWarned:
channelId = logSetting.LogWarnsId = logSetting.LogWarnsId is null ? cid : default; channelId = logSetting.LogWarnsId = logSetting.LogWarnsId is null ? cid : default;
break; 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(); uow.SaveChanges();
@ -1266,6 +1271,12 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
case LogType.UserWarned: case LogType.UserWarned:
id = logSetting.LogWarnsId; id = logSetting.LogWarnsId;
break; break;
case LogType.ThreadCreated:
id = logSetting.ThreadCreatedId;
break;
case LogType.ThreadDeleted:
id = logSetting.ThreadDeletedId;
break;
} }
if (id is null or 0) if (id is null or 0)

View file

@ -143,6 +143,12 @@ public partial class Administration
return l.LogVoicePresenceTTSId; return l.LogVoicePresenceTTSId;
case LogType.UserMuted: case LogType.UserMuted:
return l.UserMutedId; return l.UserMutedId;
case LogType.UserWarned:
return l.LogWarnsId;
case LogType.ThreadDeleted:
return l.ThreadDeletedId;
case LogType.ThreadCreated:
return l.ThreadCreatedId;
default: default:
return null; return null;
} }

View file

@ -841,7 +841,7 @@ public partial class Gambling : GamblingModule<GamblingService>
else if (result.Result == RpsResultType.Win) else if (result.Result == RpsResultType.Win)
{ {
if ((long)result.Won > 0) 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, msg = GetText(strs.rps_win(ctx.User.Mention,
GetRpsPick(pick), GetRpsPick(pick),

View file

@ -36,7 +36,7 @@ public partial class Games
var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args); var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args);
var config = _gamesConfig.Data; 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; return;
var trivia = new TriviaGame(opts, _cache); var trivia = new TriviaGame(opts, _cache);

View file

@ -157,7 +157,7 @@ public sealed class TriviaGame
var isWin = false; var isWin = false;
// if user won the game, tell the game to stop // if user won the game, tell the game to stop
if (val >= _opts.WinRequirement) if (_opts.WinRequirement != 0 && val >= _opts.WinRequirement)
{ {
_isStopped = true; _isStopped = true;
isWin = true; isWin = true;

View file

@ -91,7 +91,7 @@ public partial class Utility : NadekoModule
var rng = new NadekoRandom(); var rng = new NadekoRandom();
var arr = await Task.Run(() => socketGuild.Users var arr = await Task.Run(() => socketGuild.Users
.Where(u => u.Activities.FirstOrDefault()?.Name?.ToUpperInvariant() .Where(u => u.Activities.FirstOrDefault()?.Name?.Trim().ToUpperInvariant()
== game) == game)
.Select(u => u.Username) .Select(u => u.Username)
.OrderBy(_ => rng.Next()) .OrderBy(_ => rng.Next())
@ -547,15 +547,20 @@ public partial class Utility : NadekoModule
return; return;
} }
var embed = msg.Embeds.FirstOrDefault(); if (!msg.Embeds.Any())
if (embed is null)
{ {
await ReplyErrorLocalizedAsync(strs.not_found); await ReplyErrorLocalizedAsync(strs.not_found);
return; return;
} }
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson(_showEmbedSerializerOptions); var json = new SmartEmbedTextArray()
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\(")); {
Content = msg.Content,
Embeds = msg.Embeds
.Map(x => new SmartEmbedArrayElementText(x))
}.ToJson(_showEmbedSerializerOptions);
await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\("));
} }
[Cmd] [Cmd]
@ -631,4 +636,4 @@ public partial class Utility : NadekoModule
else else
await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled); await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled);
} }
} }