Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit dbebe60

Browse files
committed
Update deps; Add message edit and reaction add to the activity tracker
1 parent c29eef0 commit dbebe60

File tree

9 files changed

+40
-17
lines changed

9 files changed

+40
-17
lines changed

libs/DSharpPlus

Submodule DSharpPlus updated 782 files

src/Commands/BlockCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using DSharpPlus.Commands;
77
using DSharpPlus.Commands.ContextChecks;
88
using DSharpPlus.Commands.Trees;
9-
using DSharpPlus.Commands.Trees.Attributes;
109
using DSharpPlus.Entities;
1110

1211
namespace NotifierRedirecter.Commands;

src/Commands/HelpCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
using System.Threading.Tasks;
77
using DSharpPlus;
88
using DSharpPlus.Commands;
9-
using DSharpPlus.Commands.Processors.TextCommands.Attributes;
9+
using DSharpPlus.Commands.ArgumentModifiers;
1010
using DSharpPlus.Commands.Trees;
11-
using DSharpPlus.Commands.Trees.Attributes;
1211
using DSharpPlus.Entities;
1312

1413
namespace NotifierRedirecter.Commands;

src/Commands/IgnoreCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using DSharpPlus.Commands;
77
using DSharpPlus.Commands.ContextChecks;
88
using DSharpPlus.Commands.Trees;
9-
using DSharpPlus.Commands.Trees.Attributes;
109
using DSharpPlus.Entities;
1110

1211
namespace NotifierRedirecter.Commands;

src/Commands/RedirectCommand.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
using System.ComponentModel;
33
using System.Text;
44
using System.Threading.Tasks;
5-
using DSharpPlus;
65
using DSharpPlus.Commands;
76
using DSharpPlus.Commands.ContextChecks;
87
using DSharpPlus.Commands.Trees;
9-
using DSharpPlus.Commands.Trees.Attributes;
108
using DSharpPlus.Entities;
119

1210
namespace NotifierRedirecter.Commands;
@@ -18,7 +16,7 @@ public sealed class RedirectCommand
1816
public RedirectCommand(Database database) => this._database = database;
1917

2018
[Command("add"), Description("Start redirecting pings from this channel into user's DMs.")]
21-
[RequirePermissions(Permissions.None, Permissions.ManageMessages)]
19+
[RequirePermissions(DiscordPermissions.None, DiscordPermissions.ManageMessages)]
2220
public ValueTask AddAsync(CommandContext context, [Description("Which channel to start listening for pings.")] DiscordChannel channel)
2321
{
2422
if (this._database.IsRedirect(channel.Id))
@@ -31,7 +29,7 @@ public sealed class RedirectCommand
3129
}
3230

3331
[Command("remove"), Description("Stop redirecting notifications from this channel into user's DMs.")]
34-
[RequirePermissions(Permissions.None, Permissions.ManageMessages)]
32+
[RequirePermissions(DiscordPermissions.None, DiscordPermissions.ManageMessages)]
3533
public ValueTask RemoveAsync(CommandContext context, [Description("Which channel to stop listening for pings.")] DiscordChannel channel)
3634
{
3735
if (!this._database.IsRedirect(channel.Id))

src/Events/Handlers/GuildDownloadCompletedEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public Task ExecuteAsync(DiscordClient client, GuildDownloadCompletedEventArgs e
2121
}
2222

2323
this._logger.LogInformation("{GuildCount:N0} guilds are ready to go!", eventArgs.Guilds.Count);
24-
return client.UpdateStatusAsync(new DiscordActivity("Messing around with your notifications...", ActivityType.Custom));
24+
return client.UpdateStatusAsync(new DiscordActivity("Messing around with your notifications...", DiscordActivityType.Custom));
2525
}
2626
}

src/Events/Handlers/MessageCreatedEventHandler.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,31 @@
1111

1212
namespace NotifierRedirecter.Events.Handlers;
1313

