Update discord.net to v3
This commit is contained in:
parent
be06870892
commit
b0d603e518
10 changed files with 38 additions and 19 deletions
|
@ -49,9 +49,18 @@ public class BotStartup
|
||||||
{
|
{
|
||||||
_client = new DiscordSocketClient(new DiscordSocketConfig
|
_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,
|
LogLevel = LogSeverity.Verbose,
|
||||||
MessageCacheSize = 1000,
|
MessageCacheSize = 1000,
|
||||||
ExclusiveBulkDelete = true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var discordLogger = new DiscordLogger(_logger);
|
var discordLogger = new DiscordLogger(_logger);
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Geekbot.Bot.Commands.Utils
|
||||||
|
|
||||||
sb.AppendLine("For a list of all commands, please visit the following page");
|
sb.AppendLine("For a list of all commands, please visit the following page");
|
||||||
sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands");
|
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 dm.SendMessageAsync(sb.ToString());
|
||||||
await Context.Message.AddReactionAsync(new Emoji("✅"));
|
await Context.Message.AddReactionAsync(new Emoji("✅"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@ namespace Geekbot.Bot.Handlers
|
||||||
_client = client;
|
_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
|
try
|
||||||
{
|
{
|
||||||
var guildSocketData = ((IGuildChannel) channel).Guild;
|
var guildSocketData = ((IGuildChannel) cacheableMessageChannel.Value).Guild;
|
||||||
var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildSocketData.Id.AsLong()));
|
var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildSocketData.Id.AsLong()));
|
||||||
if ((guild?.ShowDelete ?? false) && guild?.ModChannel != 0)
|
if ((guild?.ShowDelete ?? false) && guild?.ModChannel != 0)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,7 @@ namespace Geekbot.Bot.Handlers
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
if (message.Value != null)
|
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);
|
sb.AppendLine(message.Value.Content);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,19 +14,19 @@ namespace Geekbot.Bot.Handlers
|
||||||
_reactionListener = reactionListener;
|
_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 (reaction.User.Value.IsBot) return Task.CompletedTask;
|
||||||
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
||||||
_reactionListener.GiveRole(socketMessageChannel, reaction);
|
_reactionListener.GiveRole(cacheableMessageChannel.Value, reaction);
|
||||||
return Task.CompletedTask;
|
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 (reaction.User.Value.IsBot) return Task.CompletedTask;
|
||||||
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
||||||
_reactionListener.RemoveRole(socketMessageChannel, reaction);
|
_reactionListener.RemoveRole(cacheableMessageChannel.Value, reaction);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,15 +74,15 @@ namespace Geekbot.Bot.Handlers
|
||||||
await _userRepository.Update(newUser);
|
await _userRepository.Update(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Left(SocketGuildUser user)
|
public async Task Left(SocketGuild socketGuild, SocketUser socketUser)
|
||||||
{
|
{
|
||||||
try
|
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)
|
if (guild?.ShowLeave ?? false)
|
||||||
{
|
{
|
||||||
var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(guild.ModChannel.AsUlong());
|
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)
|
catch (Exception e)
|
||||||
|
@ -90,7 +90,7 @@ namespace Geekbot.Bot.Handlers
|
||||||
_logger.Error(LogSource.Geekbot, "Failed to send leave message", e);
|
_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})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
<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" Version="5.0.12" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
|
@ -12,8 +13,17 @@ namespace Geekbot.Core.Polyfills
|
||||||
public string Mention { get; set; }
|
public string Mention { get; set; }
|
||||||
public IActivity Activity { get; }
|
public IActivity Activity { get; }
|
||||||
public UserStatus Status { get; set; }
|
public UserStatus Status { get; set; }
|
||||||
|
IReadOnlyCollection<ClientType> IPresence.ActiveClients => ActiveClients;
|
||||||
|
|
||||||
|
IReadOnlyCollection<IActivity> IPresence.Activities => Activities;
|
||||||
|
|
||||||
public IImmutableSet<ClientType> ActiveClients { get; }
|
public IImmutableSet<ClientType> ActiveClients { get; }
|
||||||
public IImmutableList<IActivity> Activities { get; }
|
public IImmutableList<IActivity> Activities { get; }
|
||||||
|
public Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public string AvatarId { get; set; }
|
public string AvatarId { get; set; }
|
||||||
public string AvatarUrl { get; set; }
|
public string AvatarUrl { get; set; }
|
||||||
public string Discriminator { get; set; }
|
public string Discriminator { get; set; }
|
||||||
|
|
|
@ -8,8 +8,8 @@ namespace Geekbot.Core.ReactionListener
|
||||||
{
|
{
|
||||||
bool IsListener(ulong id);
|
bool IsListener(ulong id);
|
||||||
Task AddRoleToListener(ulong messageId, ulong guildId, string emoji, IRole role);
|
Task AddRoleToListener(ulong messageId, ulong guildId, string emoji, IRole role);
|
||||||
void RemoveRole(ISocketMessageChannel channel, SocketReaction reaction);
|
void RemoveRole(IMessageChannel channel, SocketReaction reaction);
|
||||||
void GiveRole(ISocketMessageChannel message, SocketReaction reaction);
|
void GiveRole(IMessageChannel message, SocketReaction reaction);
|
||||||
IEmote ConvertStringToEmote(string emoji);
|
IEmote ConvertStringToEmote(string emoji);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -67,7 +67,7 @@ namespace Geekbot.Core.ReactionListener
|
||||||
_listener[messageId].Add(emote, role.Id);
|
_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);
|
_listener.TryGetValue(reaction.MessageId, out var registeredReactions);
|
||||||
if (registeredReactions == null) return;
|
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);
|
_listener.TryGetValue(reaction.MessageId, out var registeredReactions);
|
||||||
if (registeredReactions == null) return;
|
if (registeredReactions == null) return;
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Geekbot.Core
|
||||||
Transaction.Finish();
|
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 replySpan = Transaction.StartChild("Reply");
|
||||||
var msg = base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference);
|
var msg = base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference);
|
||||||
|
|
Loading…
Reference in a new issue