Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EnsureFromUserCriterion(ulong id)

public Task<bool> JudgeAsync(SocketCommandContext sourceContext, IMessage parameter)
{
bool ok = _id == parameter.Author.Id;
var ok = _id == parameter.Author.Id;
return Task.FromResult(ok);
}
}
Expand Down
22 changes: 6 additions & 16 deletions Discord.Addons.Interactive/InteractiveBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public abstract class InteractiveBase : InteractiveBase<SocketCommandContext>
{
}

public abstract class InteractiveBase<T> : ModuleBase<T>
where T : SocketCommandContext
public abstract class InteractiveBase<T> : ModuleBase<T> where T : SocketCommandContext
{
public InteractiveService Interactive { get; set; }

Expand All @@ -31,26 +30,17 @@ public Task<IUserMessage> ReplyAndDeleteAsync(string content, bool isTTS = false

public Task<IUserMessage> InlineReactionReplyAsync(ReactionCallbackData data, bool fromSourceUser = true)
=> Interactive.SendMessageWithReactionCallbacksAsync(Context, data, fromSourceUser);

public Task<IUserMessage> PagedReplyAsync(IEnumerable<object> pages, bool fromSourceUser = true)
{
var pager = new PaginatedMessage
{
Pages = pages
};
return PagedReplyAsync(pager, fromSourceUser);
}

public Task<IUserMessage> PagedReplyAsync(PaginatedMessage pager, bool fromSourceUser = true)

public Task<IUserMessage> PagedReplyAsync(PaginatedMessage pager, ReactionList reactions, bool fromSourceUser = true)
{
var criterion = new Criteria<SocketReaction>();
if (fromSourceUser)
criterion.AddCriterion(new EnsureReactionFromSourceUserCriterion());
return PagedReplyAsync(pager, criterion);
return PagedReplyAsync(pager, reactions, criterion);
}

public Task<IUserMessage> PagedReplyAsync(PaginatedMessage pager, ICriterion<SocketReaction> criterion)
=> Interactive.SendPaginatedMessageAsync(Context, pager, criterion);
public Task<IUserMessage> PagedReplyAsync(PaginatedMessage pager, ReactionList reactions, ICriterion<SocketReaction> criterion)
=> Interactive.SendPaginatedMessageAsync(Context, pager, reactions, criterion);

public RuntimeResult Ok(string reason = null) => new OkResult(reason);
}
Expand Down
32 changes: 11 additions & 21 deletions Discord.Addons.Interactive/InteractiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InteractiveService : IDisposable
private readonly Dictionary<ulong, IReactionCallback> _callbacks;
private readonly TimeSpan _defaultTimeout;

// helpers to allow DI containers to resolve without a custom factory
// Helpers to allow DI containers to resolve without a custom factory
public InteractiveService(DiscordSocketClient discord, InteractiveServiceConfig config = null)
: this((BaseSocketClient)discord, config) { }

Expand All @@ -43,10 +43,13 @@ public Task<SocketMessage> NextMessageAsync(SocketCommandContext context,
CancellationToken token = default)
{
var criterion = new Criteria<SocketMessage>();

if (fromSourceUser)
criterion.AddCriterion(new EnsureSourceUserCriterion());

if (inSourceChannel)
criterion.AddCriterion(new EnsureSourceChannelCriterion());

return NextMessageAsync(context, criterion, timeout, token);
}

Expand Down Expand Up @@ -80,8 +83,7 @@ async Task Handler(SocketMessage message)

if (task == trigger)
return await trigger.ConfigureAwait(false);
else
return null;
return null;
}

