From 81d7fa59971e2d8c5b8e1676b7af0206b627b366 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sat, 8 May 2021 22:36:52 +0100 Subject: [PATCH 1/2] Updated dependencies --- .../Discord.Addons.Interactive.csproj | 4 ++-- SampleApp/SampleApp.csproj | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj index ce5f9bc..8a136a2 100644 --- a/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj +++ b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj @@ -18,8 +18,8 @@ - - + + \ No newline at end of file diff --git a/SampleApp/SampleApp.csproj b/SampleApp/SampleApp.csproj index 50052b9..d3de106 100644 --- a/SampleApp/SampleApp.csproj +++ b/SampleApp/SampleApp.csproj @@ -6,9 +6,9 @@ - - - + + + From 113fa3509eecb1987a1ce883446ba009bf0a30d3 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Wed, 5 Jan 2022 19:37:38 +0000 Subject: [PATCH 2/2] Updated to latest, cleaned up some code formatting. --- .gitignore | 3 +- .../Criteria/Criteria.cs | 2 +- .../Discord.Addons.Interactive.csproj | 4 +- ...cord.Addons.Interactive.csproj.DotSettings | 5 ++ Discord.Addons.Interactive/InteractiveBase.cs | 12 +++-- .../InteractiveService.cs | 48 +++++++++++-------- .../EnsureReactionFromSourceUserCriterion.cs | 6 +-- SampleApp/SampleApp.csproj | 14 ++++-- 8 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 Discord.Addons.Interactive/Discord.Addons.Interactive.csproj.DotSettings diff --git a/.gitignore b/.gitignore index 3c4efe2..e5d4b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -258,4 +258,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc +/SampleApp/*.ignore diff --git a/Discord.Addons.Interactive/Criteria/Criteria.cs b/Discord.Addons.Interactive/Criteria/Criteria.cs index f3ffbe3..156ca50 100644 --- a/Discord.Addons.Interactive/Criteria/Criteria.cs +++ b/Discord.Addons.Interactive/Criteria/Criteria.cs @@ -6,7 +6,7 @@ namespace Discord.Addons.Interactive { public class Criteria : ICriterion { - private List> _critiera = new List>(); + private readonly List> _critiera = new List>(); public Criteria AddCriterion(ICriterion criterion) { diff --git a/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj index 8a136a2..fdc84b8 100644 --- a/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj +++ b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj @@ -18,8 +18,8 @@ - - + + \ No newline at end of file diff --git a/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj.DotSettings b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj.DotSettings new file mode 100644 index 0000000..0f273b0 --- /dev/null +++ b/Discord.Addons.Interactive/Discord.Addons.Interactive.csproj.DotSettings @@ -0,0 +1,5 @@ + + True + True + True + True \ No newline at end of file diff --git a/Discord.Addons.Interactive/InteractiveBase.cs b/Discord.Addons.Interactive/InteractiveBase.cs index 89e5369..3dc7f8f 100644 --- a/Discord.Addons.Interactive/InteractiveBase.cs +++ b/Discord.Addons.Interactive/InteractiveBase.cs @@ -7,18 +7,20 @@ namespace Discord.Addons.Interactive { - public abstract class InteractiveBase : InteractiveBase + public abstract class InteractiveBase + : InteractiveBase { } - public abstract class InteractiveBase : ModuleBase + public abstract class InteractiveBase + : ModuleBase where T : SocketCommandContext { public InteractiveService Interactive { get; set; } - public Task NextMessageAsync(ICriterion criterion, TimeSpan? timeout = null, CancellationToken token = default(CancellationToken)) + public Task NextMessageAsync(ICriterion criterion, TimeSpan? timeout = null, CancellationToken token = default) => Interactive.NextMessageAsync(Context, criterion, timeout, token); - public Task NextMessageAsync(bool fromSourceUser = true, bool inSourceChannel = true, TimeSpan? timeout = null, CancellationToken token = default(CancellationToken)) + public Task NextMessageAsync(bool fromSourceUser = true, bool inSourceChannel = true, TimeSpan? timeout = null, CancellationToken token = default) => Interactive.NextMessageAsync(Context, fromSourceUser, inSourceChannel, timeout, token); public Task ReplyAndDeleteAsync(string content, bool isTTS = false, Embed embed = null, TimeSpan? timeout = null, RequestOptions options = null) @@ -32,6 +34,7 @@ public Task PagedReplyAsync(IEnumerable pages, bool fromSo }; return PagedReplyAsync(pager, fromSourceUser); } + public Task PagedReplyAsync(PaginatedMessage pager, bool fromSourceUser = true) { var criterion = new Criteria(); @@ -39,6 +42,7 @@ public Task PagedReplyAsync(PaginatedMessage pager, bool fromSourc criterion.AddCriterion(new EnsureReactionFromSourceUserCriterion()); return PagedReplyAsync(pager, criterion); } + public Task PagedReplyAsync(PaginatedMessage pager, ICriterion criterion) => Interactive.SendPaginatedMessageAsync(Context, pager, criterion); diff --git a/Discord.Addons.Interactive/InteractiveService.cs b/Discord.Addons.Interactive/InteractiveService.cs index 6a9e421..5499a4a 100644 --- a/Discord.Addons.Interactive/InteractiveService.cs +++ b/Discord.Addons.Interactive/InteractiveService.cs @@ -7,19 +7,24 @@ namespace Discord.Addons.Interactive { - public class InteractiveService : IDisposable + public class InteractiveService + : IDisposable { public BaseSocketClient Discord { get; } - private Dictionary _callbacks; - private TimeSpan _defaultTimeout; + private readonly Dictionary _callbacks; + private readonly TimeSpan _defaultTimeout; // helpers to allow DI containers to resolve without a custom factory public InteractiveService(DiscordSocketClient discord, InteractiveServiceConfig config = null) - : this((BaseSocketClient)discord, config) {} - + : this((BaseSocketClient)discord, config) + { + } + public InteractiveService(DiscordShardedClient discord, InteractiveServiceConfig config = null) - : this((BaseSocketClient)discord, config) {} + : this((BaseSocketClient)discord, config) + { + } public InteractiveService(BaseSocketClient discord, InteractiveServiceConfig config = null) { @@ -32,24 +37,27 @@ public InteractiveService(BaseSocketClient discord, InteractiveServiceConfig con _callbacks = new Dictionary(); } - public Task NextMessageAsync(SocketCommandContext context, + public Task NextMessageAsync( + SocketCommandContext context, bool fromSourceUser = true, bool inSourceChannel = true, TimeSpan? timeout = null, - CancellationToken token = default(CancellationToken)) + CancellationToken token = default) { var criterion = new Criteria(); if (fromSourceUser) criterion.AddCriterion(new EnsureSourceUserCriterion()); if (inSourceChannel) criterion.AddCriterion(new EnsureSourceChannelCriterion()); + return NextMessageAsync(context, criterion, timeout, token); } - public async Task NextMessageAsync(SocketCommandContext context, + public async Task NextMessageAsync( + SocketCommandContext context, ICriterion criterion, TimeSpan? timeout = null, - CancellationToken token = default(CancellationToken)) + CancellationToken token = default) { timeout = timeout ?? _defaultTimeout; @@ -103,17 +111,17 @@ public async Task SendPaginatedMessageAsync(SocketCommandContext c return callback.Message; } - public void AddReactionCallback(IMessage message, IReactionCallback callback) - => _callbacks[message.Id] = callback; - public void RemoveReactionCallback(IMessage message) - => RemoveReactionCallback(message.Id); - public void RemoveReactionCallback(ulong id) - => _callbacks.Remove(id); - public void ClearReactionCallbacks() - => _callbacks.Clear(); + public void AddReactionCallback(IMessage message, IReactionCallback callback) => _callbacks[message.Id] = callback; + + public void RemoveReactionCallback(IMessage message) => RemoveReactionCallback(message.Id); + + public void RemoveReactionCallback(ulong id) => _callbacks.Remove(id); + + public void ClearReactionCallbacks() => _callbacks.Clear(); - private async Task HandleReactionAsync(Cacheable message, - ISocketMessageChannel channel, + private async Task HandleReactionAsync( + Cacheable message, + Cacheable cacheable, SocketReaction reaction) { if (reaction.UserId == Discord.CurrentUser.Id) return; diff --git a/Discord.Addons.Interactive/Paginator/EnsureReactionFromSourceUserCriterion.cs b/Discord.Addons.Interactive/Paginator/EnsureReactionFromSourceUserCriterion.cs index 9444d5e..af5fe14 100644 --- a/Discord.Addons.Interactive/Paginator/EnsureReactionFromSourceUserCriterion.cs +++ b/Discord.Addons.Interactive/Paginator/EnsureReactionFromSourceUserCriterion.cs @@ -4,12 +4,12 @@ namespace Discord.Addons.Interactive { - internal class EnsureReactionFromSourceUserCriterion : ICriterion + internal class EnsureReactionFromSourceUserCriterion + : ICriterion { public Task JudgeAsync(SocketCommandContext sourceContext, SocketReaction parameter) { - bool ok = parameter.UserId == sourceContext.User.Id; - return Task.FromResult(ok); + return Task.FromResult(parameter.UserId == sourceContext.User.Id); } } } diff --git a/SampleApp/SampleApp.csproj b/SampleApp/SampleApp.csproj index d3de106..25a000e 100644 --- a/SampleApp/SampleApp.csproj +++ b/SampleApp/SampleApp.csproj @@ -2,17 +2,23 @@ Exe - netcoreapp3.1 + net6.0 - - - + + + + + + PreserveNewest + + + \ No newline at end of file