From 9d9f8f7f98937af5e2f8751008d12691dd4c6668 Mon Sep 17 00:00:00 2001 From: Hokuto Chen Date: Wed, 29 Nov 2023 12:26:26 +0000 Subject: [PATCH 1/6] Notifications will be sent even if dms are off when using .give --- .../Currency/CurrencyServiceExtensions.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs b/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs index 603eb479b..e5dcfa7ba 100644 --- a/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs +++ b/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs @@ -1,4 +1,4 @@ -using NadekoBot.Services.Currency; +using NadekoBot.Services.Currency; namespace NadekoBot.Services; @@ -27,13 +27,19 @@ public static class CurrencyServiceExtensions if (await fromWallet.Transfer(amount, toWallet, extra)) { - await to.SendConfirmAsync(ebs, - string.IsNullOrWhiteSpace(note) - ? $"Received {formattedAmount} from {from} " - : $"Received {formattedAmount} from {from}: {note}"); + try + { + await to.SendConfirmAsync(ebs, + string.IsNullOrWhiteSpace(note) + ? $"Received {formattedAmount} from {from} " + : $"Received {formattedAmount} from {from}: {note}"); + } + catch + { + //ignored + } return true; } - return false; } -} \ No newline at end of file +} From 340c5b2268f57e55ab1ff949d4b0c9602f662bba Mon Sep 17 00:00:00 2001 From: Cata Date: Mon, 11 Dec 2023 23:24:04 +0000 Subject: [PATCH 2/6] Potential fix for no-show quoteshow --- .../Modules/Utility/Quote/QuoteCommands.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs index 05edfba95..013ab8490 100644 --- a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs @@ -127,15 +127,27 @@ public partial class Utility } private async Task ShowQuoteData(Quote data) - => await ctx.Channel.EmbedAsync(_eb.Create(ctx) - .WithOkColor() - .WithTitle(GetText(strs.quote_id($"#{data.Id}"))) - .AddField(GetText(strs.trigger), data.Keyword) - .AddField(GetText(strs.response), - Format.Sanitize(data.Text).Replace("](", "]\\(")) - .WithFooter( - GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})")))); + { + var eb = _eb.Create(ctx) + .WithOkColor() + .WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:") + .WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096)) + .AddField(GetText(strs.trigger), data.Keyword) + .WithFooter( + GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})"))) + .Build(); + if (!(data.Text.Length > 4096)) + { + await ctx.Channel.SendMessageAsync(embed: eb); + return; + } + + await ctx.Channel.SendFileAsync( + attachment: new FileAttachment(await data.Text.ToStream(), "quote.txt"), + embed: eb); + } + private async Task QuoteSearchinternalAsync(string? keyword, string textOrAuthor) { if (string.IsNullOrWhiteSpace(textOrAuthor)) From bab23c25a5c0ae1f0ab88cb55a298731c027551d Mon Sep 17 00:00:00 2001 From: Kaoticz <3125254-Kaoticz@users.noreply.gitlab.com> Date: Thu, 21 Dec 2023 12:45:34 +0000 Subject: [PATCH 3/6] Implemented owner-only command `.cacheusers` to force users into the database, closes #425 --- .../Db/Extensions/DiscordUserExtensions.cs | 49 +++++++++++++++++++ .../Administration/Self/SelfCommands.cs | 35 +++++++++++++ src/NadekoBot/data/aliases.yml | 4 +- .../data/strings/commands/commands.en-US.yml | 5 ++ .../strings/responses/responses.en-US.json | 4 +- 5 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs b/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs index a2eaaa179..0b6dc0e85 100644 --- a/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs +++ b/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs @@ -4,11 +4,60 @@ using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using NadekoBot.Db.Models; using NadekoBot.Services.Database; +using System.Collections.Immutable; namespace NadekoBot.Db; public static class DiscordUserExtensions { + /// + /// Adds the specified to the database. If a database user with placeholder name + /// and discriminator is present in , their name and discriminator get updated accordingly. + /// + /// This database context. + /// The users to add or update in the database. + /// A tuple with the amount of new users added and old users updated. + public static async Task<(long UsersAdded, long UsersUpdated)> RefreshUsersAsync(this NadekoContext ctx, List users) + { + var presentDbUsers = await ctx.DiscordUser + .Select(x => new { x.UserId, x.Username, x.Discriminator }) + .Where(x => users.Select(y => y.Id).Contains(x.UserId)) + .ToArrayAsyncEF(); + + var usersToAdd = users + .Where(x => !presentDbUsers.Select(x => x.UserId).Contains(x.Id)) + .Select(x => new DiscordUser() + { + UserId = x.Id, + AvatarId = x.AvatarId, + Username = x.Username, + Discriminator = x.Discriminator + }); + + var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied; + var toUpdateUserIds = presentDbUsers + .Where(x => x.Username == "Unknown" && x.Discriminator == "????") + .Select(x => x.UserId) + .ToArray(); + + foreach (var user in users.Where(x => toUpdateUserIds.Contains(x.Id))) + { + await ctx.DiscordUser + .Where(x => x.UserId == user.Id) + .UpdateAsync(x => new DiscordUser() + { + Username = user.Username, + Discriminator = user.Discriminator, + + // .award tends to set AvatarId and DateAdded to NULL, so account for that. + AvatarId = user.AvatarId, + DateAdded = x.DateAdded ?? DateTime.UtcNow + }); + } + + return (added, toUpdateUserIds.Length); + } + public static Task GetByUserIdAsync( this IQueryable set, ulong userId) diff --git a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs index fb81c86bd..e76c49ba9 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs @@ -1,5 +1,6 @@ #nullable disable using Nadeko.Medusa; +using NadekoBot.Db; using NadekoBot.Modules.Administration.Services; using NadekoBot.Services.Database.Models; @@ -22,19 +23,53 @@ public partial class Administration private readonly IBotStrings _strings; private readonly IMedusaLoaderService _medusaLoader; private readonly ICoordinator _coord; + private readonly DbService _db; public SelfCommands( DiscordSocketClient client, + DbService db, IBotStrings strings, ICoordinator coord, IMedusaLoaderService medusaLoader) { _client = client; + _db = db; _strings = strings; _coord = coord; _medusaLoader = medusaLoader; } + + [Cmd] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + public Task CacheUsers() + => CacheUsers(ctx.Guild); + + [Cmd] + [OwnerOnly] + public async Task CacheUsers(IGuild guild) + { + var downloadUsersTask = guild.DownloadUsersAsync(); + var message = await ReplyPendingLocalizedAsync(strs.cache_users_pending); + using var dbContext = _db.GetDbContext(); + + await downloadUsersTask; + + var users = (await guild.GetUsersAsync(CacheMode.CacheOnly)) + .Cast() + .ToList(); + + var (added, updated) = await dbContext.RefreshUsersAsync(users); + + await message.ModifyAsync(x => + x.Embed = _eb.Create() + .WithDescription(GetText(strs.cache_users_done(added, updated))) + .WithOkColor() + .Build() + ); + } + [Cmd] [OwnerOnly] public async Task DoAs(IUser user, [Leftover] string message) diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 1efc29abe..5b7957e4a 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -1390,4 +1390,6 @@ autopublish: - autopublish doas: - doas - - execas \ No newline at end of file + - execas +cacheusers: + - cacheusers \ No newline at end of file diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 2caec755d..8023f3180 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -2363,3 +2363,8 @@ doas: desc: "Execute the command as if you were the target user. Requires bot ownership and server administrator permission." args: - "@Thief .give all @Admin" +cacheusers: + desc: Caches users of a Discord server and saves them to the database. + args: + - "" + - "serverId" \ No newline at end of file diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index 77d3ea9b0..50a16a795 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -1058,5 +1058,7 @@ "sticker_missing_name": "Please specify a name for the sticker.", "thread_deleted": "Thread Deleted", "thread_created": "Thread Created", - "supported_languages": "Supported Languages" + "supported_languages": "Supported Languages", + "cache_users_pending": "Updating users, please wait...", + "cache_users_done": "{0} users were added and {1} users were updated." } From 41ae1823738b5dbd09e0ac67f851caffd747d4c1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 24 Dec 2023 07:50:41 +0000 Subject: [PATCH 4/6] Removed .revimg and .revav, closes #417 --- src/NadekoBot/Modules/Searches/Searches.cs | 24 ------------------- .../Modules/Searches/SearchesService.cs | 3 +++ src/NadekoBot/data/aliases.yml | 4 ---- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index c928c308a..0e8b66d65 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -422,30 +422,6 @@ public partial class Searches : NadekoModule await SendConfirmAsync("🐈" + GetText(strs.catfact), fact); } - //done in 3.0 - [Cmd] - [RequireContext(ContextType.Guild)] - public async Task Revav([Leftover] IGuildUser usr = null) - { - if (usr is null) - usr = (IGuildUser)ctx.User; - - var av = usr.RealAvatarUrl(); - await SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={av}"); - } - - //done in 3.0 - [Cmd] - public async Task Revimg([Leftover] string imageLink = null) - { - imageLink = imageLink?.Trim() ?? ""; - - if (string.IsNullOrWhiteSpace(imageLink)) - return; - - await SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={imageLink}"); - } - [Cmd] public async Task Wiki([Leftover] string query = null) { diff --git a/src/NadekoBot/Modules/Searches/SearchesService.cs b/src/NadekoBot/Modules/Searches/SearchesService.cs index eedea43a1..00edaa19e 100644 --- a/src/NadekoBot/Modules/Searches/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/SearchesService.cs @@ -9,6 +9,9 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; +using System.Collections; +using System.Net.Http.Json; +using System.Text.Json.Serialization; using Color = SixLabors.ImageSharp.Color; using Image = SixLabors.ImageSharp.Image; diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 5b7957e4a..85157bcf2 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -647,10 +647,6 @@ chucknorris: magicitem: - magicitem - mi -revav: - - revav -revimg: - - revimg safebooru: - safebooru wiki: From 96851c7c2d8e4f2b683797ef55863be7b4cbe590 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 26 Dec 2023 17:02:02 +0000 Subject: [PATCH 5/6] Updated lib, fixed icon_url in .showembed --- .../Common/SmartText/SmartTextEmbedAuthor.cs | 2 ++ .../Common/SmartText/SmartTextEmbedFooter.cs | 2 ++ .../Modules/Administration/Self/DoAsUserMessage.cs | 13 ++++++++++++- src/NadekoBot/Modules/Utility/Utility.cs | 12 +++++++----- src/NadekoBot/NadekoBot.csproj | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/Common/SmartText/SmartTextEmbedAuthor.cs b/src/NadekoBot/Common/SmartText/SmartTextEmbedAuthor.cs index 51e8369ea..5b243abe2 100644 --- a/src/NadekoBot/Common/SmartText/SmartTextEmbedAuthor.cs +++ b/src/NadekoBot/Common/SmartText/SmartTextEmbedAuthor.cs @@ -1,5 +1,6 @@ #nullable disable using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace NadekoBot; @@ -8,6 +9,7 @@ public class SmartTextEmbedAuthor public string Name { get; set; } [JsonProperty("icon_url")] + [JsonPropertyName("icon_url")] public string IconUrl { get; set; } public string Url { get; set; } diff --git a/src/NadekoBot/Common/SmartText/SmartTextEmbedFooter.cs b/src/NadekoBot/Common/SmartText/SmartTextEmbedFooter.cs index 19489881f..54f9ed0dd 100644 --- a/src/NadekoBot/Common/SmartText/SmartTextEmbedFooter.cs +++ b/src/NadekoBot/Common/SmartText/SmartTextEmbedFooter.cs @@ -1,5 +1,6 @@ #nullable disable using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace NadekoBot; @@ -8,5 +9,6 @@ public class SmartTextEmbedFooter public string Text { get; set; } [JsonProperty("icon_url")] + [JsonPropertyName("icon_url")] public string IconUrl { get; set; } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs b/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs index 849c7df3a..86d5ad2f2 100644 --- a/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs +++ b/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs @@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Administration; public sealed class DoAsUserMessage : IUserMessage { private readonly string _message; - private IUserMessage _msg; + private readonly IUserMessage _msg; private readonly IUser _user; public DoAsUserMessage(SocketUserMessage msg, IUser user, string message) @@ -49,6 +49,13 @@ public sealed class DoAsUserMessage : IUserMessage return _msg.RemoveAllReactionsForEmoteAsync(emote, options); } + public IAsyncEnumerable> GetReactionUsersAsync( + IEmote emoji, + int limit, + RequestOptions? options = null, + ReactionType type = ReactionType.Normal) + => _msg.GetReactionUsersAsync(emoji, limit, options, type); + public IAsyncEnumerable> GetReactionUsersAsync(IEmote emoji, int limit, RequestOptions? options = null) { @@ -78,6 +85,7 @@ public sealed class DoAsUserMessage : IUserMessage public IMessageChannel Channel => _msg.Channel; public IUser Author => _user; + public IThreadChannel Thread => _msg.Thread; public IReadOnlyCollection Attachments => _msg.Attachments; @@ -106,6 +114,7 @@ public sealed class DoAsUserMessage : IUserMessage public MessageFlags? Flags => _msg.Flags; public IMessageInteraction Interaction => _msg.Interaction; + public MessageRoleSubscriptionData RoleSubscriptionData => _msg.RoleSubscriptionData; public Task ModifyAsync(Action func, RequestOptions? options = null) { @@ -134,5 +143,7 @@ public sealed class DoAsUserMessage : IUserMessage return _msg.Resolve(userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); } + public MessageResolvedData ResolvedData => _msg.ResolvedData; + public IUserMessage ReferencedMessage => _msg.ReferencedMessage; } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 825d576cf..5a732290d 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -464,12 +464,14 @@ public partial class Utility : NadekoModule { if (tags.Length == 0) tags = new[] { name }; - - await ctx.Guild.CreateStickerAsync(name, - string.IsNullOrWhiteSpace(description) ? "Missing description" : description, - tags, + + await ctx.Guild.CreateStickerAsync( + name, stream, - $"{name}.{format}"); + $"{name}.{format}", + tags, + string.IsNullOrWhiteSpace(description) ? "Missing description" : description + ); await ctx.OkAsync(); } diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 8e5ad93a1..ea32dd82c 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -27,7 +27,7 @@ - + From ef4d38bc871891b3cf419da3450f299874919521 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 26 Dec 2023 17:10:44 +0000 Subject: [PATCH 6/6] Changelog updated, version updated to 4.3.18 --- CHANGELOG.md | 23 +++++++++++++++++++++ src/NadekoBot/Services/Impl/StatsService.cs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c357a0f9..581080202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,29 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o +## [4.3.18] - 26.12.2023 + +### Added + +- Added `.cacheusers` command (thx Kotz) +- Added `.clubreject` which lets you reject club applications + +### Changed + +- Updated discord lib, there should be less console errors now + +### Fixed + +- Fixed `icon_url` when using `.showembed` +- Fixed `.quoteshow` not showing sometimes (thx Cata) +- Notifications will no longer be sent if dms are off when using `.give` +- Users should no longer be able to apply to clubs while in a club already (especially not to the same club they're already in) + +### Removed + +- `.revimg` and `.revav` as google removed reverse image search +- + ## [4.3.17] - 06.09.2023 ### Fixed diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 68a23bc9c..a69d6503c 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -7,7 +7,7 @@ namespace NadekoBot.Services; public sealed class StatsService : IStatsService, IReadyExecutor, INService { - public const string BOT_VERSION = "4.3.17"; + public const string BOT_VERSION = "4.3.18"; public string Author => "Kwoth#2452";