Esempio n. 1
0
        static void Main()
        {
            process = Process.Start(new ProcessStartInfo
            {
                FileName  = "python",
                Arguments = "-u -m deepdanbooru evaluate --project-path D:\\DeepDanbooru-master\\test --allow-folder",
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            });
            var dic   = new Dictionary <string, int>();
            var count = new List <int>();

            process.OutputDataReceived += (sender, eventArgs) =>
            {
                var line = eventArgs.Data;
                if (line.IsNullOrWhiteSpace() || !line.StartsWith("MAGIC"))
                {
                    return;
                }
                line = line.Substring(5);
                var split      = line.Split('艹');
                var path       = split[0];
                var tagsSource = split.Skip(1);
                var tags       = new List <Tag>();

                foreach (var tagSource in tagsSource)
                {
                    var split1 = tagSource.Split('丂');
                    var score  = split1[0];
                    var tag    = split1[1];
                    tags.Add(new Tag {
                        Score = score, TagName = tag
                    });
                    if (!dic.ContainsKey(tag))
                    {
                        dic[tag] = 0;
                    }

                    dic[tag]++;
                }
                count.Add(tags.Count);
                var result = new FileResult {
                    FilePath = Path.GetFileNameWithoutExtension(path), Tags = tags
                };
                SeTuTaskManager.ReportTask(result);
            };

            ChildProcessTracker.AddProcess(process);
            process.BeginOutputReadLine();


            MiraiHttpSession = new MiraiHttpSession("127.0.0.1", 8080, "********", 3320645904);
            MiraiHttpSession session = MiraiHttpSession;

            session.Connect();
            while (true)
            {
                var evt = session.PullEvent();
                if (evt is GroupMessageEventArgs args)
                {
                    if (args.Message.OfType <Plain>().Any(m => m.Text.Contains("/mute")))
                    {
                        var group = args.Group.Identifier;
                        SeTuTaskManager.BlockedGroups.Add(group);
                        File.AppendAllText("blocked", group);
                    }

                    var force = args.Message.OfType <Plain>().Any(m => m.Text.Contains("/色图检测"));

                    foreach (var component in args.Message)
                    {
                        if (component is Image image)
                        {
                            try
                            {
                                using var result = image.OpenReadAsync().Result;
                                var    tempfilename = Guid.NewGuid().ToString("D");
                                var    temppath     = Path.Combine("pending check", tempfilename);
                                Stream s            = File.Create(temppath);

                                result.CopyTo(s);
                                // 写重复检测
                                s.Close();

                                var filename = File.ReadAllBytes(temppath).MD5().ToHexString();
                                var realpath = Path.Combine("pending check", filename);
                                if (File.Exists(realpath) && !force)
                                {
                                    continue;
                                }

                                // 我不管了 反正就是要被占用 加个try完事
                                try
                                {
                                    File.Move(temppath, realpath, true);
                                }
                                catch (Exception)
                                {
                                }
                                SeTuTaskManager.AddTask(filename, args.Group, force);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }
                }
                Thread.Sleep(50);
            }
        }