Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicQueryAttribute"/> class.
 /// Also, Finds and constructs DynamicQueryOptions class in the parameters.
 /// </summary>
 /// <param name="maxCountSize">Max data set count for the result set.</param>
 /// <param name="includeDataSetCountToPagination">Includes the total data set count to the options class.</param>
 /// <param name="exceededPaginationCountBehaviour">Behaviour when the requested data set count greater than max count size.</param>
 public DynamicQueryAttribute(
     int maxCountSize = 100,
     bool includeDataSetCountToPagination = true,
     PaginationBehaviour exceededPaginationCountBehaviour = PaginationBehaviour.GetMax)
 {
     _maxCountSize = maxCountSize;
     _includeDataSetCountToPagination  = includeDataSetCountToPagination;
     _exceededPaginationCountBehaviour = exceededPaginationCountBehaviour;
 }
Beispiel #2
0
        /// <summary>
        /// Replys with a paginated message
        /// </summary>
        /// <param name="c"></param>
        /// <param name="u"></param>
        /// <param name="pages"></param>
        /// <param name="emojis"></param>
        /// <param name="behaviour"></param>
        /// <param name="deletion"></param>
        /// <param name="timeoutoverride"></param>
        /// <returns></returns>
        public static async Task ReplyPaginatedAsync(this CommandContext ctx, IEnumerable <Page> pages,
                                                     PaginationEmojis emojis       = null,
                                                     PaginationBehaviour behaviour = PaginationBehaviour.Default,
                                                     PaginationDeletion deletion   = PaginationDeletion.Default,
                                                     TimeSpan?timeoutoverride      = null)
        {
            var m = await ctx.ReplyAsync(pages.First().Content, pages.First().Embed);

            var timeout = timeoutoverride ?? TimeSpan.FromMinutes(1);

            var ems      = emojis ?? new PaginationEmojis();
            var prequest = new KoalaBot.Interactivity.PaginationRequest(m, ctx.Member, behaviour, deletion, ems, timeout, pages.ToArray());
            await ctx.Client.GetInteractivity().WaitForCustomPaginationAsync(prequest);
        }
