private void AddMedia(IEnumerable<Item> items, string userId)
        {
            var user = _context.Users.FirstOrDefault(x => x.InstaId == userId);

            foreach (var item in items)
            {
                var alreadyIserted = _context.Media.FirstOrDefault(x => x.InstaId == item.id);
                if (alreadyIserted == null)
                {
                    var newItem = new Media
                    {
                        InsertedDate = DateTime.Now,
                        InstaId = item.id,
                        InstaCreatedTime = item.created_time.FromUnixTime(),
                        InstaLikes = item.likes.count,
                        InstaLowResolution = item.images.low_resolution.url,
                        InstaStandardResolution = item.images.standard_resolution.url,
                        InstaThumbnail = item.images.thumbnail.url,
                        Caption = item.caption?.text,
                        //InstaFilter = item.Filter,
                        InstaLink = item.link,
                        InstaType = item.type,
                        User = user
                    };
                    _context.Media.Add(newItem);

                    //Helpers.Telegram.SendMessageToChannel(newItem, "@InstaChehreh").Wait();
                    //1   بازیگر
                    //2   فوتبالیست
                    //3   مجری
                    //4   والیبالیست
                    //5   خواننده
                    var telegram = new Telegram(_context);
                    if (item.likes.count > 10)
                    {
                        if (user.Category?.Id == 1 || user.Category?.Id == 3 || user.Category?.Id == 5)
                        {
                            telegram.SendMessageToChannel(newItem, "@InstaHonar").Wait();
                            telegram.SendMessageToChannel(newItem, "@InstaChehreh").Wait();
                        }
                        else if (user.Category?.Id == 2 || user.Category?.Id == 4)
                            telegram.SendMessageToChannel(newItem, "@InstaVarzesh1").Wait();
                    }
                }
            }
            _context.SaveChanges();
        }
Beispiel #2
0
        public async Task SendMessageToChannel(Media item, string channelName)
        {
            try
            {
                var Bot = new TB.TelegramBotClient(BOT_API);
                var hashtag = !string.IsNullOrEmpty(item.User.Name) ? "🖼 " + item.User.Name.ToHashtag() : "";
                var name = $"{item.User.Name} ({item.User.Username})</b>";
                //var ad = "⚽️🎼🎭\r\n<i>جدیدترین عکس‌ها و اخبار از محبوب‌ترین چهره‌های ایرانی در کانال اینستاچهره  </i> 👇\r\n  https://telegram.me/joinchat/BFGINT2hHdPVzqGfj43k1Q";
                var ad = "⚽️🎼🎭<i>داغ‌ترین عکس‌ها از هنرمندان و ورزشکاران ایرانی  </i> 👇\r\n https://telegram.me/joinchat/BFGINT2hHdPVzqGfj43k1Q   @InstaHonar    @InstaVarzesh1";
                var link = $"<a href='{item.InstaStandardResolution}'>{item.InstaCreatedTime.ToShamsi()}</a>";
                var instaLink = $"<a href='{item.InstaLink}'>اینستاگرام</a>";

                await Bot.SendTextMessageAsync(channelName, $"{hashtag} [{link}]\r\n{item.Caption}\r\n\r\n{ad}", false, true, 0, null, TB.Types.Enums.ParseMode.Html);
                MarkAsSent(item);
            }
            catch (Exception ex)
            {
                //TODO
            }
        }
Beispiel #3
0
 private void MarkAsSent(Media item)
 {
     item.PostToTelegram = true;
     _context.SaveChanges();
 }