public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var    deskid    = context.FromGroup;
            var    playerid  = context.FromQq;
            var    message   = context.Message;
            string groupName = null;

            try
            {
                groupName = _mahuaApi.GetGroupsWithModel().Model.FirstOrDefault(g => g.Group == deskid)?.Name;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            var desk = Desk.GetOrCreateDesk(deskid, groupName);

            desk.ParseCommand(playerid, message);
            desk.PlayerList.Where(player => player.Message != null && !(player is FakePlayer)).ToList().ForEach(player =>
            {
                _mahuaApi.SendPrivateMessage(player.PlayerId, player.Message);
                player.ClearMessage();
            });

            Player.ForceSendPlayers.Where(player => player.Message != null && player.ForceSend).ToList().ForEach(player => {
                _mahuaApi.SendPrivateMessage(player.PlayerId, player.Message);
                player.ClearMessage();
                player.ForceSend = false;
            });

            if (desk.Message != null)
            {
                _mahuaApi.SendGroupMessage(deskid, desk.Message);
                desk.ClearMessage();
            }
        }
Пример #2
0
        // private MessageController messageController = new MessageController();
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            String message = context.Message;

            message = message.Trim();
            if (message == "" || message.Length == 0 || message == null)
            {
                return;
            }
            String myQQ   = _mahuaApi.GetLoginQq();
            String aiteQQ = "[CQ:at,qq=" + myQQ + "]";

            if (message.Contains(aiteQQ))
            {
                String sendMessage = "[CQ:at,qq=" + context.FromQq + "]";
                message = message.Replace(aiteQQ, "").Replace("\"\"", "").Replace("“", "").Replace("”", "").Trim();
                IDatabase redis = RedisHelper.getRedis();
                // 判断用户是否在缓冲中
                if (redis.StringGet(context.FromQq).IsNull)
                {
                    redis.StringSet(context.FromQq, "flag");
                    redis.KeyExpire(context.FromQq, new TimeSpan(10000000 * Convert.ToInt16(Constants.sleepTime)));
                }
                else
                {
                    string tmpStr = "为防止造成刷屏,您每次使用机器人的时间间隔" + Constants.sleepTime + "秒哦!";
                    sendMessage += tmpStr;
                    _mahuaApi.SendGroupMessage(context.FromGroup, sendMessage);
                    return;
                };
                if (message == null || message == "" || message.Length == 0)
                {
                    //
                }
                else
                {
                    MessageModel messageModel = MessageController.main(message, context.FromQq);
                    // 发送消息
                    string tmpStr = messageModel.SendMessage;
                    if (messageModel.IsAdmin)
                    {
                        // 群数量
                        if (MessageConstant.QUN_TOTAL.Equals(messageModel.Code))
                        {
                            ModelWithSourceString <IEnumerable <GroupInfo> > modelWithSourceString = _mahuaApi.GetGroupsWithModel();
                            IEnumerable <GroupInfo> groupInfo = modelWithSourceString.Model;
                            int count = 0;
                            foreach (var item in groupInfo)
                            {
                                count++;
                            }
                            _mahuaApi.SendGroupMessage(context.FromQq, "群数量:" + count.ToString());
                        }
                        else
                        {
                            if (tmpStr != "" && tmpStr.Length > 0)
                            {
                                sendMessage += tmpStr;
                                _mahuaApi.SendGroupMessage(context.FromQq, sendMessage);
                            }
                        }
                    }
                    else
                    {
                        if (tmpStr != "" && tmpStr.Length > 0)
                        {
                            sendMessage += tmpStr;
                            _mahuaApi.SendGroupMessage(context.FromGroup, sendMessage);
                        }
                    }
                }
            }
        }
        //  private MessageController messageController = new MessageController();
        public void ProcessFriendMessage(PrivateMessageFromFriendReceivedContext context)
        {
            string message = context.Message;

            if (message == "" || message.Length == 0 || message == null)
            {
                return;
            }
            IDatabase redis = RedisHelper.getRedis();

            // 判断用户是否在缓冲中
            if (redis.StringGet(context.FromQq).IsNull)
            {
                redis.StringSet(context.FromQq, "flag");
                redis.KeyExpire(context.FromQq, new TimeSpan(10000000 * Convert.ToInt16(Constants.sleepTime)));
            }
            else
            {
                string tmpStr = "为防止造成刷屏,您每次使用机器人的时间间隔" + Constants.sleepTime + "秒哦!";
                _mahuaApi.SendPrivateMessage(context.FromQq, tmpStr);
                return;
            };
            if (message == null || message == "" || message.Length == 0)
            {
                //
            }
            else
            {
                MessageModel messageModel = MessageController.main(message, context.FromQq);
                string       tmpStr       = messageModel.SendMessage;
                bool         isAdmin      = messageModel.IsAdmin;
                if (isAdmin)
                {
                    // 判断是否为 公告指令
                    if (MessageConstant.GONG_GAO.Equals(messageModel.Code))
                    {
                        // 获取所有群信息
                        ModelWithSourceString <IEnumerable <GroupInfo> > modelWithSourceString = _mahuaApi.GetGroupsWithModel();
                        IEnumerable <GroupInfo> groupInfo = modelWithSourceString.Model;
                        foreach (var item in groupInfo)
                        {
                            _mahuaApi.SendGroupMessage(item.Group, tmpStr);
                            _mahuaApi.SendPrivateMessage(context.FromQq, "【" + item.Name + "】 " + item.Group + " 推送成功!");
                        }
                    }
                    // 判断是否为全体成员处理
                    else if (MessageConstant.AITE_ALL.Equals(messageModel.Code))
                    {
                        // 获取所有群信息
                        ModelWithSourceString <IEnumerable <GroupInfo> > modelWithSourceString = _mahuaApi.GetGroupsWithModel();
                        IEnumerable <GroupInfo> groupInfo = modelWithSourceString.Model;
                        tmpStr = "[CQ:at,qq=all]\n" + tmpStr;
                        foreach (var item in groupInfo)
                        {
                            _mahuaApi.SendGroupMessage(item.Group, tmpStr);
                            _mahuaApi.SendPrivateMessage(context.FromQq, "【" + item.Name + "】 " + item.Group + " 推送成功!");
                        }
                    }
                    // 更新金额
                    else if (MessageConstant.UPDATE_MONEY.Equals(messageModel.Code))
                    {
                        _mahuaApi.SendPrivateMessage(context.FromQq, messageModel.SendMessage);
                    }
                    // 群数量
                    else if (MessageConstant.QUN_TOTAL.Equals(messageModel.Code))
                    {
                        ModelWithSourceString <IEnumerable <GroupInfo> > modelWithSourceString = _mahuaApi.GetGroupsWithModel();
                        IEnumerable <GroupInfo> groupInfo = modelWithSourceString.Model;
                        int count = 0;
                        foreach (var item in groupInfo)
                        {
                            count++;
                        }
                        _mahuaApi.SendPrivateMessage(context.FromQq, "群数量:" + count.ToString());
                    }
                    else
                    {
                        if (tmpStr != "" && tmpStr.Length > 0)
                        {
                            _mahuaApi.SendPrivateMessage(context.FromQq, tmpStr);
                        }
                    }
                }
                else
                {
                    if (tmpStr != "" && tmpStr.Length > 0)
                    {
                        _mahuaApi.SendPrivateMessage(context.FromQq, tmpStr);
                    }
                }
            }
        }
        public void ProcessPrivateMessage(PrivateMessageReceivedContext context)
        {
            if (HotUpdateInfo.PreviousVersion)
            {
                return;
            }
            // F**k 我先注释了 如果你有兴趣拿正则重构这傻逼功能 JUSTDOIT.

            /*if (context.Message.StartsWith("添加骚话"))
             * {
             *  var strs = context.Message.Split(' ');
             *  if (strs.Length >= 2)
             *  {
             *      var word = strs[1];
             *      var result = strs[2];
             *      if (result.Contains("[CQ:image"))// 检测是否有图片cq码
             *      {
             *          var strs1 = strs[2].Split(new[] {"file="}, StringSplitOptions.None);// 去掉cq码前面的东西
             *          var strs2 = strs1.Last().Split('.');// 去掉cq码后面的东西
             *          var filename = strs2.First() + ".cqimg";// 终于 我们得到了cq随机生成的文件名 还得加个cqimg
             *          if (!Directory.Exists(@"骚话\"))
             *          {
             *              Directory.CreateDirectory(@"骚话\");
             *          }
             *
             *          var extension = strs2.Last().Substring(0, 3);// 文件扩展名
             *          DownloadImage(filename, @"骚话\", word + "." + extension);// 下载图片
             *          result = strs[2].Replace(strs2.First(), @"骚话\" + word);// 原本的缓存重新导向
             *      }
             *      CoquettishConfig.Instance.CoquettishWords.Add(new CoquettishWord(word, result));
             *      CoquettishConfig.Save();
             *  }
             *  else
             *  {
             *      Messenger.SendPrivate(context.FromQq, "参数不足,添加骚话请使用: 添加骚话 关键词 骚话");
             *  }
             * }*/

            if (context.Message.StartsWith("删除骚话"))
            {
                var strs = context.Message.Split(' ');
                if (strs.Length >= 2)
                {
                    CoquettishConfig.Instance.CoquettishWords.Remove(CoquettishConfig.Instance.CoquettishWords
                                                                     .Where(word => word.word == strs[1]).ToList().First());
                    Messenger.SendPrivate(context.FromQq, "已经移除.");
                }
            }
            if (context.FromQq == Config.Instance.QQ)
            {
                if (context.Message == $"没有开启通知的群 {Config.Instance.Code}")
                {
                    var groups = _mahuaApi.GetGroupsWithModel().Model.ToList();
                    var gs     = groups.Where(g => !groups.Contains(g)).Select(g => $"{g.Group}-{g.Name}");

                    Messenger.SendPrivate(context.FromQq, string.Join("\r\n", gs));
                }
                if (context.Message == $"执行自动更新 {Config.Instance.Code}")
                {
                    AutoUpdateRR.Execute();
                }
            }

            if (context.Message.Contains("添加群"))
            {
                var strs = context.Message.Split(' ');
                if (strs.Length >= 3)
                {
                    if (strs[1] == Config.Instance.Code)
                    {
                        if (strs[2].IsNumber())
                        {
                            //mycode begin  判断群是否存在,且是否有管理权限
                            if (_wFGraceMange.QQisGroupMember(_mahuaApi, strs[2], context.FromQq) < 0)
                            {
                                Messenger.SendPrivate(context.FromQq, $"您不是群[{strs[2]}]的成员,或机器人未加入此群");
                                return;
                            }
                            var info = _wFGraceMange.GetGroupMemberInfo(_mahuaApi, strs[2], context.FromQq);
                            if (info.Authority == GroupMemberAuthority.Normal || info.Authority == GroupMemberAuthority.Unknown)
                            {
                                Messenger.SendPrivate(context.FromQq, "您的权限不足,需要群主或者管理员权限");
                                return;
                            }
                            //mycode end
                            if (Config.Instance.WFGroupList.Contains(strs[2]))
                            {
                                Messenger.SendPrivate(context.FromQq, "群号已经存在.");
                            }
                            else
                            {
                                Config.Instance.WFGroupList.Add(strs[2]);
                                Config.Save();
                                Messenger.SendPrivate(context.FromQq, "完事.");
                                Messenger.SendGroup(strs[2], $"{context.FromQq}已经在私聊启用了此群的新任务通知功能.");
                                Messenger.SendDebugInfo($"{strs[2]}启用了通知功能.");
                            }
                        }
                        else
                        {
                            Messenger.SendPrivate(context.FromQq, "您群号真牛逼."); // 看一次笑一次 2
                        }
                    }
                    else
                    {
                        Messenger.SendPrivate(context.FromQq, "口令错误.");
                    }
                }
                else
                {
                    Messenger.SendPrivate(context.FromQq, "参数不足.");
                }
            }
            if (context.Message.Contains("删除群"))
            {
                var strs = context.Message.Split(' ');
                if (strs.Length >= 3)
                {
                    if (strs[1] == Config.Instance.Code)
                    {
                        if (strs[2].IsNumber())
                        {
                            Config.Instance.WFGroupList.Remove(strs[2]);
                            Config.Save();
                            Messenger.SendPrivate(context.FromQq, "完事.");
                            Messenger.SendGroup(strs[2], $"{context.FromQq}已经在私聊禁用了此群的新任务通知功能.");
                            Messenger.SendDebugInfo($"{strs[2]}禁用了通知功能.");
                        }
                        else
                        {
                            Messenger.SendPrivate(context.FromQq, "您群号真牛逼.");
                        }
                    }
                    else
                    {
                        Messenger.SendPrivate(context.FromQq, "口令错误.");
                    }
                }
                else
                {
                    Messenger.SendPrivate(context.FromQq, "参数不足.");
                }
            }
        }