public static void ReportTask(Program.FileResult result)
        {
            if (Program.MiraiHttpSession == null)
            {
                return;
            }
            if (taskQueue.All(task => task.FileName != result.FilePath))
            {
                Console.WriteLine($"警告: {result.FilePath} 不在队列中.");
                return;
            }

            var task = taskQueue.First(task => task.FileName == result.FilePath);

            taskQueue.Remove(task);

            var path = Path.Combine("pending check", result.FilePath);

            ModelInput sampleData = new ModelInput()
            {
                ImageSource = Path.GetFullPath(path),
            };
            var predictionResult = ConsumeModel.Predict(sampleData);
            var tags_like        = Enum.GetNames(typeof(TagsLike));

            if (predictionResult.Prediction == "二次元色图" || task.Force)
            {
                if (task.Force)
                {
                    var tags = result.Tags.Select(t => t.TagName).ToArray();
                    for (var i = 0; i < tags.Length; i++)
                    {
                        var tagstr = tags[i];
                        if (Enum.TryParse <TagsLike>(tagstr, out var tag))
                        {
                            tags[i] = GetChinese(tag);
                        }
                    }
                    SendMessage(task.Group, MessageChain.Construct(new Plain($"检测到含有以下元素: {tags.Connect()}, 模型匹配为{predictionResult.Prediction} (完全不准确)")));
                }
                else
                {
                    var random = new Random().Next(10) < 4 ? "如果你觉得太吵 可以使用/mute来在这个群永久关闭所有消息" : "";
                    var likes  = tags_like.Intersect(result.Tags.Select(t => t.TagName)).ToArray();
                    if (likes.Length == 0)
                    {
                        return;
                    }
                    var msg =
                        (from like in likes select Enum.Parse <TagsLike>(like) into tag select GetChinese(tag)).Connect();
                    SendMessage(task.Group,
                                new MessageChain(new MessageComponent[] { new At(775942303), new Plain($"检测到了 {msg} 色图!" + random) }));
                    File.Copy(path, Path.Combine("setu", result.FilePath + task.Extension));
                }
            }
        }
Exemplo n.º 2
0
 public async Task Github(Group group, string query)
 {
     MessageChain chain = MessageChain.Construct(new Image(null,
                                                           new UrlSource(new Uri($"https://opengraph.githubassets.com/0/{query}"))));
     await group.SendAsync(chain);
 }