public void Reply(IReceiveMessage message, IMessageTarget sender, ReplyForm replyForm, object result) { IMessageTarget target = ReplyTarget(message); ISendMessage sendMessage = ReplyMessage(message.Connection.MessageSender, target, replyForm, result); if(replyForm != ReplyForm.More) { String[] messages = SplitMessage(sendMessage).ToArray(); if(messages.Length > _data.ReplyMores) { _moreMessages.Remove(sender); _moreMessages.Add(sender, new Queue<String>(messages.Skip(_data.ReplyMores))); _lastMore = sender; } message.Connection.SendAndForget(messages .Take(_data.ReplyMores) .Select(s => SendMessage(sendMessage, s, sender, replyForm)) ); } else { message.Connection.SendAndForget(SendMessage(sendMessage, sendMessage.Contents, sender, _bot.DefaultReplyForm)); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } ReplyForm replyForm = cmdData.ProtoBufDeserialize <ReplyForm>(); if (Compiled.Debug) { replyForm.Debug("=== Bbs.ReplyCreate 上行数据 ==="); } CreateReply(replyForm, context); }
public async Task <IActionResult> AddReply(ReplyForm model) { if (ModelState.IsValid) { var user = await _workContext.GetCurrentUser(); var reply = new Models.Reply { ReviewId = model.ReviewId, UserId = user.Id, Comment = model.Comment, ReplierName = model.ReplierName, }; _replyRepository.Add(reply); _replyRepository.SaveChanges(); return(PartialView("_ReplyFormSuccess", model)); } return(PartialView("_ReplyForm", model)); }
public ActionResult Reply(ReplyForm form) { var ticket = _tickets.Get(form.TicketID); ticket.AddReply(_user.User, form.Body); //send the message to the user try { _notifier.SendReply(ticket, _user.User, form.Body); } catch { this.Error("There was a problem sending an E-mail to the user. Please try again."); return(this.RedirectToAction(c => c.ViewTicket(form.TicketID))); } _tickets.Save(); this.Success("Reply sent!"); return(this.RedirectToAction(c => c.ViewTicket(form.TicketID))); }
public void Reply(IReceiveMessage message, IMessageTarget sender, ReplyForm replyForm, Exception e) { LogUserError(message, e); if(!_data.ReplyError) return; if(_data.ReplyErrorDetailed) Reply(message, sender, replyForm, "Error -- " + e.Message); else Reply(message, sender, replyForm, "An error occurred."); }
private ISendMessage SendMessage(ISendMessage message, String contents, IMessageTarget sender, ReplyForm replyForm) { if(replyForm == ReplyForm.Reply) contents = sender.Name + ": " + contents; return message.Connection.Client.CreateSendMessage(message, contents); }
private ISendMessage ReplyMessage(IMessageSender messageSender, IMessageTarget target, ReplyForm replyForm, object result) { switch(replyForm) { case ReplyForm.Action: return messageSender.Action(target, result.ToString()); case ReplyForm.Notice: return messageSender.Notice(target, result.ToString()); default: return messageSender.Message(target, result.ToString()); } }
/// <summary> /// /// </summary> /// <param name="replyForm"></param> /// <param name="context"></param> private static void CreateReply(ReplyForm replyForm, DataContext context) { int userId = context.UserId; UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); int schoolId = userCache.UserSite; #region 基本校验 TopicInfo topicInfo = BbsBiz.GetTopicInfoById(replyForm.TopicId); if (null == topicInfo) { context.Flush(RespondCode.DataInvalid); return; } if (!topicInfo.IsAllowReply) { context.Flush(RespondCode.ShowError, "该帖子不允许回复!"); return; } //是否带有声音、图片文件 bool hasVoice = replyForm.Voices != null && replyForm.Voices.Count > 0; bool hasImage = replyForm.Image != null && replyForm.Image.Count > 0; bool hasMediaFiles = hasVoice || hasImage; //敏感关键词 List <string> filters = FilterHelper.GetSensitiveWords().ToList(); //内容 string content = (replyForm.Content ?? string.Empty).Trim(); if (!string.IsNullOrEmpty(content)) { if (filters.Count > 0) { content = content.ReplaceSensitiveWord(filters); } if (!hasMediaFiles) { content = string.Format("<TopicContent><Text>{0}</Text></TopicContent>", content); } } #endregion #region 数据组装 DateTime dtNow = DateTime.Now; PostFullInfo postInfo = new PostFullInfo { TopicId = replyForm.TopicId, ForumId = topicInfo.ForumId, SchoolId = schoolId, UserId = userId, Content = content, FavouredCount = 0, ReplyForUserId = replyForm.TargetId, IsBestReply = false, SetBestDate = dtNow, ExpChanged = 0, VirtualCoinChanged = 0, Status = 0, Remark = "", CreateDate = dtNow, ManageMark = "", LastManageDate = dtNow }; #endregion //创建跟帖 BbsBiz.CreateReply(postInfo); if (postInfo.PostId > 0) { #region 处理声音、图片等文件,并更新帖子内容 if (hasMediaFiles) { List <string> voiceNodeList = new List <string>(0); string extName, url; if (hasVoice) { int voiceTime; foreach (MediaDetail voice in replyForm.Voices) { if (voice.Data != null && voice.Data.Length > 0) { extName = (voice.Name ?? ".mp3").Trim().ToLower(); voiceTime = 0; int.TryParse(voice.Attr ?? "0", out voiceTime); url = voice.Data.SaveMediaFile(FileTarget.Post, postInfo.PostId, Utility.MediaType.Audio, extName); if (!string.IsNullOrEmpty(url)) { voiceNodeList.Add(string.Format("<Voice Url=\"{0}\" Duration=\"{1}\"></Voice>", url, voiceTime)); } } } } List <string> imageNodeList = new List <string>(0); if (hasImage) { foreach (MediaDetail image in replyForm.Image) { if (image.Data != null && image.Data.Length > 0) { extName = (image.Name ?? ".jpg").Trim().ToLower(); url = image.Data.SaveMediaFile(FileTarget.Post, postInfo.PostId, Utility.MediaType.Image, extName); if (!string.IsNullOrEmpty(url)) { Tuple <int, int> imageSize = url.GetImageSize(); int w = imageSize.Item1, h = imageSize.Item2; if (w > 0 && h > 0) { if (w > 480) { h = (int)((double)h * (double)((double)w / (double)480)); w = 480; } imageNodeList.Add(string.Format("<Image ThumbUrl=\"{0}\" ImageUrl=\"{1}\" Width=\"{2}\" Height=\"{3}\"></Image>", url, url, w, h)); } } } } } string voiceContent = string.Empty; if (voiceNodeList.Count > 0) { voiceContent = string.Join(string.Empty, voiceNodeList); } string textContent = string.Empty; if (!string.IsNullOrEmpty(content)) { textContent = string.Format("<Text>{0}</Text>", content); } string imageContent = string.Empty; if (imageNodeList.Count > 0) { imageContent = string.Join(string.Empty, imageNodeList); } postInfo.Content = string.Format("<TopicContent>{0}{1}{2}</TopicContent>", voiceContent, textContent, imageContent); //更新帖子内容 BbsBiz.UpdatePostContent(postInfo); } #endregion context.Flush(BitConverter.GetBytes(postInfo.PostId).Reverse()); } else { context.Flush(RespondCode.ExecError); } }