コード例 #1
0
        public async Task HandleArchiveCommand(ITextChannel channel, [Remainder] string category)
        {
            if (string.IsNullOrEmpty(category))
            {
                return;
            }

            category = new CultureInfo("en-GB", false).TextInfo.ToTitleCase(category);
            string env = HARDCODED_ARCHIVE_PATH;

            Guild g = new Guild(new Snowflake(Context.Guild.Id), Context.Guild.Name, Context.Guild.IconUrl);
            var   discordCategory = channel.CategoryId.HasValue ? await channel.GetCategoryAsync() : null;

            ChannelCategory cc = new ChannelCategory(new Snowflake(channel.CategoryId.Value), discordCategory.Name, discordCategory.Position);
            Channel         c  = new Channel(new Snowflake(channel.Id), ChannelKind.GuildTextChat, g.Id, cc, channel.Name, channel.Position, channel.Topic);

            ExportRequest req = new ExportRequest(g, c, env + $"/{category}/Light/{channel.Name}.html", ExportFormat.HtmlLight,
                                                  null, null, PartitionLimit.Null, MessageFilter.Null, true, true, "yyyy-MM-dd hh:mm:ss");

            ExportRequest req2 = new ExportRequest(g, c, env + $"/{category}/Dark/{channel.Name}.html", ExportFormat.HtmlDark,
                                                   null, null, PartitionLimit.Null, MessageFilter.Null, true, true, "yyyy-MM-dd hh:mm:ss");

            bool   isLight = true;
            string path    = env + $"/{category}/{(isLight ? "Light" : "Dark")}/{channel.Name}.html_Files/";


            var message = await Context.Channel.SendMessageAsync("", false, Embeds.Archiving(Context.User, channel, "Starting")).ConfigureAwait(false);

            //Timer _timer = new Timer(async _ => await OnTick(), null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));


            try
            {
                await message.ModifyAsync(x => x.Embed = Embeds.Archiving(Context.User, channel, "Exporting Light Mode")).ConfigureAwait(false);

                await _exporter.ExportChannelAsync(req).ConfigureAwait(false);

                await message.ModifyAsync(x => x.Embed = Embeds.Archiving(Context.User, channel, "Exporting Dark Mode")).ConfigureAwait(false);

                isLight = false;
                await _exporter.ExportChannelAsync(req2).ConfigureAwait(false);

                await message.ModifyAsync(x => x.Embed = Embeds.Archiving(Context.User, channel, "Done"));
            }
            catch (Exception ex)
            {
                await message.ModifyAsync(x =>
                {
                    x.Content = $"Error occured: {ex}";
                    x.Embed   = null;
                });
            }

            //async Task OnTick()
            //{
            //    await message.ModifyAsync(x => x.Content = $"Exported: {Directory.GetFiles(path, "*.*").Length} files.");
            //}
        }