Пример #1
0
        private async Task OnCollect(SocketReaction reaction)
        {
            var emote             = reaction.Emote;
            var hasManageMessages = false;

            if (reaction.Channel is SocketTextChannel textChannel)
            {
                hasManageMessages = textChannel.Guild.CurrentUser.GetPermissions(textChannel).ManageMessages;

                if (hasManageMessages)
                {
                    await _message.RemoveReactionAsync(emote, reaction.UserId).ConfigureAwait(false);
                }
            }

            if (emote.Equals(Reactions.Front))
            {
                if (_currentPageIndex == 0)
                {
                    return;
                }
                _currentPageIndex = 0;
            }
            else if (emote.Equals(Reactions.Rear))
            {
                if (_currentPageIndex == _lastPageIndex)
                {
                    return;
                }
                _currentPageIndex = _lastPageIndex;
            }
            else if (emote.Equals(Reactions.Previous))
            {
                if (_circularEnabled)
                {
                    if (_currentPageIndex == 0)
                    {
                        _currentPageIndex = _lastPageIndex;
                    }
                    else
                    {
                        _currentPageIndex--;
                    }
                }
                else
                {
                    if (_currentPageIndex == 0)
                    {
                        return;
                    }
                    _currentPageIndex--;
                }
            }
            else if (emote.Equals(Reactions.Next))
            {
                if (_circularEnabled)
                {
                    if (_currentPageIndex == _lastPageIndex)
                    {
                        _currentPageIndex = 0;
                    }
                    else
                    {
                        _currentPageIndex++;
                    }
                }
                else
                {
                    if (_currentPageIndex == _lastPageIndex)
                    {
                        return;
                    }
                    _currentPageIndex++;
                }
            }
            else if (emote.Equals(Reactions.Stop))
            {
                _collector.Stop();
                return;
            }
            else if (emote.Equals(Reactions.Trash))
            {
                _collector.Stop();
                await _message.DeleteAsync().ConfigureAwait(false);

                return;
            }
            else if (emote.Equals(Reactions.Jump))
            {
                var promptMessage = _jumpOptions.PromptEnabled
                    ? await _message.Channel.SendMessageAsync(_jumpOptions.Prompt).ConfigureAwait(false)
                    : null;

                var collectorConfig = new MessageCollectorConfig(_client)
                {
                    Channel = _message.Channel,
                    Timeout = _jumpOptions.Timeout,
                    Max     = 1
                };

                var messageCollector = new MessageCollector(
                    x => x.Author.Id == reaction.UserId, collectorConfig);

                var collected = await messageCollector.StartAsync().ConfigureAwait(false);

                var collectedMessage = collected.FirstOrDefault();

                if (promptMessage != null)
                {
                    await promptMessage.DeleteAsync().ConfigureAwait(false);
                }

                if (collectedMessage != null)
                {
                    if (_jumpOptions.DeleteResponse && hasManageMessages)
                    {
                        await collectedMessage.DeleteAsync().ConfigureAwait(false);
                    }

                    if (int.TryParse(collectedMessage.Content, out var pageNumber) &&
                        pageNumber >= 1 && pageNumber <= _pageCount)
                    {
                        _currentPageIndex = pageNumber - 1;
                    }
                }
            }
            else if (emote.Equals(Reactions.Info))
            {
                var message = await _message.Channel.SendMessageAsync(_infoOptions.Text).ConfigureAwait(false);

                await Task.Delay(_infoOptions.Timeout).ConfigureAwait(false);

                await message.DeleteAsync().ConfigureAwait(false);

                return;
            }

            await EditMessageAsync().ConfigureAwait(false);
        }