Exemplo n.º 1
0
        /// <inheritdoc />
        public override async Task <ExportedRoleplay> ExportAsync(Roleplay roleplay)
        {
            var owner = await this.Context.Guild.GetUserAsync((ulong)roleplay.Owner.DiscordID);

            var filePath = Path.GetTempFileName();

            using (var of = File.Create(filePath))
            {
                using (var ofw = new StreamWriter(of))
                {
                    await ofw.WriteLineAsync($"Roleplay name: {roleplay.Name}");

                    await ofw.WriteLineAsync($"Owner: {owner.Username}");

                    var joinedUsers = await Task.WhenAll(roleplay.JoinedUsers.Select(p => this.Context.Guild.GetUserAsync((ulong)p.User.DiscordID)));

                    await ofw.WriteLineAsync("Participants:");

                    foreach (var participant in joinedUsers)
                    {
                        await ofw.WriteLineAsync(participant.Username);
                    }

                    await ofw.WriteLineAsync();

                    await ofw.WriteLineAsync();

                    var messages = roleplay.Messages.OrderBy(m => m.Timestamp).DistinctBy(m => m.Contents);
                    foreach (var message in messages)
                    {
                        await ofw.WriteLineAsync($"{message.AuthorNickname}: \n{message.Contents}");

                        await ofw.WriteLineAsync();
                    }
                }
            }

            var resultFile = File.OpenRead(filePath);
            var exported   = new ExportedRoleplay(roleplay.Name, ExportFormat.Plaintext, resultFile);

            return(exported);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override async Task <ExportedRoleplay> ExportAsync(Roleplay roleplay)
        {
            // Create our document
            var pdfDoc = new Document();

            var filePath = Path.GetTempFileName();

            using (var of = File.Create(filePath))
            {
                using (PdfWriter.GetInstance(pdfDoc, of))
                {
                    pdfDoc.Open();

                    var owner = await this.Context.Guild.GetUserAsync((ulong)roleplay.Owner.DiscordID);

                    pdfDoc.AddAuthor(owner.Nickname);
                    pdfDoc.AddCreationDate();
                    pdfDoc.AddCreator("DIGOS Ambassador");
                    pdfDoc.AddTitle(roleplay.Name);

                    var joinedUsers = await Task.WhenAll(roleplay.JoinedUsers.Select(p => this.Context.Guild.GetUserAsync((ulong)p.User.DiscordID)));

                    pdfDoc.Add(CreateTitle(roleplay.Name));
                    pdfDoc.Add(CreateParticipantList(joinedUsers));

                    pdfDoc.NewPage();

                    var messages = roleplay.Messages.OrderBy(m => m.Timestamp).DistinctBy(m => m.Contents);
                    foreach (var message in messages)
                    {
                        pdfDoc.Add(CreateMessage(message.AuthorNickname, message.Contents));
                    }

                    pdfDoc.Close();
                }
            }

            var resultFile = File.OpenRead(filePath);
            var exported   = new ExportedRoleplay(roleplay.Name, ExportFormat.PDF, resultFile);

            return(exported);
        }