From b0d603e51877176095ce42095d48710a0f63f955 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Fri, 22 Jul 2022 19:46:32 +0200 Subject: [PATCH] Update discord.net to v3 --- src/Bot/BotStartup.cs | 11 ++++++++++- src/Bot/Commands/Utils/Help.cs | 2 +- src/Bot/Handlers/MessageDeletedHandler.cs | 6 +++--- src/Bot/Handlers/ReactionHandler.cs | 8 ++++---- src/Bot/Handlers/UserHandler.cs | 8 ++++---- src/Core/Core.csproj | 2 +- src/Core/Polyfills/UserPolyfillDto.cs | 10 ++++++++++ src/Core/ReactionListener/IReactionListener.cs | 4 ++-- src/Core/ReactionListener/ReactionListener.cs | 4 ++-- src/Core/TransactionModuleBase.cs | 2 +- 10 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/Bot/BotStartup.cs b/src/Bot/BotStartup.cs index 1e7dd0e..bc3ef49 100644 --- a/src/Bot/BotStartup.cs +++ b/src/Bot/BotStartup.cs @@ -49,9 +49,18 @@ public class BotStartup { _client = new DiscordSocketClient(new DiscordSocketConfig { + GatewayIntents = GatewayIntents.DirectMessageReactions | + GatewayIntents.DirectMessages | + GatewayIntents.GuildMessageReactions | + GatewayIntents.GuildMessages | + GatewayIntents.GuildWebhooks | + GatewayIntents.GuildIntegrations | + GatewayIntents.GuildEmojis | + GatewayIntents.GuildBans | + GatewayIntents.Guilds | + GatewayIntents.GuildMembers, LogLevel = LogSeverity.Verbose, MessageCacheSize = 1000, - ExclusiveBulkDelete = true }); var discordLogger = new DiscordLogger(_logger); diff --git a/src/Bot/Commands/Utils/Help.cs b/src/Bot/Commands/Utils/Help.cs index 7377bfa..7aa9aff 100644 --- a/src/Bot/Commands/Utils/Help.cs +++ b/src/Bot/Commands/Utils/Help.cs @@ -27,7 +27,7 @@ namespace Geekbot.Bot.Commands.Utils sb.AppendLine("For a list of all commands, please visit the following page"); sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands"); - var dm = await Context.User.GetOrCreateDMChannelAsync(); + var dm = await Context.User.CreateDMChannelAsync(RequestOptions.Default); await dm.SendMessageAsync(sb.ToString()); await Context.Message.AddReactionAsync(new Emoji("✅")); } diff --git a/src/Bot/Handlers/MessageDeletedHandler.cs b/src/Bot/Handlers/MessageDeletedHandler.cs index d0377f7..b8ffe5c 100644 --- a/src/Bot/Handlers/MessageDeletedHandler.cs +++ b/src/Bot/Handlers/MessageDeletedHandler.cs @@ -23,11 +23,11 @@ namespace Geekbot.Bot.Handlers _client = client; } - public async Task HandleMessageDeleted(Cacheable message, ISocketMessageChannel channel) + public async Task HandleMessageDeleted(Cacheable message, Cacheable cacheableMessageChannel) { try { - var guildSocketData = ((IGuildChannel) channel).Guild; + var guildSocketData = ((IGuildChannel) cacheableMessageChannel.Value).Guild; var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildSocketData.Id.AsLong())); if ((guild?.ShowDelete ?? false) && guild?.ModChannel != 0) { @@ -35,7 +35,7 @@ namespace Geekbot.Bot.Handlers var sb = new StringBuilder(); if (message.Value != null) { - sb.AppendLine($"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{channel.Id}>"); + sb.AppendLine($"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{cacheableMessageChannel.Id}>"); sb.AppendLine(message.Value.Content); } else diff --git a/src/Bot/Handlers/ReactionHandler.cs b/src/Bot/Handlers/ReactionHandler.cs index 66af3e8..816e125 100644 --- a/src/Bot/Handlers/ReactionHandler.cs +++ b/src/Bot/Handlers/ReactionHandler.cs @@ -14,19 +14,19 @@ namespace Geekbot.Bot.Handlers _reactionListener = reactionListener; } - public Task Added(Cacheable cacheable, ISocketMessageChannel socketMessageChannel, SocketReaction reaction) + public Task Added(Cacheable cacheableUserMessage, Cacheable cacheableMessageChannel, SocketReaction reaction) { if (reaction.User.Value.IsBot) return Task.CompletedTask; if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask; - _reactionListener.GiveRole(socketMessageChannel, reaction); + _reactionListener.GiveRole(cacheableMessageChannel.Value, reaction); return Task.CompletedTask; } - public Task Removed(Cacheable cacheable, ISocketMessageChannel socketMessageChannel, SocketReaction reaction) + public Task Removed(Cacheable cacheableUserMessage, Cacheable cacheableMessageChannel, SocketReaction reaction) { if (reaction.User.Value.IsBot) return Task.CompletedTask; if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask; - _reactionListener.RemoveRole(socketMessageChannel, reaction); + _reactionListener.RemoveRole(cacheableMessageChannel.Value, reaction); return Task.CompletedTask; } } diff --git a/src/Bot/Handlers/UserHandler.cs b/src/Bot/Handlers/UserHandler.cs index a22d0e1..1f58131 100644 --- a/src/Bot/Handlers/UserHandler.cs +++ b/src/Bot/Handlers/UserHandler.cs @@ -74,15 +74,15 @@ namespace Geekbot.Bot.Handlers await _userRepository.Update(newUser); } - public async Task Left(SocketGuildUser user) + public async Task Left(SocketGuild socketGuild, SocketUser socketUser) { try { - var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(user.Guild.Id.AsLong())); + var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(socketGuild.Id.AsLong())); if (guild?.ShowLeave ?? false) { var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(guild.ModChannel.AsUlong()); - await modChannelSocket.SendMessageAsync($"{user.Username}#{user.Discriminator} left the server"); + await modChannelSocket.SendMessageAsync($"{socketUser.Username}#{socketUser.Discriminator} left the server"); } } catch (Exception e) @@ -90,7 +90,7 @@ namespace Geekbot.Bot.Handlers _logger.Error(LogSource.Geekbot, "Failed to send leave message", e); } - _logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})"); + _logger.Information(LogSource.Geekbot, $"{socketUser.Username} ({socketUser.Id}) joined {socketGuild.Name} ({socketGuild.Id})"); } } } \ No newline at end of file diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index dac4945..2cd8dbc 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -14,7 +14,7 @@ - + all diff --git a/src/Core/Polyfills/UserPolyfillDto.cs b/src/Core/Polyfills/UserPolyfillDto.cs index 385a30d..3907e05 100644 --- a/src/Core/Polyfills/UserPolyfillDto.cs +++ b/src/Core/Polyfills/UserPolyfillDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Threading.Tasks; using Discord; @@ -12,8 +13,17 @@ namespace Geekbot.Core.Polyfills public string Mention { get; set; } public IActivity Activity { get; } public UserStatus Status { get; set; } + IReadOnlyCollection IPresence.ActiveClients => ActiveClients; + + IReadOnlyCollection IPresence.Activities => Activities; + public IImmutableSet ActiveClients { get; } public IImmutableList Activities { get; } + public Task CreateDMChannelAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + public string AvatarId { get; set; } public string AvatarUrl { get; set; } public string Discriminator { get; set; } diff --git a/src/Core/ReactionListener/IReactionListener.cs b/src/Core/ReactionListener/IReactionListener.cs index 4909d68..c22d792 100644 --- a/src/Core/ReactionListener/IReactionListener.cs +++ b/src/Core/ReactionListener/IReactionListener.cs @@ -8,8 +8,8 @@ namespace Geekbot.Core.ReactionListener { bool IsListener(ulong id); Task AddRoleToListener(ulong messageId, ulong guildId, string emoji, IRole role); - void RemoveRole(ISocketMessageChannel channel, SocketReaction reaction); - void GiveRole(ISocketMessageChannel message, SocketReaction reaction); + void RemoveRole(IMessageChannel channel, SocketReaction reaction); + void GiveRole(IMessageChannel message, SocketReaction reaction); IEmote ConvertStringToEmote(string emoji); } } \ No newline at end of file diff --git a/src/Core/ReactionListener/ReactionListener.cs b/src/Core/ReactionListener/ReactionListener.cs index 0d9f1f6..dcb0d5b 100644 --- a/src/Core/ReactionListener/ReactionListener.cs +++ b/src/Core/ReactionListener/ReactionListener.cs @@ -67,7 +67,7 @@ namespace Geekbot.Core.ReactionListener _listener[messageId].Add(emote, role.Id); } - public async void RemoveRole(ISocketMessageChannel channel, SocketReaction reaction) + public async void RemoveRole(IMessageChannel channel, SocketReaction reaction) { _listener.TryGetValue(reaction.MessageId, out var registeredReactions); if (registeredReactions == null) return; @@ -86,7 +86,7 @@ namespace Geekbot.Core.ReactionListener } } - public async void GiveRole(ISocketMessageChannel channel, SocketReaction reaction) + public async void GiveRole(IMessageChannel channel, SocketReaction reaction) { _listener.TryGetValue(reaction.MessageId, out var registeredReactions); if (registeredReactions == null) return; diff --git a/src/Core/TransactionModuleBase.cs b/src/Core/TransactionModuleBase.cs index 726c355..cbe5206 100644 --- a/src/Core/TransactionModuleBase.cs +++ b/src/Core/TransactionModuleBase.cs @@ -34,7 +34,7 @@ namespace Geekbot.Core Transaction.Finish(); } - protected override Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null) + protected Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null) { var replySpan = Transaction.StartChild("Reply"); var msg = base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference);