public void GroupMessage(object sender, CQGroupMessageEventArgs e)
        {
            if (!Sdata.isReady)
            {
                return;
            }                              //如果配置没有成功加载,则不处理消息

            if (e.Message.Text.StartsWith("#"))
            {
                if (e.FromQQ.Id.ToString() != Sdata.adminQQ)
                {
                    Sdata.log.Warning("鉴权", "权限不足的用户在尝试使用#命令<" + e.FromQQ.ToString() + "!=" + Sdata.adminQQ);
                    Sdata.APIII.SendGroupMessage(e.FromGroup, "抱歉,权限不足!");
                    return;
                }
                String command_msg = e.Message.Text.Substring(1);
//                command_msg = "/" + command_msg;
                TCPLK_QQ temp2 = (TCPLK_QQ)Sdata.GroupList[e.FromGroup.Id];
                temp2.sendData("cmd", command_msg);
                return;
            }

            //处理普通消息(转换CQ码,处理@的信息,加上用户名)
            String sendMSG;
            //获取群名片
            String frome_name = Sdata.APIII.GetGroupMemberInfo(e.FromGroup, e.FromQQ).Card;

            if (frome_name.Equals("")) //如果没有获取到群名片,就拿QQ昵称替代
            {
                frome_name = Sdata.APIII.GetGroupMemberInfo(e.FromGroup, e.FromQQ).Nick;
            }
            String text = e.Message.Text;

            text    = text.Replace("\n", " | ");            //处理换行
            text    = KQlib.CQmsg_re(text, e.FromGroup.Id); //处理CQ码
            sendMSG = "[" + frome_name + "]:" + text;       //拼接消息
            //发送消息
            TCPLK_QQ temp1 = (TCPLK_QQ)Sdata.GroupList[e.FromGroup.Id];

            temp1.send(sendMSG);
            return;
        }
Пример #2
0
        //这个方法将在程序运行时执行
        public void AppEnable(object sender, CQAppEnableEventArgs e)
        {
            e.CQLog.Info("localnet连接插件开始加载...");
            Sdata.APIII = e.CQApi;
            Sdata.log   = e.CQLog;

            //加载配置文件
            if (!File.Exists("./LNconfig.txt"))
            {
                Sdata.log.Warning("配置文件", "未找到配置文件,创建之...");
                File.Create("./LNconfig.txt").Dispose();
                System.IO.StreamWriter config_file_ = new System.IO.StreamWriter("./LNconfig.txt");
                config_file_.WriteLine("#修改为你localnet的IP和端口");
                config_file_.WriteLine("IP=127.0.0.1");
                config_file_.WriteLine("Port=2333333");
                config_file_.WriteLine("#管理员QQ号");
                config_file_.WriteLine("adminQQ=123456789");
                config_file_.Close();
                Sdata.log.Warning("配置文件", "配置文件创建完毕,请修改配置文件并重新启用应用");
                return;
            }


            if (!File.Exists("./LNid.txt"))
            {
                Sdata.log.Warning("配置文件", "未找到ID配置文件,创建之...");
                File.Create("./LNid.txt").Dispose();
                Sdata.log.Warning("配置文件", "ID配置文件创建完毕");
            }

            //读取配置文件
            System.IO.StreamReader config_file = new System.IO.StreamReader("./LNconfig.txt");
            while (true)
            {
                string line_text = config_file.ReadLine();
                if (line_text == null)
                {
                    break;
                }
                string[] temp2 = line_text.Split('=');
                if (temp2.Length != 2)
                {
                    continue;
                }
                switch (temp2[0])
                {
                case "IP":
                    Sdata.lnIP = temp2[1];
                    break;

                case "Port":
                    Sdata.lnPort = int.Parse(temp2[1]);
                    break;

                case "adminQQ":
                    Sdata.adminQQ = temp2[1];
                    break;

                default:
                    Sdata.log.Info("配置文件", "未知配置项目:" + line_text);
                    break;
                }
            }
            config_file.Close();
            if (Sdata.lnIP == null)
            {
                Sdata.log.Error("配置文件", "未在配置文件中找到配置项目<IP>"); return;
            }
            if (Sdata.lnPort == null)
            {
                Sdata.log.Error("配置文件", "未在配置文件中找到配置项目<Port>"); return;
            }
            if (Sdata.adminQQ == null)
            {
                Sdata.log.Error("配置文件", "未在配置文件中找到配置项目<adminQQ>"); return;
            }

            //读取ID对照表
            System.IO.StreamReader id_file = new System.IO.StreamReader("./LNid.txt");
            while (true)
            {
                string line_text = id_file.ReadLine();
                if (line_text == null)
                {
                    break;
                }
                string[] temp2 = line_text.Split('=');
                if (temp2.Length != 2)
                {
                    Sdata.log.Error("配置文件", "ID配置文件行<" + line_text + ">无效"); continue;
                }
                Sdata.IDlist.Add(temp2[0], temp2[1]);
            }

            //载入群列表
            List <Native.Sdk.Cqp.Model.GroupInfo> temp1 = Sdata.APIII.GetGroupList();

            for (int temp2 = 0; temp2 < temp1.Count; temp2++)//批量向localnet注册群
            {
                Sdata.log.Info("初始化", "加载群:" + temp1[temp2].Group.Id + "=" + KQlib.ID_re(temp1[temp2].Group.Id.ToString()));
                Sdata.GroupList.Add(temp1[temp2].Group.Id, new TCPLK_QQ(Sdata.lnIP, Sdata.lnPort, KQlib.ID_re(temp1[temp2].Group.Id.ToString()), temp1[temp2].Group.Id));
            }
            Sdata.isReady = true;
        }