예제 #1
0
        /// <summary>
        /// Type=21 私聊消息。
        /// </summary>
        /// <param name="subType">子类型,11/来自好友 1/来自在线状态 2/来自群 3/来自讨论组。</param>
        /// <param name="sendTime">发送时间(时间戳)。</param>
        /// <param name="fromQQ">来源QQ。</param>
        /// <param name="msg">消息内容。</param>
        /// <param name="font">字体。</param>
        public override void PrivateMessage(int subType, int sendTime, long fromQQ, string msg, int font)
        {
            // 处理私聊消息。
            logs.Log_write("私聊消息" + '[' + fromQQ.ToString() + "][" + CQ.GetQQName(fromQQ) + "]:" + msg);
            if (msg.IndexOf(XML.read(config_read.Event, "绑定文本")) == 0)
            {
                string player = null;
                if (Mysql_mode == true)
                {
                    player = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                }
                else
                {
                    player = XML.read(config_read.player, fromQQ.ToString());
                }
                if (player == null)
                {
                    string player_name = msg.Replace(XML.read(config_read.Event, "绑定文本"), "");
                    if (player_name == " " || player_name == "" || use.IsNatural_Number(player_name) == false)
                    {
                        CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "绑定失败,请检查你的ID");
                    }
                    else
                    {
                        player_name = player_name.Trim();
                        if (Mysql_mode == true)
                        {
                            if (Mysql.mysql_search(Mysql.Mysql_notid, player_name.ToLower()) == "notid")
                            {
                                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                return;
                            }
                            Mysql.mysql_add(Mysql.Mysql_player, fromQQ.ToString(), player_name.ToString());
                        }
                        else
                        {
                            if (XML.read(config_read.notid, player_name.ToLower()) == "notid")
                            {
                                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                return;
                            }
                            XML.write(config_read.player, fromQQ.ToString(), player_name);
                        }

                        CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "绑定ID:" + player_name + "成功!");

                        string qq_admin = XML.read(config_read.admin, "发送给的人");
                        if (qq_admin != null)
                        {
                            CQ.SendPrivateMessage(long.Parse(qq_admin), "玩家[" + CQ.GetQQName(fromQQ) + "]绑定了ID:[" + player_name + "]");
                        }
                    }
                }
                else
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "你已经绑定ID了,请找腐竹更改");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "禁言文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "禁言文本"), "");
                string player_name = null;
                if (player.IndexOf("[CQ") != -1)
                {
                    player = use.get_string(player, "=", "]");
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                    }
                    else
                    {
                        player_name = XML.read(config_read.player, player);
                    }
                }
                else
                {
                    player_name = player;
                }
                player_name = player_name.Trim();
                if (player_name == null)
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "该玩家未绑定ID");
                }
                else
                {
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "true");
                    }
                    else
                    {
                        XML.write(config_read.mute, player_name.ToLower(), "true");
                    }
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已禁言:[" + player_name + "]");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "解禁文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "解禁文本"), "");
                string player_name = null;
                if (player.IndexOf("[CQ") != -1)
                {
                    player = use.get_string(player, "=", "]");
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                    }
                    else
                    {
                        player_name = XML.read(config_read.player, player);
                    }
                }
                else
                {
                    player_name = player;
                }
                player_name = player_name.Trim();
                if (player_name == null)
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "该玩家未绑定ID");
                }
                else
                {
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "false");
                    }
                    else
                    {
                        XML.write(config_read.mute, player_name.ToLower(), "false");
                    }
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已解禁:[" + player_name + "]");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "查询玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player = msg.Replace(XML.read(config_read.Event, "查询玩家ID"), "");
                player = use.get_string(player, "=", "]");
                string player_name = null;
                if (Mysql_mode == true)
                {
                    player_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                }
                else
                {
                    player_name = XML.read(player, fromQQ.ToString());
                }
                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "玩家ID:" + player_name);
            }
            if (msg.IndexOf(XML.read(config_read.Event, "修改玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "修改玩家ID"), "");
                string player_name = player;
                player      = use.get_string(player, "=", "]");
                player_name = use.get_string(player_name, "]");
                player_name = player_name.Trim();
                if (Mysql_mode == true)
                {
                    XML.write(player, player, player_name);
                }
                else
                {
                    Mysql.mysql_add(Mysql.Mysql_player, player, player_name);
                }

                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已修改玩家[" + player + "]ID为:" + player_name);
            }
            if (msg == XML.read(config_read.Event, "维护文本") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                if (XML.read(config_read.config, "维护模式") == "关")
                {
                    XML.write(config_read.config, "维护模式", "开");
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "服务器维护模式已开启");
                    server = false;
                    return;
                }
                else
                {
                    XML.write(config_read.config, "维护模式", "关");
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "服务器维护模式已关闭");
                    server = true;
                    return;
                }
            }
            if (msg.IndexOf("打开菜单") == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                CQ.SendPrivateMessage(fromQQ, "已打开,请前往后台查看");
                OpenSettingForm();
            }
            if (msg == XML.read(config_read.Event, "机器人功能-重读配置文件") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                CQ.SendPrivateMessage(fromQQ, "开始重读配置文件");
                config_read.read_config();
                CQ.SendPrivateMessage(fromQQ, "重读完成");
            }
            if (msg == XML.read(config_read.Event, "机器人功能-内存回收") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                try
                {
                    GC.Collect();
                    CQ.SendPrivateMessage(fromQQ, "内存回收完毕");
                }
                catch (Exception exception)
                { }
            }
        }
