public static WeiboVo TransWeiboData(UserMicroBlogPB data) { var weiboInfo = new WeiboVo() { UserId = data.UserId, SceneId = data.SceneId, IsLike = data.Like == 1, IsComment = data.SelectState == 1, IsPublish = data.PubState == 1, CommentIndex = data.SelectIndex, CreateTime = data.CreateTime, //CommentContents = new List<string>(), }; // weiboInfo.IsPublish = weiboInfo.WeiboRuleInfo.weiboSceneInfo.NpcId == 0 ? v.PubState == 1 : true; string text = new AssetLoader().LoadTextSync(AssetLoader.GetPhoneDataPath(data.SceneId.ToString())); if (text == "") { return(null); } WeiboInfo info = JsonConvert.DeserializeObject <WeiboInfo>(text); weiboInfo.WeiboRuleInfo = info; return(weiboInfo); }
private void LoadPhoneWeiboRuleById(int id) { string text = new AssetLoader().LoadTextSync(AssetLoader.GetPhoneDataPath(id.ToString())); WeiboInfo info = JsonConvert.DeserializeObject <WeiboInfo>(text); _weiboRuleInfos.Add(info); if (_weiboRuleInfos.Count == _weiboIds.Count) { LoadWeiboRuleFinishs(); } }
public async Task SendWeibo(WeiboInfo weiboInfo) { var retryTime = 0; //var sizeLimit = 1000L * 1000 * 10; // 10MB limit //var widthLimit = 10000; //var heightLimit = 10000; while (true) { if (retryTime > 5) { break; } var files = weiboInfo.ImgUrls .Where(t => !string.IsNullOrEmpty(t.ImgPath)) .Select(t => new FileInfo(t.ImgPath)) .Select(t => new { t.Name, Stream = Utils.Utils.ResaveImage(t.OpenRead()) }) /*.TakeWhile(t => t.Length < sizeLimit && * t.Image.Height < heightLimit && * t.Image.Width < widthLimit)*/ .ToList(); try { if (string.IsNullOrEmpty(weiboInfo.Url)) { return; } await BotClient.SendChatActionAsync(Program.Config["Telegram:ChatId"], ChatAction.UploadPhoto); if (files.Count > 1) { /*var totalSize = 0L; * (totalSize+=t.Length) < sizeLimit && */ while (files.Count > 0) { var photo = files.Take(Math.Min(9, files.Count)).ToList(); photo.ForEach(t => files.Remove(t)); var photoInput = photo .Select(t => new InputMediaPhoto(new InputMedia(t.Stream, t.Name))).ToList(); photoInput[0].Caption = weiboInfo.Url; await BotClient.SendMediaGroupAsync(photoInput, new ChatId(long.Parse(Program.Config["Telegram:ChatId"]))); } } else if (files.Count == 1) { await BotClient.SendPhotoAsync(new ChatId(long.Parse(Program.Config["Telegram:ChatId"])), new InputMedia(files[0].Stream, files[0].Name), weiboInfo.Url); } else { await BotClient.SendTextMessageAsync( new ChatId(long.Parse(Program.Config["Telegram:ChatId"])), weiboInfo.Url, disableWebPagePreview : true); } break; } catch (Exception e) { retryTime++; Log.Logger.Fatal(e, $"Failed to send message, weiboId {weiboInfo.Id}, retry ({retryTime}/5)"); await Task.Delay(TimeSpan.FromSeconds(10)); } finally { foreach (var file in files) { file.Stream.Close(); file.Stream.Dispose(); } } } }