public void KotowNotify() { const int kotowCount = 10; var groupNumber = AppSetting.GroupNumber; var result = _qqRobotService.GetEventLogByDate(DateTime.Now.AddDays(-1), DateTime.Now, "Kowtow", groupNumber, 1, kotowCount).GetAwaiter().GetResult(); var kotows = result?.Data.Items; using (var robotSession = MahuaRobotManager.Instance.CreateSession()) { var api = robotSession.MahuaApi; if (kotows?.Count() > 0) { StringBuilder msg = new StringBuilder(); msg.Append($"磕头播报: 昨日共磕头{result?.Data.Total}次,前{kotowCount}位磕头者:"); foreach (var item in kotows) { msg.AppendLine(); msg.Append($"{item.CreatedTime.ToString("HH:mm")}:{_groupMemberInfosCache.GetGroupNike(groupNumber, item.CreatedBy)};已连续磕头{item.ContinuousCheckIn}天"); } api.SendGroupMessage(groupNumber, msg.ToString()); } else { api.SendGroupMessage(groupNumber).Text("一个时代一个神,昨天没人磕头,教主牛逼.").Done(); } } }
public void ProcessGroupMessage(GroupMessageReceivedContext context) { var content = context.Message; foreach (var item in RuntimeConfig.Config.GroupEvent) { if (item.Regex.IsMatch(content)) { if (context.FromQq == item.QQ) { _mahuaApi.SendGroupMessageExtension(context.FromGroup, item.DefaultReply); continue; } var request = new Model.GroupEventRequest { FromQq = context.FromQq, EventText = context.Message, EventType = item.EventType, Source = context.FromGroup, CreatedTime = DateTime.Now }; //疲劳值, 防止过多重复磕头刷屏. 只回复第一次有效数据 var kotowLog = _qqRobotService.GetEventLog(request).GetAwaiter().GetResult()?.Data; if (kotowLog != null) { continue; } kotowLog = _qqRobotService.CreateEventLog(request).GetAwaiter().GetResult()?.Data; if (!string.IsNullOrWhiteSpace(item.EventReply)) { var msg = item.EventReply .Replace("{Name}", _groupMemberInfosCache.GetGroupNike(context.FromGroup, context.FromQq)) .Replace("{IsContinuous}", (kotowLog.ContinuousCheckIn > 1 ? "连续" : "")) .Replace("{ContinuousNum}", kotowLog.ContinuousCheckIn.ToString()); _mahuaApi.SendGroupMessageExtension(context.FromGroup, msg); } } } }
private async Task <string> UploadImageAsync(GroupMessageReceivedContext context) { var imagesFileNames = CQNumberHelper.GetImage(context.Message)?.ToList(); if (imagesFileNames == null) { return("没图片at我搞毛啊."); } List <(string name, byte[] bytes)> images = new List <(string name, byte[] bytes)>(); foreach (var fileName in imagesFileNames) { string imgUrl = await GetImageUrlAsync(fileName); if (string.IsNullOrEmpty(imgUrl)) { continue; } var imgBytes = await GetByteArrayAsync(imgUrl); if (imgBytes.Length == 0) { continue; } images.Add((fileName, imgBytes)); } var result = await _qqRobotService.UploadImage(images, context.FromQq); return($"{_groupMemberInfosCache.GetGroupNike(context.FromGroup, context.FromQq)}的图片:{result.Message}"); }
public void SendMessage(IEnumerable <GroupEventLog> logs, int total, GroupEventSearchConfig config, DateTime date, string fromGroup) { var data = logs?.ToList(); if (data?.Count() > 0) { StringBuilder content = new StringBuilder(); foreach (var item in data) { content.Append($"{item.CreatedTime.ToString("HH:mm")}:{_groupMemberInfosCache.GetGroupNike(fromGroup, item.CreatedBy)};"); if (date >= DateTime.Today.AddDays(-1)) { content.Append($"连续{item.ContinuousCheckIn}天"); } content.AppendLine(); } var msg = config.Template .Replace("{Total}", total.ToString()) .Replace("{Date}", date.ToString("MM-dd")) .Replace("{Num}", EventLogSrachCount.ToString()) .Replace("{Content}", content.ToString()) ; _mahuaApi.SendGroupMessageExtension(fromGroup, msg); } else { _mahuaApi.SendGroupMessageExtension(fromGroup, config.NullTemplate); } }