Exemple #1
0
        public async Task CollectAsync(double timeoutSeconds, bool resetTimeoutOnMatch = false, int?capacity = null)
        {
            MessageCollector  collector = new MessageCollector(Context.Client);
            CollectionOptions options   = new CollectionOptions {
                ResetTimeoutOnMatch = resetTimeoutOnMatch,
                Timeout             = TimeSpan.FromSeconds(timeoutSeconds), Capacity = capacity, IncludeFailedMatches = false
            };

            FilterCollection c = await collector.CollectAsync(
                delegate(SocketMessage msg, FilterCollection matches, int i)
            {
                return(msg.Content.StartsWith("ok"));
            }, options);

            StringBuilder sb = new StringBuilder();

            sb.Append($"The **MessageFilter** found **{c.Count}** successful {Format.TryPluralize("match", c.Count)}. ({Format.Counter(collector.ElapsedTime?.TotalSeconds ?? 0)})");
            if (c.Count > 0)
            {
                sb.Append(Discord.Format.Code($"{string.Join("\n", c.Select(x => $"[{x.Index}]: {x.Message.Content}"))}", "autohotkey"));
            }

            await Context.Channel.SendMessageAsync(sb.ToString());
        }