Esempio n. 1
0
        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);
                    }
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var ats = CQNumberHelper.GetAtQQ(context.Message)?.ToList();

            if (ats != null && ats.Contains(_mahuaApi.GetLoginQq()) && (context.Message.Contains("--help") || context.Message.Contains("-h")))
            {
                _mahuaApi.SendGroupMessageExtension(context.FromGroup, RuntimeConfig.Config.HelpText);
            }
        }
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var ats = CQNumberHelper.GetAtQQ(context.Message)?.ToList();

            if (ats != null && ats.Contains(_mahuaApi.GetLoginQq()))
            {
                if (context.Message.Contains("上传图片"))
                {
                    var result = UploadImageAsync(context).GetAwaiter().GetResult();
                    if (!string.IsNullOrEmpty(result))
                    {
                        _mahuaApi.SendGroupMessageExtension(context.FromGroup, result);
                        ILog logger = LogProvider.GetCurrentClassLogger();
                        logger.Info(result);
                    }
                }
            }
        }
Esempio n. 5
0
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var group   = context.FromGroup;
            var message = context.Message;
            var currentGroupMessageCache = messageCache.GetOrAdd(group, new ConcurrentQueue <string>());
            //当前缓存消息出现的次数
            var currentGroupMessageCacheCount = messageCacheCount.GetOrAdd(group, new ConcurrentDictionary <string, byte>());
            //已复读
            var currentGroupRepeatMessageCache = repeatMessageCache.GetOrAdd(group, new ConcurrentDictionary <string, bool>());

            //已禁言
            //var currentGroupBanMessageCache = banMessageCache.GetOrAdd(group, new ConcurrentDictionary<string, bool>());
            while (currentGroupMessageCache.Count >= MessageCacheCount)
            {
                lock (ClearMessageCacheLock)
                {
                    if (currentGroupMessageCache.Count >= MessageCacheCount &&
                        currentGroupMessageCache.TryDequeue(out string oldMessage))
                    {
                        //确保队列缓存被处理了
                        byte oldCount = 0;
                        while (currentGroupMessageCacheCount.TryGetValue(oldMessage, out oldCount))
                        {
                            if (currentGroupMessageCacheCount.TryUpdate(oldMessage, (byte)(oldCount - 1), oldCount))
                            {
                                break;
                            }
                        }
                        if (oldMessage != message && oldCount <= 1)
                        {
                            currentGroupMessageCacheCount.TryRemove(oldMessage, out _);
                            currentGroupRepeatMessageCache.TryRemove(oldMessage, out _);
                            break;
                        }
                    }
                }
            }


            currentGroupMessageCache.Enqueue(message);
            var messageCount = currentGroupMessageCacheCount.AddOrUpdate(message, 1, (_, count) => (byte)(count + 1));


            //3条起 20%增长, 60%封顶
            var maxProbality = (100 - (messageCount - 2 >= 3 ? 3 : messageCount - 2) * 20);
            var probability  = 0;

            lock (randLock)
            {
                probability = random.Next(1, 101);
            }
            if (messageCount > 2)
            {
                //复读
                if (RuntimeConfig.Config.IsRepeatMessage && probability > maxProbality && !currentGroupRepeatMessageCache.ContainsKey(message))
                {
                    currentGroupRepeatMessageCache.TryAdd(message, true);
                    _mahuaApi.SendGroupMessageExtension(group, message);
                }
                //禁言
                var p = 100 - RuntimeConfig.Config.RepeatMessageBanProbability;
                if (RuntimeConfig.Config.IsBanRepeatMessage && probability > p)
                {
                    _mahuaApi.BanGroupMember(group, context.FromQq, TimeSpan.FromMinutes(RuntimeConfig.Config.RepeatMessageBanDuration));
                }
            }
        }