public override int HandleImpl() { try { String[] temp = message.Split(' '); String AttentionPoint = temp[1]; String GroupNum = temp[2]; //添加前先检测:1.群号是否为一串数字;2.该用户和本机器人是否都在群中; //如果不是就抛出异常 GroupMemberInfoCollection groupMemberInfoCollection = CQEventArgsArgs.CQApi.GetGroupMemberList(Convert.ToInt64(GroupNum)); int flag = 0; foreach (GroupMemberInfo groupMemberInfo in groupMemberInfoCollection) { if (groupMemberInfo.QQ.Id.Equals(Convert.ToInt64(fromQQ))) { flag += 1; } else if (groupMemberInfo.QQ.Id.Equals(Convert.ToInt64(botQQ))) { flag += 2; } } if (flag < 3) { throw new InvalidDataException(); } AttentionService attentionService = new AttentionService(); attentionService.Add(fromQQ, AttentionPoint, GroupNum); CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加成功】添加关注成功!"); } catch (IndexOutOfRangeException e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】添加关注的正确格式是 “添加关注 考试(内容) 1525468122(群号)"); } catch (DbUpdateException e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】数据库更新异常"); } catch (FormatException e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】群号中只能包含数字"); } catch (InvalidDataException e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】用户或机器人不在群聊中"); } catch (ArgumentOutOfRangeException e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】无效QQ群号"); } catch (Exception e) { CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【添加失败】\n" + e.Message); } return(0); }
public string BattleStatistics(CQGroupMessageEventArgs e) { string output = "【今日出刀状况】"; List <SQLiteManager.Damage> damages = SQLiteManager.GetInstance().GetTodayDamages(e.FromGroup.Id); GroupMemberInfoCollection infos = e.CQApi.GetGroupMemberList(e.FromGroup); foreach (GroupMemberInfo info in infos) { if (GuildBattle.GetInstance(e.FromGroup.Id).GetMemberList() == null) { if (!info.Card.Contains(GuildBattle.GetSignChar())) { continue; } } else { if (!GuildBattle.GetInstance(e.FromGroup.Id).GetMemberList().Contains(info.QQ.Id)) { continue; } } SQLiteManager.Damage temp = new SQLiteManager.Damage(); temp.user = info.QQ.Id; temp.damage = temp.troop = 0; if (damages.Contains(temp, SQLiteManager.DamageComparer.Default)) { continue; } damages.Add(temp); } for (int i = 0; i < damages.Count; ++i) { for (int j = i + 1; j < damages.Count; ++j) { if (damages[i].troop < damages[j].troop || (damages[i].troop == damages[j].troop && damages[i].damage < damages[j].damage)) { SQLiteManager.Damage temp = damages[i]; damages[i] = damages[j]; damages[j] = temp; } } } long totalTroop = 0; long totalDamage = 0; int totalReimburseTroop = 0; for (int i = 0; i < damages.Count; ++i) { totalTroop += damages[i].troop; totalDamage += damages[i].damage; totalReimburseTroop += damages[i].is_reimburse; output += "\n" + GuildBattle.GetUserName(e.FromGroup.Id, damages[i].user) + "\t\t" + (damages[i].troop - damages[i].is_reimburse).ToString(); if (damages[i].is_reimburse > 0) { output += "(+" + damages[i].is_reimburse.ToString() + ")"; } output += "刀\t伤害: " + damages[i].damage.ToString(); } output += "\n【已进行战斗次数(含补刀)】 " + (totalTroop - totalReimburseTroop).ToString(); if (totalReimburseTroop > 0) { output += "(+" + totalReimburseTroop.ToString() + ")"; } output += " 次"; output += "\n【本日总伤害】 " + totalDamage.ToString(); return(output); }