public void GroupMessage(object sender, CQGroupMessageEventArgs e)
    {
        try
        {
            if (e.IsFromAnonymous)
            {
                e.Handler = false;
                return;
            }

            if (e.Message.Text.Contains("#启用公会战工具") && isAdmin(e))
            {
                if (GuildBattle.GetInstance(e.FromGroup.Id).GetActive())
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "工具已启用,该指令无效!");
                }
                //else if (GuildBattle.GetInstance(e.FromGroup.Id).GetGroup() != -1) e.CQApi.SendGroupMessage(e.FromGroup.Id, "已在其它群启用工具,请先禁用!");
                else
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).SetActive(true);
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "已成功启用!");
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("#help"))
            {
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "[指令列表]\n" + "https://docs.qq.com/sheet/DYXBDZ1RmRXdXR0dH");
                e.Handler = true;
                return;
            }

            // 未启用公会战工具时,拦截以下指令
            if (!GuildBattle.GetInstance(e.FromGroup.Id).GetActive())
            {
                e.Handler = false;
                return;
            }

            if (e.Message.Text.Contains("#禁用公会战工具") && isAdmin(e))
            {
                if (!GuildBattle.GetInstance(e.FromGroup.Id).GetActive())
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "工具已禁用,该指令无效!");
                }
                else
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).SetActive(false);
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "已成功禁用!");
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Contains("#重置公会战数据") && isAdmin(e))
            {
                // 重置BOSS
                GuildBattle.GetInstance(e.FromGroup.Id).SetFrequency(1, 1);
                // 清空出刀
                GuildBattle.GetInstance(e.FromGroup.Id).ClearBattleUser();
                // 清空留言
                GuildBattle.GetInstance(e.FromGroup.Id).ClearMessage();
                // 清空预约
                GuildBattle.GetInstance(e.FromGroup.Id).ClearSubscribe();
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("公会战状态"))
            {
                List <string> logs = SQLiteManager.GetInstance().GetLogs(e.FromGroup.Id);
                string        text = "【日志记录】";

                for (int i = 0; i < logs.Count; ++i)
                {
                    text += "\n" + logs[i];
                }

                text += "\n\n" + "【战斗列表】" + "\n" + GuildBattle.PrintList(e.FromGroup.Id, GuildBattle.GetInstance(e.FromGroup.Id).GetBattleUser());
                text += "\n\n" + "【挂树列表】" + "\n" + GuildBattle.PrintList(e.FromGroup.Id, GuildBattle.GetInstance(e.FromGroup.Id).GetTreeUser());
                e.CQApi.SendGroupMessage(e.FromGroup.Id, text);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("出刀列表"))
            {
                string text = "【战斗列表】" + "\n" + GuildBattle.PrintList(e.FromGroup.Id, GuildBattle.GetInstance(e.FromGroup.Id).GetBattleUser());
                e.CQApi.SendGroupMessage(e.FromGroup.Id, text);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("挂树列表"))
            {
                string text = "【挂树列表】" + "\n" + GuildBattle.PrintList(e.FromGroup.Id, GuildBattle.GetInstance(e.FromGroup.Id).GetTreeUser());
                e.CQApi.SendGroupMessage(e.FromGroup.Id, text);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("我挂树了") || e.Message.Text.Equals("救救救") || e.Message.Text.Equals("申请挂树"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).AddTreeUser(e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if ((e.Message.Text.StartsWith("他挂树了 [CQ:at,qq=") || e.Message.Text.StartsWith("他挂树了[CQ:at,qq=")))
            {
                long qq = GetOperateQQ(e.Message.Text);
                GuildBattle.GetInstance(e.FromGroup.Id).AddTreeUser(qq);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Contains("我去去就来") || e.Message.Text.Equals("申请出刀"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).AddBattleUser(e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if ((e.Message.Text.StartsWith("申请出刀 [CQ:at,qq=") || e.Message.Text.StartsWith("代刀中 [CQ:at,qq=")))
            {
                long qq = GetOperateQQ(e.Message.Text);
                GuildBattle.GetInstance(e.FromGroup.Id).AddBattleUser(qq, e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if ((e.Message.Text.StartsWith("取消挂树 [CQ:at,qq=") || e.Message.Text.StartsWith("取消挂树[CQ:at,qq=")))
            {
                long qq = GetOperateQQ(e.Message.Text);
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveTreeUser(qq);
                e.Handler = true;
                return;
            }

            if ((e.Message.Text.StartsWith("取消出刀 [CQ:at,qq=") || e.Message.Text.StartsWith("取消出刀[CQ:at,qq=")))
            {
                long qq = GetOperateQQ(e.Message.Text);
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveBattleUser(qq, e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("取消挂树"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveTreeUser(e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("取消出刀"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveBattleUser(e.FromQQ.Id, e.FromQQ.Id);
                e.Handler = true;
                return;
            }

            if ((e.Message.Text.StartsWith("伤害 [CQ:at,qq=") || e.Message.Text.StartsWith("修改伤害 [CQ:at,qq=")))
            {
                long qq = GetOperateQQ(e.Message.Text);

                string[] temp = e.Message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                int  troop_num;
                long damage;

                if (temp.Length != 4 || !int.TryParse(temp[2], out troop_num) || !long.TryParse(temp[3], out damage))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup, "输入格式与要求不符!");
                    e.Handler = true;
                    return;
                }

                if (e.Message.Text.StartsWith("修改伤害 [CQ:at,qq="))
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).PushDamage(qq, troop_num, damage, true);
                }
                else
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).PushDamage(qq, troop_num, damage, false, e.FromQQ.Id);
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("伤害 ") || e.Message.Text.StartsWith("修改伤害 "))
            {
                string[] temp = e.Message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                int  troop_num;
                long damage;

                if (temp.Length != 3 || !int.TryParse(temp[1], out troop_num) || !long.TryParse(temp[2], out damage))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup, "输入格式与要求不符!");
                    e.Handler = true;
                    return;
                }

                if (e.Message.Text.StartsWith("修改伤害 "))
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).PushDamage(e.FromQQ.Id, troop_num, damage, true);
                }
                else
                {
                    GuildBattle.GetInstance(e.FromGroup.Id).PushDamage(e.FromQQ.Id, troop_num, damage, false);
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("设置BOSS ") && isAdmin(e))
            {
                string[] temp = e.Message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                int frequency, boss_num;

                if (temp.Length != 3 || !int.TryParse(temp[1], out frequency) || !int.TryParse(temp[2], out boss_num))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup, "输入格式与要求不符!");
                    e.Handler = true;
                    return;
                }
                GuildBattle.GetInstance(e.FromGroup.Id).SetFrequency(frequency, boss_num);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("设置血量 ") && isAdmin(e))
            {
                string[] temp = e.Message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (temp.Length != 2)
                {
                    e.CQApi.SendGroupMessage(e.FromGroup, "输入格式与要求不符!");
                }
                long blood;
                if (!long.TryParse(temp[1], out blood))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup, "输入格式与要求不符!");
                }
                GuildBattle.GetInstance(e.FromGroup.Id).SetDamage(blood);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("清空出刀") && isAdmin(e))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).ClearBattleUser();
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "战斗列表已清空!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("清空挂树") && isAdmin(e))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).ClearTreeUser();
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "挂树列表已清空!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("今日伤害 [CQ:at,qq=") && isAdmin(e) && !FileOptions.GetInstance().IsDisableAt())
            {
                long qq = GetOperateQQ(e.Message.Text);
                e.CQApi.SendPrivateMessage(e.FromQQ.Id, GetTodayDamage(e.FromGroup.Id, qq));
                //e.CQApi.SendPrivateMessage(qq, "[" + GuildBattle.GetUserName(e.FromGroup.Id, e.FromQQ.Id) + "] 查询了您的今日伤害数据");
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "相关数据已通过私聊发送!");
                e.Handler = true;
                return;
            }

            if (Regex.IsMatch(e.Message.Text, @"今日伤害 (\d+)") && isAdmin(e))
            {
                Match match = Regex.Match(e.Message.Text, @"今日伤害 (\d+)");
                long  qq;
                if (!long.TryParse(match.Groups[1].Value, out qq))
                {
                    return;
                }
                e.CQApi.SendPrivateMessage(e.FromQQ.Id, GetTodayDamage(e.FromGroup.Id, qq));
                e.CQApi.SendPrivateMessage(qq, "[" + GuildBattle.GetUserName(e.FromGroup.Id, e.FromQQ.Id) + "] 查询了您的今日伤害数据");
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "相关数据已通过私聊发送!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("今日伤害"))
            {
                e.CQApi.SendGroupMessage(e.FromGroup.Id, GetTodayDamage(e.FromGroup.Id, e.FromQQ.Id));
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("查看总伤害 [CQ:at,qq=") && isAdmin(e) && !FileOptions.GetInstance().IsDisableAt())
            {
                long qq = GetOperateQQ(e.Message.Text);
                e.CQApi.SendPrivateMessage(e.FromQQ.Id, GetRecentDaysDamages(e.FromGroup.Id, qq));
                //e.CQApi.SendPrivateMessage(qq, "[" + GuildBattle.GetUserName(e.FromGroup.Id, e.FromQQ.Id) + "] 查询了您的今日伤害数据");
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "相关数据已通过私聊发送!");
                e.Handler = true;
                return;
            }

            if (Regex.IsMatch(e.Message.Text, @"查看总伤害 (\d+)") && isAdmin(e))
            {
                Match match = Regex.Match(e.Message.Text, @"查看总伤害 (\d+)");
                long  qq;
                if (!long.TryParse(match.Groups[1].Value, out qq))
                {
                    return;
                }
                e.CQApi.SendPrivateMessage(e.FromQQ.Id, GetRecentDaysDamages(e.FromGroup.Id, qq));
                e.CQApi.SendPrivateMessage(qq, "[" + GuildBattle.GetUserName(e.FromGroup.Id, e.FromQQ.Id) + "] 查询了您的今日伤害数据");
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "相关数据已通过私聊发送!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("查看总伤害"))
            {
                e.CQApi.SendGroupMessage(e.FromGroup.Id, GetRecentDaysDamages(e.FromGroup.Id, e.FromQQ.Id));
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("查看公会总伤害") && isAdmin(e))
            {
                e.CQApi.SendGroupMessage(e.FromGroup.Id, GetRecentDaysGuildTotalDamages(e.FromGroup.Id));
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("出刀统计") && isAdmin(e))
            {
                e.CQApi.SendGroupMessage(e.FromGroup, BattleStatistics(e));
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("代刀统计") && isAdmin(e))
            {
                e.CQApi.SendGroupMessage(e.FromGroup, GuildBattle.GetInstance(e.FromGroup.Id).GetHelpTroopNum());
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("查看留言板") || e.Message.Text.Equals("查看留言"))
            {
                string output = "【留言板】";
                Dictionary <long, string> messages = new Dictionary <long, string>(GuildBattle.GetInstance(e.FromGroup.Id).GetMessages()); //简单粗暴解决并发问题,有待优化
                if (messages == null || messages.Count == 0)
                {
                    output += "\n无记录";
                }
                else
                {
                    foreach (KeyValuePair <long, string> kvp in messages)
                    {
                        output += "\n" + "[" + GuildBattle.GetUserName(e.FromGroup.Id, kvp.Key) + "] " + kvp.Value;
                    }
                }
                e.CQApi.SendGroupMessage(e.FromGroup, output);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("留言 "))
            {
                string[] temp       = e.Message.Text.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string   addMessage = Regex.Replace(temp[1], @"\[CQ[^\s\]]+\]", "");
                GuildBattle.GetInstance(e.FromGroup.Id).AddMessage(e.FromQQ.Id, addMessage.Trim());
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "设置留言成功!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("删除留言") || e.Message.Text.Equals("取消留言"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveMessage(e.FromQQ.Id);
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "删除留言成功!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("清空留言") && isAdmin(e))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).ClearMessage();
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "已成功清空所有留言!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.StartsWith("预约 "))
            {
                string[] temp = e.Message.Text.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);

                int boss_num = 0;
                if (!int.TryParse(temp[1], out boss_num) || boss_num <1 || boss_num> GuildBattle.BOSS_MAX)
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "参数错误!");
                    e.Handler = true;
                    return;
                }

                if (GuildBattle.GetInstance(e.FromGroup.Id).AddSubscribe(e.FromQQ.Id, boss_num))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "已成功为[CQ:at,qq=" + e.FromQQ.Id.ToString() + "] 预约第" + temp[1] + "号BOSS" + "\n" + "注:只能同时预约一个BOSS,多次预约的数据将被覆盖");
                }
                else
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "当前已经是第" + temp[1] + "号BOSS,预约无效");
                }

                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("取消预约"))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).RemoveSubscribe(e.FromQQ.Id);
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "取消成功!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("清空预约") && isAdmin(e))
            {
                GuildBattle.GetInstance(e.FromGroup.Id).ClearSubscribe();
                e.CQApi.SendGroupMessage(e.FromGroup.Id, "已成功清空所有预约!");
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("查看预约") || e.Message.Text.Equals("预约列表"))
            {
                List <string> list = GuildBattle.GetInstance(e.FromGroup.Id).GetSubscribeList();
                string        text = "【预约列表】";
                for (int i = 0; i < list.Count; ++i)
                {
                    text += "\n" + list[i];
                }
                if (list.Count == 0)
                {
                    text += "\n无记录";
                }
                e.CQApi.SendGroupMessage(e.FromGroup.Id, text);
                e.Handler = true;
                return;
            }

            if (e.Message.Text.Equals("状态"))
            {
                e.CQApi.SendGroupMessage(e.FromGroup.Id, GuildBattle.GetInstance(e.FromGroup.Id).GetBossStatus());
                e.Handler = true;
                return;
            }

            if (e.Message.Text.ToUpper().Equals("申请SL") || e.Message.Text.ToUpper().StartsWith("申请SL [CQ:at,qq=", true, null))
            {
                long qq = e.FromQQ.Id;
                if (e.Message.Text.ToUpper().StartsWith("申请SL [CQ:at,qq=", true, null))
                {
                    qq = GetOperateQQ(e.Message.Text);
                }
                if (GuildBattle.GetInstance(e.FromGroup.Id).SetSL(qq))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "今日SL次数使用状态已记录!\n[今日SL使用状态] 已使用\n[使用时间] " + SQLiteManager.ConvertIntDateTime(SQLiteManager.GetTimeStamp()));
                }
                else
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "今日SL次数已用完!指令无效!");
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.ToUpper().Equals("撤销SL") || e.Message.Text.ToUpper().StartsWith("撤销SL [CQ:at,qq=", true, null))
            {
                long qq = e.FromQQ.Id;
                if (e.Message.Text.ToUpper().StartsWith("撤销SL [CQ:at,qq=", true, null))
                {
                    qq = GetOperateQQ(e.Message.Text);
                }
                if (GuildBattle.GetInstance(e.FromGroup.Id).RemoveSL(qq))
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "今日SL使用状态已成功撤销!\n[今日SL使用状态] 未使用\n[使用时间] 无");
                }
                else
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "今日SL次数仍未被使用!指令无效!");
                }
                e.Handler = true;
                return;
            }

            if (e.Message.Text.ToUpper().Equals("查询SL") || e.Message.Text.ToUpper().StartsWith("查询SL [CQ:at,qq=", true, null))
            {
                long qq = e.FromQQ.Id;
                if (e.Message.Text.ToUpper().StartsWith("查询SL [CQ:at,qq=", true, null))
                {
                    qq = GetOperateQQ(e.Message.Text);
                }
                long checkTime = GuildBattle.GetInstance(e.FromGroup.Id).GetSLStatus(qq);
                if (checkTime > -1)
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "[今日SL使用状态] 已使用\n[使用时间] " + SQLiteManager.ConvertIntDateTime(checkTime));
                }
                else
                {
                    e.CQApi.SendGroupMessage(e.FromGroup.Id, "[今日SL使用状态] 未使用\n[使用时间] 无");
                }
                e.Handler = true;
                return;
            }
        } catch (Exception exception)
        {
            e.CQLog.Warning("GroupMessage", exception);
        }
    }
