Update discord.net to v3

This commit is contained in:
Daan Boerlage 2022-07-22 19:46:32 +02:00
parent be06870892
commit b0d603e518
Signed by: daan
GPG key ID: FCE070E1E4956606
10 changed files with 38 additions and 19 deletions

View file

@ -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);

View file

@ -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("✅"));
}

View file

@ -23,11 +23,11 @@ namespace Geekbot.Bot.Handlers
_client = client;
}
public async Task HandleMessageDeleted(Cacheable<IMessage, ulong> message, ISocketMessageChannel channel)
public async Task HandleMessageDeleted(Cacheable<IMessage, ulong> message, Cacheable<IMessageChannel, ulong> 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

View file

@ -14,19 +14,19 @@ namespace Geekbot.Bot.Handlers
_reactionListener = reactionListener;
}
public Task Added(Cacheable<IUserMessage, ulong> cacheable, ISocketMessageChannel socketMessageChannel, SocketReaction reaction)
public Task Added(Cacheable<IUserMessage, ulong> cacheableUserMessage, Cacheable<IMessageChannel, ulong> 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<IUserMessage, ulong> cacheable, ISocketMessageChannel socketMessageChannel, SocketReaction reaction)
public Task Removed(Cacheable<IUserMessage, ulong> cacheableUserMessage, Cacheable<IMessageChannel, ulong> 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;
}
}

View file

@ -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})");
}
}
}

View file

@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Discord.Net" Version="2.4.0" />
<PackageReference Include="Discord.Net" Version="3.7.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
<PrivateAssets>all</PrivateAssets>

View file

@ -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<ClientType> IPresence.ActiveClients => ActiveClients;
IReadOnlyCollection<IActivity> IPresence.Activities => Activities;
public IImmutableSet<ClientType> ActiveClients { get; }
public IImmutableList<IActivity> Activities { get; }
public Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}
public string AvatarId { get; set; }
public string AvatarUrl { get; set; }
public string Discriminator { get; set; }

View file

@ -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);
}
}

View file

@ -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;

View file

@ -34,7 +34,7 @@ namespace Geekbot.Core
Transaction.Finish();
}
protected override Task<IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
protected Task<IUserMessage> 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);