コード例 #1
0
        public async Task HandleArchiveSearchCommand(string name = "")
        {
            string env = HARDCODED_ARCHIVE_PATH;

            DirectoryInfo di        = new DirectoryInfo(env);
            var           fileInfos = di.GetFiles($"*{name}*.html", SearchOption.AllDirectories);

            List <Info> infos = new List <Info>();

            foreach (var fileInfo in fileInfos)
            {
                if (fileInfo.DirectoryName.Contains("Dark"))
                {
                    continue;
                }

                var fileName  = fileInfo.Name;
                var diName    = fileInfo.Directory.FullName;
                var directory = diName.Substring(diName.IndexOf("archive"));

                Info info = new Info
                {
                    Category = GetCategory(diName),
                    Name     = fileName,
                    Path     = directory
                };

                infos.Add(info);

                //TODO: Please find a better way to extract from a path.
                string GetCategory(string diName)
                {
                    diName = diName.Substring(diName.IndexOf("archive/") + 8);
                    diName = diName.Substring(0, diName.IndexOf("/"));
                    return(diName);
                }
            }

            await Context.Channel.SendMessageAsync("", false, Embeds.ArchiveSearch(infos));
        }