예제 #2
0
        /// <summary>
        /// Type=2 群消息。
        /// </summary>
        /// <param name="subType">子类型,目前固定为1。</param>
        /// <param name="sendTime">发送时间(时间戳)。</param>
        /// <param name="fromGroup">来源群号。</param>
        /// <param name="fromQQ">来源QQ。</param>
        /// <param name="fromAnonymous">来源匿名者。</param>
        /// <param name="msg">消息内容。</param>
        /// <param name="font">字体。</param>
        public override void GroupMessage(int subType, int sendTime, long fromGroup, long fromQQ, string fromAnonymous, string msg, int font)
        {
            logs.Log_write('[' + fromGroup.ToString() + ']' + '[' + fromQQ.ToString() + "][" + CQ.GetQQName(fromQQ) + "]:" + msg);
            // 处理群消息。
            if (fromGroup == GroupSet1 || fromGroup == GroupSet2 || fromGroup == GroupSet3)
            {
                if (XML.read(config_read.message, msg) != "" && XML.read(config_read.message, "启用") == "true")
                {
                    CQ.SendGroupMessage(fromGroup, XML.read(config_read.message, msg));
                }
                if (XML.read(config_read.config, "发送消息") == "当然!")
                {
                    if (server == true && socket.ready == true)
                    {
                        if ((fromGroup == GroupSet2 && Group2_on == true) || (fromGroup == GroupSet3 && Group3_on == true) || fromGroup == GroupSet1)
                        {
                            string play_name = null;
                            if (Mysql_mode == true)
                            {
                                play_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                            }
                            else
                            {
                                play_name = XML.read(config_read.player, fromQQ.ToString());
                            }
                            if (play_name != null)
                            {
                                if (Mysql_mode == true)
                                {
                                    if (Mysql.mysql_search(Mysql.Mysql_mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (XML.read(config_read.mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                string send;
                                send = XML.read(config_read.config, "发送文本");
                                send = send.Replace("%player%", play_name);
                                msg  = use.remove_pic(msg);
                                if (msg == "")
                                {
                                    return;
                                }
                                msg  = use.get_at(msg);
                                send = send.Replace("%message%", use.remove_pic(msg));
                                socket.Send("群消息" + send, socket.MCserver);
                            }
                        }
                    }
                }
                else if (msg.IndexOf(XML.read(config_read.Event, "发送文本")) == 0 && XML.read(config_read.config, "发送消息") == "不!")
                {
                    if ((fromGroup == GroupSet2 && Group2_on == false) || (fromGroup == GroupSet3 && Group3_on == false))
                    {
                        CQ.SendGroupMessage(fromGroup, "该群没有开启聊天功能");
                    }
                    else if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            string play_name = null;
                            if (Mysql_mode == true)
                            {
                                play_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                            }
                            else
                            {
                                play_name = XML.read(config_read.player, fromQQ.ToString());
                            }
                            if (play_name != null && play_name != "")
                            {
                                if (Mysql_mode == true)
                                {
                                    if (Mysql.mysql_search(Mysql.Mysql_mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (XML.read(config_read.mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                string send;
                                send = XML.read(config_read.config, "发送文本");
                                send = send.Replace("%player%", play_name);
                                msg  = msg.Replace(XML.read(config_read.Event, "发送文本"), "");
                                msg  = use.remove_pic(msg);
                                if (msg == "")
                                {
                                    return;
                                }
                                msg  = use.get_at(msg);
                                send = send.Replace("%message%", use.remove_pic(msg));
                                socket.Send("群消息" + send, socket.MCserver);
                            }
                            else
                            {
                                CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "检测到你没有绑定服务器ID,发送:" + XML.read(config_read.Event, "绑定文本") + "ID来绑定,如:" +
                                                    "\n" + XML.read(config_read.Event, "绑定文本") + "Color_yr");
                            }
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg == XML.read(config_read.Event, "在线人数"))
                {
                    if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            if (fromGroup == GroupSet1)
                            {
                                Group = 1;
                            }
                            else if (fromGroup == GroupSet2)
                            {
                                Group = 2;
                            }
                            else if (fromGroup == GroupSet3)
                            {
                                Group = 3;
                            }
                            socket.Send("在线人数", socket.MCserver);
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg == XML.read(config_read.Event, "服务器状态"))
                {
                    if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "查询中,如果没有回复,则证明服务器未开启");
                            if (fromGroup == GroupSet1)
                            {
                                Group = 1;
                            }
                            else if (fromGroup == GroupSet2)
                            {
                                Group = 2;
                            }
                            else if (fromGroup == GroupSet3)
                            {
                                Group = 3;
                            }
                            socket.Send("服务器状态", socket.MCserver);
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "绑定文本")) == 0)
                {
                    string player = null;
                    if (Mysql_mode == true)
                    {
                        player = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                    }
                    else
                    {
                        player = XML.read(config_read.player, fromQQ.ToString());
                    }
                    if (player == null)
                    {
                        string player_name = msg.Replace(XML.read(config_read.Event, "绑定文本"), "");
                        if (player_name == " " || player_name == "" || use.IsNatural_Number(player_name) == false)
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "绑定失败,请检查你的ID");
                        }
                        else
                        {
                            player_name = player_name.Trim();
                            if (Mysql_mode == true)
                            {
                                if (Mysql.mysql_search(Mysql.Mysql_notid, player_name.ToLower()) == "notid")
                                {
                                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                    return;
                                }
                                Mysql.mysql_add(Mysql.Mysql_player, fromQQ.ToString(), player_name);
                            }
                            else
                            {
                                if (XML.read(config_read.notid, player_name.ToLower()) == "notid")
                                {
                                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                    return;
                                }
                                XML.write(config_read.player, fromQQ.ToString(), player_name);
                            }

                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "绑定ID:" + player_name + "成功!");

                            string qq_admin = XML.read(config_read.admin, "发送给的人");
                            if (qq_admin != null)
                            {
                                CQ.SendPrivateMessage(long.Parse(qq_admin), "玩家[" + CQ.GetQQName(fromQQ) + "]绑定了ID:[" + player_name + "]");
                            }
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "你已经绑定ID了,请找腐竹更改");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "禁言文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "禁言文本"), "");
                    string player_name = null;
                    if (player.IndexOf("[CQ") != -1)
                    {
                        player = use.get_string(player, "=", "]");
                        if (Mysql_mode == true)
                        {
                            player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                        }
                        else
                        {
                            player_name = XML.read(config_read.player, player);
                        }
                    }
                    else
                    {
                        player_name = player;
                    }
                    if (player_name == null)
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "ID无效");
                    }
                    else
                    {
                        if (Mysql_mode == true)
                        {
                            Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "true");
                        }
                        else
                        {
                            XML.write(config_read.mute, player_name.ToLower(), "true");
                        }
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已禁言:[" + player_name + "]");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "解禁文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "解禁文本"), "");
                    string player_name = null;
                    if (player.IndexOf("[CQ") != -1)
                    {
                        player = use.get_string(player, "=", "]");
                        if (Mysql_mode == true)
                        {
                            player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                        }
                        else
                        {
                            player_name = XML.read(config_read.player, player);
                        }
                    }
                    else
                    {
                        player_name = player;
                    }
                    if (player_name == null)
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "ID无效");
                    }
                    else
                    {
                        if (Mysql_mode == true)
                        {
                            Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "false");
                        }
                        else
                        {
                            XML.write(config_read.mute, player_name.ToLower(), "false");
                        }
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已解禁:[" + player_name + "]");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "查询玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player = msg.Replace(XML.read(config_read.Event, "查询玩家ID"), "");
                    player = use.get_string(player, "=", "]");
                    string player_name = null;
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                    }
                    else
                    {
                        player_name = XML.read(player, fromQQ.ToString());
                    }
                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "玩家ID:" + player_name);
                }
                if (msg.IndexOf(XML.read(config_read.Event, "修改玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "修改玩家ID"), "");
                    string player_name = player;
                    player      = use.get_string(player, "=", "]");
                    player_name = use.get_string(player_name, "]");
                    player_name = player_name.Trim();
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_player, player, player_name);
                    }
                    else
                    {
                        XML.write(player, player, player_name);
                    }

                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已修改玩家[" + player + "]ID为:" + player_name);
                }
                if (msg == XML.read(config_read.Event, "维护文本") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    if (XML.read(config_read.config, "维护模式") == "关")
                    {
                        XML.write(config_read.config, "维护模式", "开");
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "服务器维护模式已开启");
                        server = false;
                        return;
                    }
                    else
                    {
                        XML.write(config_read.config, "维护模式", "关");
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "服务器维护模式已关闭");
                        server = true;
                        return;
                    }
                }
                if (msg.IndexOf("打开菜单") == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    CQ.SendGroupMessage(fromGroup, "已打开,请前往后台查看");
                    OpenSettingForm();
                }
                if (msg == XML.read(config_read.Event, "机器人功能-重读配置文件") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    CQ.SendGroupMessage(fromGroup, "开始重读配置文件");
                    config_read.read_config();
                    CQ.SendGroupMessage(fromGroup, "重读完成");
                }
                if (msg == XML.read(config_read.Event, "机器人功能-内存回收") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    try
                    {
                        GC.Collect();
                        CQ.SendGroupMessage(fromGroup, "内存回收完毕");
                    }
                    catch (Exception exception)
                    { }
                }
            }
        }