예제 #1
0
        public async Task SendWebhookFilesAsync(CommandContext ctx)
        {
            var webhook = await ctx.Channel.CreateWebhookAsync("webhook-test");

            using (var fs = new FileStream("ADumbFile.txt", FileMode.Open, FileAccess.Read))
            {
                // Verify that the lib resets the position when asked
                var builder = new DiscordWebhookBuilder()
                              .WithContent("Testing the `AddFile(Dictionary<string, stream>)` Overload with resetting the postion turned on.")
                              .AddFiles(new Dictionary <string, Stream>()
                {
                    { "ADumbFile1.txt", fs }
                }, true);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);

                builder.Clear();

                //Verify the lib doesnt reset the position.  THe file sent should have 0 bytes.
                builder.WithContent("Testing the `AddFile(Dictionary<string, stream> files)` Overload with resetting the postion turned off  The 2nd file sent should have 0 bytes.")
                .AddFiles(new Dictionary <string, Stream>()
                {
                    { "ADumbFile1.txt", fs }
                }, false);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);

                builder.Clear();

                fs.Position = 0;

                // Verify that the lib resets the position when asked
                builder.WithContent("Testing the `AddFile(Stream stream)` Overload with resetting the postion turned on.")
                .AddFile(fs, true);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);

                builder.Clear();

                //Verify the lib doesnt reset the position.  THe file sent should have 0 bytes.
                builder.WithContent("Testing the `AddFile(Stream stream)` Overload with resetting the postion turned off.  The 2nd file sent should have 0 bytes.")
                .AddFile(fs, false);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);

                builder.Clear();
                fs.Position = 0;


                // Verify that the lib resets the position when asked
                builder.WithContent("Testing the `AddFile(string fileName, Stream stream)` Overload with resetting the postion turned on.")
                .AddFile("ADumbFile2.txt", fs, true);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);

                builder.Clear();

                //Verify the lib doesnt reset the position.  THe file sent should have 0 bytes.
                builder.WithContent("Testing the `AddFile(string fileName, Stream stream)` Overload with resetting the postion turned off.  The 2nd file sent should have 0 bytes.")
                .AddFile("ADumbFile2.txt", fs, false);

                await builder.SendAsync(webhook);

                await builder.SendAsync(webhook);
            }

            await webhook.DeleteAsync();
        }