Update D.NET version and add bulk deletion support
This commit is contained in:
parent
4fe80749c4
commit
11eabe2e3d
@ -83,7 +83,8 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
.AddSingleton<IDiscordClient, DiscordShardedClient>(_ => new DiscordShardedClient(new DiscordSocketConfig
|
.AddSingleton<IDiscordClient, DiscordShardedClient>(_ => new DiscordShardedClient(new DiscordSocketConfig
|
||||||
{
|
{
|
||||||
MessageCacheSize = 0
|
MessageCacheSize = 0,
|
||||||
|
ExclusiveBulkDelete = true
|
||||||
}))
|
}))
|
||||||
.AddSingleton<Bot>()
|
.AddSingleton<Bot>()
|
||||||
|
|
||||||
@ -161,6 +162,7 @@ namespace PluralKit.Bot
|
|||||||
_client.MessageReceived += (msg) => { var _ = MessageReceived(msg).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
_client.MessageReceived += (msg) => { var _ = MessageReceived(msg).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
||||||
_client.ReactionAdded += (message, channel, reaction) => { var _ = _proxy.HandleReactionAddedAsync(message, channel, reaction).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
_client.ReactionAdded += (message, channel, reaction) => { var _ = _proxy.HandleReactionAddedAsync(message, channel, reaction).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
||||||
_client.MessageDeleted += (message, channel) => { var _ = _proxy.HandleMessageDeletedAsync(message, channel).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
_client.MessageDeleted += (message, channel) => { var _ = _proxy.HandleMessageDeletedAsync(message, channel).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
||||||
|
_client.MessagesBulkDeleted += (messages, channel) => { var _ = _proxy.HandleMessageBulkDeleteAsync(messages, channel).CatchException(HandleRuntimeError); return Task.CompletedTask; };
|
||||||
|
|
||||||
_client.Log += FrameworkLog;
|
_client.Log += FrameworkLog;
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net.Commands" Version="2.0.1" />
|
<PackageReference Include="Discord.Net.Commands" Version="2.1.1" />
|
||||||
<PackageReference Include="Discord.Net.Webhook" Version="2.0.1" />
|
<PackageReference Include="Discord.Net.Webhook" Version="2.1.1" />
|
||||||
<PackageReference Include="Discord.Net.WebSocket" Version="2.0.1" />
|
<PackageReference Include="Discord.Net.WebSocket" Version="2.1.1" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.6.2" />
|
<PackageReference Include="Humanizer.Core" Version="2.6.2" />
|
||||||
<PackageReference Include="Sentry" Version="2.0.0-beta2" />
|
<PackageReference Include="Sentry" Version="2.0.0-beta2" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
|
||||||
|
@ -271,6 +271,12 @@ namespace PluralKit.Bot
|
|||||||
await _messageStorage.Delete(message.Id);
|
await _messageStorage.Delete(message.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task HandleMessageBulkDeleteAsync(IReadOnlyCollection<Cacheable<IMessage, ulong>> messages, IMessageChannel channel)
|
||||||
|
{
|
||||||
|
_logger.Information("Bulk deleting {Count} messages in channel {Channel}", messages.Count, channel.Id);
|
||||||
|
await _messageStorage.BulkDelete(messages.Select(m => m.Id).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
private string FixClyde(string name)
|
private string FixClyde(string name)
|
||||||
{
|
{
|
||||||
var match = Regex.Match(name, "clyde", RegexOptions.IgnoreCase);
|
var match = Regex.Match(name, "clyde", RegexOptions.IgnoreCase);
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
<PackageReference Include="NodaTime" Version="3.0.0-alpha01" />
|
<PackageReference Include="NodaTime" Version="3.0.0-alpha01" />
|
||||||
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="2.2.0" />
|
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="2.2.0" />
|
||||||
<PackageReference Include="Npgsql" Version="4.0.6" />
|
<PackageReference Include="Npgsql" Version="4.0.8" />
|
||||||
<PackageReference Include="Npgsql.NodaTime" Version="4.0.6" />
|
<PackageReference Include="Npgsql.NodaTime" Version="4.0.8" />
|
||||||
<PackageReference Include="Serilog" Version="2.8.0" />
|
<PackageReference Include="Serilog" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
|
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
|
||||||
<PackageReference Include="Serilog.NodaTime" Version="1.0.0" />
|
<PackageReference Include="Serilog.NodaTime" Version="1.0.0" />
|
||||||
|
@ -227,6 +227,18 @@ namespace PluralKit {
|
|||||||
_logger.Information("Deleted message {Message}", id);
|
_logger.Information("Deleted message {Message}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task BulkDelete(IReadOnlyCollection<ulong> ids)
|
||||||
|
{
|
||||||
|
using (var conn = await _conn.Obtain())
|
||||||
|
{
|
||||||
|
// Npgsql doesn't support ulongs in general - we hacked around it for plain ulongs but tbh not worth it for collections of ulong
|
||||||
|
// Hence we map them to single longs, which *are* supported (this is ok since they're Technically (tm) stored as signed longs in the db anyway)
|
||||||
|
var foundCount = await conn.ExecuteAsync("delete from messages where mid = any(@Ids)", new {Ids = ids.Select(id => (long) id).ToArray()});
|
||||||
|
if (foundCount > 0)
|
||||||
|
_logger.Information("Bulk deleted messages {Messages}, {FoundCount} found", ids, foundCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<ulong> Count()
|
public async Task<ulong> Count()
|
||||||
{
|
{
|
||||||
using (var conn = await _conn.Obtain())
|
using (var conn = await _conn.Obtain())
|
||||||
|
Loading…
Reference in New Issue
Block a user