示例#1
0
        public async Task SetupMessage()
        {
            PostedMessages = new Collection <IMessage>();
            Interactive.ClearReactionCallbacks();
            if (this.beforeTextPosted != null)
            {
                this.beforeTextPosted(this);
            }
            if (additionalPosts.Count > 0)
            {
                var additionalPostsString = new StringBuilder();
                foreach (var text in additionalPosts)
                {
                    additionalPostsString.Append(text + Environment.NewLine);
                }
                var value = additionalPostsString.ToString();
                if (value != string.Empty)
                {
                    var message = await Context.Channel.SendMessageAsync(value);

                    PostedMessages.Add(message);
                }
            }

            this.Message = await Context.Channel.SendMessageAsync(description);

            PostedMessages.Add(this.Message);
            if (type == StepType.Reaction)
            {
                var emotes = new Collection <IEmote>();
                foreach (var action in Actions)
                {
                    emotes.Add(action.Emote);
                }
                await Message.AddReactionsAsync(emotes.ToArray());

                Interactive.AddReactionCallback(this.Message, this);
            }
            else
            {
                var response = await Interactive.NextMessageAsync(Context, true, true, TimeSpan.FromMinutes(2));

                Result = response.Content;
                await response.DeleteAsync();
                await RemoveMessagesOnNextProgression();

                reactBasedOnResult();
            }

            if (Timeout.HasValue && Timeout.Value != null)
            {
                _ = Task.Delay(Timeout.Value).ContinueWith(async _ =>
                {
                    if (Message != null)
                    {
                        Interactive.RemoveReactionCallback(Message);
                    }

                    foreach (var message in PostedMessages)
                    {
                        await message.DeleteAsync();
                    }
                });
            }
        }