public async Task<IUserMessage> ReplyAndDeleteAsync(SocketCommandContext context,
Expand All @@ -97,23 +99,10 @@ public async Task<IUserMessage> ReplyAndDeleteAsync(SocketCommandContext context
.ConfigureAwait(false);
return message;
}

/// <summary>
/// Sends a message with reaction callbacks
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <param name="reactionCallbackData">
/// The callbacks.
/// </param>
/// <param name="fromSourceUser">
/// The from source user.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public async Task<IUserMessage> SendMessageWithReactionCallbacksAsync(SocketCommandContext context, ReactionCallbackData reactionCallbackData, bool fromSourceUser = true)

public async Task<IUserMessage> SendMessageWithReactionCallbacksAsync(SocketCommandContext context,
ReactionCallbackData reactionCallbackData,
bool fromSourceUser = true)
{
var criterion = new Criteria<SocketReaction>();
if (fromSourceUser)
Expand All @@ -128,10 +117,11 @@ public async Task<IUserMessage> SendMessageWithReactionCallbacksAsync(SocketComm

public async Task<IUserMessage> SendPaginatedMessageAsync(SocketCommandContext context,
PaginatedMessage pager,
ReactionList reactions,
ICriterion<SocketReaction> criterion = null)
{
var callback = new PaginatedMessageCallback(this, context, pager, criterion);
await callback.DisplayAsync().ConfigureAwait(false);
await callback.DisplayAsync(reactions).ConfigureAwait(false);
return callback.Message;
}

Expand Down
43 changes: 27 additions & 16 deletions Discord.Addons.Interactive/Paginator/PaginatedAppearanceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@ namespace Discord.Addons.Interactive.Paginator
{
public class PaginatedAppearanceOptions
{
public static PaginatedAppearanceOptions Default = new PaginatedAppearanceOptions();
public IEmote First { get; set; } = new Emoji("⏮");

public IEmote Back { get; set; } = new Emoji("◀");

public IEmote Next { get; set; } = new Emoji("▶");

public IEmote Last { get; set; } = new Emoji("⏭");

public IEmote Stop { get; set; } = new Emoji("⏹");

public IEmote Jump { get; set; } = new Emoji("🔢");

public IEmote Info { get; set; } = new Emoji("ℹ");

public IEmote First = new Emoji("⏮");
public IEmote Back = new Emoji("◀");
public IEmote Next = new Emoji("▶");
public IEmote Last = new Emoji("⏭");
public IEmote Stop = new Emoji("⏹");
public IEmote Jump = new Emoji("🔢");
public IEmote Info = new Emoji("ℹ");
public string FooterFormat { get; set; } = "Page {0}/{1}";

public string FooterFormat = "Page {0}/{1}";
public string InformationText = "This is a paginator. React with the respective icons to change page.";
public string InformationTitle { get; set; } = "Paginator Information";

public string InformationText { get; set; } = "This funny-looking embed is called a **Paginator**. It's just like a book. You can flip through the pages using the arrows, enter the number of the page you want to navigate to, or close the it entirely.";

public JumpDisplayOptions JumpDisplayOptions = JumpDisplayOptions.WithManageMessages;
public bool DisplayInformationIcon = true;
public Color InformationColor { get; set; } = new Color(252, 166, 205);

public JumpDisplayOptions JumpDisplayOptions { get; set; } = JumpDisplayOptions.WithManageMessages;

public bool DisplayInformationIcon { get; set; } = true;

public TimeSpan? Timeout { get; set; } = null;

public TimeSpan InfoTimeout { get; set; } = TimeSpan.FromSeconds(10);

public TimeSpan? Timeout = null;
public TimeSpan InfoTimeout = TimeSpan.FromSeconds(30);

public int FieldsPerPage = 6;
public static PaginatedAppearanceOptions Default { get; set; } = new PaginatedAppearanceOptions();
}

public enum JumpDisplayOptions
Expand Down
77 changes: 50 additions & 27 deletions Discord.Addons.Interactive/Paginator/PaginatedMessage.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Discord.Addons.Interactive.Paginator
{
public class PaginatedMessage
{
/// <summary>
/// Pages contains a collection of elements to page over in the embed. It is expected
/// that a string-like object is used in this collection, as objects will be converted
/// to a displayable string only through their generic ToString method, with the
/// exception of EmbedFieldBuilders.
///
/// If this collection is of EmbedFieldBuilder, then the pages will be displayed in
/// batches of <see cref="PaginatedAppearanceOptions.FieldsPerPage"/>, and the
/// embed's description will be populated with the <see cref="AlternateDescription"/> field.
/// </summary>
public IEnumerable<object> Pages { get; set; }

/// <summary>
/// Content sets the content of the message, displayed above the embed. This may remain empty.
/// </summary>
public string Content { get; set; } = "";

/// <summary>
/// Author sets the <see cref="EmbedBuilder.Author"/> property directly.
/// </summary>
public IEnumerable<EmbedPage> Pages { get; set; } = new List<EmbedPage>();

public string Content { get; set; } = string.Empty;

public EmbedAuthorBuilder Author { get; set; } = null;

public Color Color { get; set; } = Color.Default;
public string Title { get; set; } = "";
public string Title { get; set; } = null;

public string Url { get; set; } = null;

public string Description { get; set; } = string.Empty;

/// <summary>
/// AlternateDescription will be used as the description of the pager only when
/// <see cref="Pages"/> is a collection of <see cref="EmbedFieldBuilder"/>.
/// </summary>
public string AlternateDescription { get; set; } = "";
public string ImageUrl { get; set; } = null;

public string ThumbnailUrl { get; set; } = null;

public List<EmbedFieldBuilder> Fields { get; set; } = new List<EmbedFieldBuilder>();

public EmbedFooterBuilder FooterOverride { get; set; } = null;

public DateTimeOffset? TimeStamp { get; set; } = null;
public PaginatedAppearanceOptions Options { get; set; } = PaginatedAppearanceOptions.Default;
}

public class EmbedPage
{
public string AlternateAuthorTitle { get; set; }

public string AlteranteAuthorIcon { get; set; }

public bool DisplayTotalFieldsCount { get; set; } = false;

public string TotalFieldsMessage { get; set; } = null;

public double TotalFieldsCountConstant { get; set; } = 1;

public string Title { get; set; }

public string Url { get; set; } = null;

public string Description { get; set; }

public string ImageUrl { get; set; }

public string ThumbnailUrl { get; set; } = null;

public List<EmbedFieldBuilder> Fields { get; set; } = new List<EmbedFieldBuilder>();

public EmbedFooterBuilder FooterOverride { get; set; } = null;

public DateTimeOffset? TimeStamp { get; set; } = null;

public Color? Color { get; set; } = null;
}
}
Loading