Example #2
0
    public void AddBattleUser(long qq, long helper = 0)
    {
        if (data.battleUser.Contains(qq))
        {
            ApiModel.CQApi.SendGroupMessage(group, "您目前已经在出刀列表中,请勿重复申请。");
            return;
        }
        data.battleUser.Add(qq);
        //发送代刀消息
        if (helper > 0)
        {
            SendHelpTroopMessage(qq, helper);
        }
        SaveData();

        long SLTime = GetSLStatus(qq); // SL时间,-1为未SL

        ApiModel.CQApi.SendGroupMessage(group, "战斗状态已记录!目前战斗状态列表:\n" + PrintList(group, GetBattleUser()) + "\n\n" +
                                        (data.treeUser.Count == 0 ? "" : "【注意】 目前有 " + data.treeUser.Count.ToString() + " 人正在挂树!\n") +
                                        (SLTime == -1 ? "" : "【注意】 " + (helper > 0 ? "该账号" : "您") + "今日已于" + SQLiteManager.ConvertIntDateTime(SLTime) + "(GMT+8) 进行过SL操作!\n") +
                                        "第" + data.frequency.ToString() + "周目 " + data.bossNumber.ToString() + "号BOSS 剩余HP: " + GetBossLessDamage().ToString()
                                        );
    }