14-
public sealed partial class MessageCreatedEventHandler
14+
public sealed partial class MessagesEventHandler
1515
{
16-
private readonly ILogger<MessageCreatedEventHandler> _logger;
16+
private readonly ILogger<MessagesEventHandler> _logger;
1717
private readonly UserActivityTracker _userActivityTracker;
1818
private readonly Database _database;
1919

20-
public MessageCreatedEventHandler(UserActivityTracker userActivityTracker, Database database, ILogger<MessageCreatedEventHandler>? logger = null)
20+
public MessagesEventHandler(UserActivityTracker userActivityTracker, Database database, ILogger<MessagesEventHandler>? logger = null)
2121
{
2222
this._userActivityTracker = userActivityTracker ?? throw new ArgumentNullException(nameof(userActivityTracker));
2323
this._database = database ?? throw new ArgumentNullException(nameof(database));
24-
this._logger = logger ?? NullLogger<MessageCreatedEventHandler>.Instance;
24+
this._logger = logger ?? NullLogger<MessagesEventHandler>.Instance;
25+
}
26+
27+
[DiscordEvent(DiscordIntents.GuildMessages)]
28+
public Task ExecuteAsync(DiscordClient _, MessageUpdateEventArgs eventArgs)
29+
{
30+
this._userActivityTracker.UpdateUser(eventArgs.Author.Id, eventArgs.Channel.Id);
31+
return Task.CompletedTask;
2532
}
2633

2734
[DiscordEvent(DiscordIntents.GuildMessages | DiscordIntents.MessageContents)]
2835
public async Task ExecuteAsync(DiscordClient _, MessageCreateEventArgs eventArgs)
2936
{
3037
this._userActivityTracker.UpdateUser(eventArgs.Author.Id, eventArgs.Channel.Id);
31-
bool shouldSilence = eventArgs.Message.Flags?.HasFlag(MessageFlags.SuppressNotifications) ?? false;
38+
bool shouldSilence = eventArgs.Message.Flags?.HasFlag(DiscordMessageFlags.SuppressNotifications) ?? false;
3239

3340
// Ensure the channel is a redirect channel
3441
if (eventArgs.Message.Channel is null || !this._database.IsRedirect(eventArgs.Message.Channel.Id))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using DSharpPlus;
4+
using DSharpPlus.EventArgs;
5+
6+
namespace NotifierRedirecter.Events.Handlers;
7+
8+
public sealed class ReactionsEventHandler
9+
{
10+
private readonly UserActivityTracker _userActivityTracker;
11+
public ReactionsEventHandler(UserActivityTracker userActivityTracker) => this._userActivityTracker = userActivityTracker ?? throw new ArgumentNullException(nameof(userActivityTracker));
12+
13+
[DiscordEvent(DiscordIntents.GuildMessageReactions)]
14+
public Task ExecuteAsync(DiscordClient _, MessageReactionAddEventArgs eventArgs)
15+
{
16+
this._userActivityTracker.UpdateUser(eventArgs.User.Id, eventArgs.Channel.Id);
17+
return Task.CompletedTask;
18+
}
19+
}

src/UserActivityTracker.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ public sealed class UserActivityTracker
1616
private readonly ConcurrentDictionary<ulong, (ulong ChannelId, DateTimeOffset LastActivity)> _tracker = new();
1717

1818
public UserActivityTracker() => _ = this.CleanupInactiveUsersAsync();
19+
1920
public void UpdateUser(ulong userId, ulong channelId) => this._tracker.AddOrUpdate(userId, (channelId, DateTimeOffset.UtcNow), (_, _) => (channelId, DateTimeOffset.UtcNow));
21+
2022
public async ValueTask<bool> IsActiveAsync(ulong userId, ulong channelId)
2123
{
22-
// Wait 5 seconds to see if the user does anything in the channnel.
24+
// Wait X seconds to see if the user does anything in the channnel.
2325
// If they do, the _tracker will be updated and we can avoid a DM.
2426
await Task.Delay(_activityTimeout);
2527
return this._tracker.TryGetValue(userId, out (ulong ChannelId, DateTimeOffset LastActivity) value) && value.ChannelId == channelId && value.LastActivity > DateTimeOffset.UtcNow.AddSeconds(-15);
2628
}
2729

28-
public async Task CleanupInactiveUsersAsync()
30+
private async Task CleanupInactiveUsersAsync()
2931
{
3032
PeriodicTimer timer = new(_cleanupInterval);
3133
while (await timer.WaitForNextTickAsync())

0 commit comments

Comments
 (0)