Exemple #1
0
        public async Task SendPages(IMessageChannel channel, PageFormat pageFormat)
        {
            var channelObj = await _messageChannelRepository.FindAsync(channel.Id);

            if (channelObj == null)
            {
                channelObj = (channel is IDMChannel dmChannel)
                    ? _messageChannelFactory.CreateNewDM(channel.Id, dmChannel.Recipient.Id)
                    : null;
                channelObj = (channel is IGuildChannel guildChannel)
                    ? _messageChannelFactory.CreateNewServerMessage(channel.Id, guildChannel.GuildId)
                    : channelObj;
                if (channelObj == null)
                {
                    return;
                }
                await _messageChannelRepository.PostAsync(channelObj);
            }

            var paginatedMessage = new PaginatedMessage()
            {
                Pages            = BuildPages(pageFormat),
                HasHiddenContent = pageFormat.HasHiddenColumns
            };

            if (paginatedMessage.Pages.Count == 0)
            {
                return;
            }
            if (paginatedMessage.HasHiddenContent)
            {
                var revealedPages = BuildPages(pageFormat.RevealedPageFormat);
                revealedPages.ForEach(p => p.IsHidden = true);
                paginatedMessage.Pages.AddRange(revealedPages);
            }
            var message = await channel.SendMessageAsync(paginatedMessage.Pages.First().Content);

            paginatedMessage.Id = message.Id;
            paginatedMessage.MessageChannelId = channelObj.Id;
            if (paginatedMessage.Pages.Count != 1)
            {
                if (paginatedMessage.StandardPages.Count > 1)
                {
                    await message.AddReactionAsync(new Emoji(ArrowBackward));

                    await message.AddReactionAsync(new Emoji(ArrowForward));
                }

                if (pageFormat.HasHiddenColumns)
                {
                    await message.AddReactionAsync(pageFormat.RevealEmote);
                }
            }
            await _paginatedMessageRepository.PostAsync(paginatedMessage);

            await _messageChannelRepository.SaveAllChangesAsync();
        }
Exemple #2
0
        public async Task <MessageChannel> AddOrGetChannel(ICommandContext context, bool saveContext = false)
        {
            var existing = await _repository.FindAsync(context.Channel.Id);

            if (existing != null)
            {
                return(existing);
            }
            var channel = new MessageChannel()
            {
                Id       = context.Channel.Id,
                ServerId = context.Guild.Id
            };
            await _repository.PostAsync(channel);

            if (saveContext)
            {
                await _repository.SaveAllChangesAsync();
            }
            return(channel);
        }