Beispiel #3
0
        /// <summary>
        /// Method for configuring <see cref="InteractivityExtension"/>, accessing each configuration individually.
        /// </summary>
        /// <param name="timeout">Sets the default interactivity action timeout. Defaults to 5 minutes.</param>
        /// <param name="pollBehaviour">What to do after the poll ends. Defaults to <see cref="PollBehaviour.DeleteEmojis"/>.</param>
        /// <param name="paginationEmojis">Emojis to use for pagination. Defaults to <see langword="null"/>.</param>
        /// <param name="paginationBehaviour">How to handle pagination. Defaults to <see cref="PaginationBehaviour.WrapAround"/>.</param>
        /// <param name="paginationDeletion">How to handle pagination deletion. Defaults to <see cref="PaginationDeletion.DeleteEmojis"/>.</param>
        public void InteractivitySetup(TimeSpan?timeout = null, PollBehaviour pollBehaviour = PollBehaviour.DeleteEmojis, PaginationEmojis paginationEmojis = null,
                                       PaginationBehaviour paginationBehaviour = PaginationBehaviour.WrapAround, PaginationDeletion paginationDeletion = PaginationDeletion.DeleteEmojis)
        {
            _discordClient.IsNotNull(this.MessageErrorDiscordClientIsNull);

            _interactivity = _discordClient.UseInteractivity(new InteractivityConfiguration
            {
                Timeout             = timeout ?? TimeSpan.FromMinutes(5),
                PollBehaviour       = pollBehaviour,
                PaginationEmojis    = paginationEmojis ?? new PaginationEmojis(),
                PaginationBehaviour = paginationBehaviour,
                PaginationDeletion  = paginationDeletion
            });
        }
        /// <summary>
        /// Sends a paginated message.
        /// </summary>
        /// <param name="c">Channel to send paginated message in.</param>
        /// <param name="u">User to give control.</param>
        /// <param name="pages">Pages.</param>
        /// <param name="emojis">Pagination emojis (emojis set to null get disabled).</param>
        /// <param name="behaviour">Pagination behaviour (when hitting max and min indices).</param>
        /// <param name="deletion">Deletion behaviour.</param>
        /// <param name="timeoutoverride">Override timeout period.</param>
        /// <returns></returns>
        public async Task SendPaginatedMessageAsync(DiscordChannel c, DiscordUser u, IEnumerable <Page> pages, PaginationEmojis emojis = null,
                                                    PaginationBehaviour behaviour = PaginationBehaviour.Default, PaginationDeletion deletion = PaginationDeletion.Default, TimeSpan?timeoutoverride = null)
        {
            var m = await c.SendMessageAsync(pages.First().Content, false, pages.First().Embed);

            var timeout = timeoutoverride ?? Config.Timeout;

            var bhv = behaviour == PaginationBehaviour.Default ? this.Config.PaginationBehaviour : behaviour;
            var del = deletion == PaginationDeletion.Default ? this.Config.PaginationDeletion : deletion;
            var ems = emojis ?? this.Config.PaginationEmojis;

            var prequest = new PaginationRequest(m, u, bhv, del, ems, timeout, pages.ToArray());

            await Paginator.DoPaginationAsync(prequest);
        }
        public void ShouldSetGivenCtorValues()
        {
            int  changedMaxCountSize        = 200;
            bool changedIncludedataSetCount = false;
            PaginationBehaviour changedPaginationBehaviour = PaginationBehaviour.Throw;

            var parameterlessInstance = new DynamicQueryAttribute();
            var parameteredInstance   = new DynamicQueryAttribute(200, false, PaginationBehaviour.Throw);

            Assert.Equal(parameterlessInstance._maxCountSize, _defaultMaxCountSize);
            Assert.Equal(parameterlessInstance._includeDataSetCountToPagination, _defaultIncludeDataSetCount);
            Assert.Equal(parameterlessInstance._exceededPaginationCountBehaviour, _defaultPaginationBehaviour);

            Assert.Equal(parameteredInstance._maxCountSize, changedMaxCountSize);
            Assert.Equal(parameteredInstance._includeDataSetCountToPagination, changedIncludedataSetCount);
            Assert.Equal(parameteredInstance._exceededPaginationCountBehaviour, changedPaginationBehaviour);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new Pagination request
        /// </summary>
        /// <param name="message">Message to paginate</param>
        /// <param name="user">User to allow control for</param>
        /// <param name="behaviour">Behaviour during pagination</param>
        /// <param name="deletion">Behavior on pagination end</param>
        /// <param name="emojis">Emojis for this pagination object</param>
        /// <param name="timeout">Timeout time</param>
        /// <param name="pages">Pagination pages</param>
        internal PaginationRequest(DiscordMessage message, DiscordUser user, PaginationBehaviour behaviour, PaginationDeletion deletion,
                                   PaginationEmojis emojis, TimeSpan timeout, params Page[] pages)
        {
            this._tcs = new TaskCompletionSource <bool>();
            this._ct  = new CancellationTokenSource(timeout);
            this._ct.Token.Register(() => _tcs.TrySetResult(true));
            this._timeout = timeout;

            this._message = message;
            this._user    = user;

            this._deletion  = deletion;
            this._behaviour = behaviour;
            this._emojis    = emojis;

            this._pages = new List <Page>();
            foreach (var p in pages)
            {
                this._pages.Add(p);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Sends a paginated message
 /// </summary>
 /// <param name="c">Channel to send message in.</param>
 /// <param name="user">User to control pagination.</param>
 /// <param name="pages">Pages to send.</param>
 /// <param name="emojis">Pagination emojis (emojis set to null will be disabled)</param>
 /// <param name="behaviour">Pagination behaviour.</param>
 /// <param name="deletion">Deletion behaviour.</param>
 /// <param name="timeoutoverride">Override timeout period.</param>
 /// <returns></returns>
 public static async Task SendPaginatedMessageAsync(this DiscordChannel c, DiscordUser user, Page[] pages, PaginationEmojis emojis,
                                                    PaginationBehaviour behaviour = PaginationBehaviour.Default, PaginationDeletion deletion = PaginationDeletion.Default,
                                                    TimeSpan?timeoutoverride      = null)
 => await((DiscordClient)c.Discord).GetInteractivity().SendPaginatedMessageAsync(c, user, pages, emojis, behaviour, deletion, timeoutoverride);