示例#1
0
        private async Task <string> BanImageBoyan(Message message)
        {
            var isBanning = IsBanning(message.Caption, message);

            if (isBanning == false)
            {
                return(null);
            }

            var biggestPhoto = message.Photo.OrderByDescending(x => x.FileSize).FirstOrDefault();

            var tempFolderPath = Path.Combine(AppContext.BaseDirectory, "Tmp");

            if (Directory.Exists(tempFolderPath) == false)
            {
                Directory.CreateDirectory(tempFolderPath);
            }

            var filePath = Path.Combine(tempFolderPath, $"{Guid.NewGuid()}.jpg");

            using (var stream = System.IO.File.Create(filePath))
            {
                var file = await Bot.GetInfoAndDownloadFileAsync(biggestPhoto.FileId, stream);
            }

            var hash = new ImgHash();

            hash.GenerateFromPath(filePath);

            Boyan boyan = null;

            foreach (var imageBoyan in Boyans.Items.Where(x => x.ImageHash != null))
            {
                var similarity = hash.CompareWith(imageBoyan.ImageHash);
                if (similarity >= 99)
                {
                    boyan = imageBoyan;
                    break;
                }
            }

            string reply;

            if (boyan != null)
            {
                boyan.IsBanned = true;
                reply          = "Небоян забанен!";
            }
            else
            {
                reply = "Боян не найден!";
            }

            return(reply);
        }
示例#2
0
 /// <summary>
 /// Method to compare 2 image hashes
 /// </summary>
 /// <returns>% of similarity</returns>
 public double CompareWith(ImgHash compareWith)
 {
     return(CompareWith(compareWith.HashData));
 }