public Task <bool> GroupApply(MiraiHttpSession session, IGroupApplyEventArgs e) { if (reqs == null) { reqs = new Dictionary <long, GroupEntranceInfo>(); } if (repeattask == null) { dmTokenSource = new CancellationTokenSource(); repeattask = Repeat.Interval(TimeSpan.FromSeconds(15), () => { TimeSpan now = DateTime.Now.TimeOfDay; if (now > startt && now < end && !hang_req && !hang_all) { checkAndProcessReqQueue(); } }, dmTokenSource.Token); } //string answer = e..Replace("鹿野", ""); if (DataBase.me.isUserOperator(e.user.qq)) { MainHolder.api.doGroupEnterReq(e.json, true); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n管理组成员,无条件通过"); } else if (DataBase.me.isCrewGroup(e.throughgroup.id)) { //是舰长群 if (DataBase.me.isUserBoundedUID(e.user.qq)) //舰长绑定 { MainHolder.api.doGroupEnterReq(e.json, true); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "\n!正在加入舰长群\n是舰长,同意"); } else { MainHolder.api.doGroupEnterReq(e.json, false, "该QQ无可查询的舰长信息,请联系管理员。"); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "\n!正在加入舰长群\n没有可查询的舰长记录,拒绝"); } } else if (DataBase.me.isUserTrusted(e.user.qq) >= 0)//有信任 { int t = DataBase.me.isUserTrusted(e.user.qq); long op = DataBase.me.getUserTrustOperator(e.user.qq); MainHolder.api.doGroupEnterReq(e.json, true); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n[ATUSER(" + op + ")]设置了信任,同意"); if (t == 1) { DataBase.me.removeUserTrustlist(e.user.qq); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + " 一次性信任失效"); } } else if (hang_all) { GroupEntranceInfo geinfo = new GroupEntranceInfo() { json = e.json, qq = e.FromQQ, group = e.throughgroup }; reqs.Add(e.user.qq, geinfo); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n请求挂起(UC)"); } else if ((answer.IndexOf("鹿") >= 0) || !((answer.IndexOf("奶狗") >= 0) || (answer.IndexOf("柴") >= 0) || (answer.IndexOf("狗") >= 0))) { MainHolder.api.doGroupEnterReq(e.json, false, "您的答案不太对"); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n" + answer + "\n答案不对,拒绝"); } else if (DataBase.me.whichGroupsAreTheUserIn(e.user.qq).Count > 0 && !DataBase.me.isMEIgnoreGroup(e.throughgroup.id)) { List <long> li = DataBase.me.whichGroupsAreTheUserIn(e.user.qq); string a = ""; foreach (long g in li) { a += DataBase.me.getGroupName(g) + "\n"; } MainHolder.api.doGroupEnterReq(e.json, false, "您已加入多个粉丝群。如有疑问请联系管理"); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n重复加群:\n" + a + "拒绝"); } else if (DataBase.me.isUserBlacklisted(e.user.qq)) { MainHolder.api.doGroupEnterReq(e.json, false, "您被指定禁止加入本群"); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n在黑名单,拒绝"); } else { long qqlevel = ThirdPartAPIs.getQQLevel(e.user.qq, 1); if (qqlevel < 0) { GroupEntranceInfo geinfo = new GroupEntranceInfo() { json = e.json, qq = e.user, group = e.throughgroup }; reqs.Add(e.user.qq, geinfo); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n查等级失败 稍后重试"); } else if (qqlevel < 16) { MainHolder.api.doGroupEnterReq(e.json, false, "您的等级低于16(☀),根据规定不能加入。"); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n等级过低(" + qqlevel + "),拒绝"); } else if (!(hang_req)) { MainHolder.api.doGroupEnterReq(e.json, true); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "申请加入" + DataBase.me.getGroupName(e.throughgroup.id) + "\n" + "√ 答案正确\n" + "√ 没有重复加群\n" + "√ 等级足够:" + qqlevel + "\n" + "√ 没有黑名单限制项目\n" + "通过"); } else { GroupEntranceInfo geinfo = new GroupEntranceInfo() { json = e.json, qq = e.user, group = e.throughgroup }; reqs.Add(e.user.qq, geinfo); MainHolder.broadcaster.broadcastToAdminGroup(e.user.name + "#" + e.user.qq + "\n请求挂起(C)"); } } try { } catch (Exception err) { MainHolder.broadcaster.broadcastToAdminGroup("[Exception]\n这条消息可能意味着机器人发生了错误。它仍在继续运行,但可能不是很稳定。下面的信息用来帮助鸡蛋定位错误,管理不必在意。\n[申请入群处理]" + err.Message + "\n\n堆栈跟踪:\n" + err.StackTrace); } }
public void checkAndProcessReqQueue() { if (reqs.Count < 1) { return; } DateTime start = DateTime.Now; MainHolder.broadcaster.broadcastToAdminGroup("[队列DEBUG]\n长度=" + reqs.Count); Dictionary <long, GroupEntranceInfo> fails = new Dictionary <long, GroupEntranceInfo>(); string log = ""; int pass = 0; int fail = 0; foreach (KeyValuePair <long, GroupEntranceInfo> d in reqs) { if (d.Value == null) { continue; } IGroupInfo g = getGroupInfo(d.Value.group.Id); IGroupConfig gc = getGroupConf(d.Value.group.Id); int countmember = memberCountGroup(d.Value.group.Id); if (g != null) { bool success = true; int maxmember = groupMaxMember; long q = d.Value.qq.qq; QBaseInfo qi = d.Value.qq; int trusted = DataBase.me.isUserTrusted(q); //QQ q = MainHolder.session.get; if (DataBase.me.isUserOperator(q)) { MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Allow); log += qi.nickname + "-> 是管理员 √\n"; pass++; } else if (trusted >= 0) { long opid = DataBase.me.getUserTrustOperator(q); MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Allow); if (trusted == 1) { DataBase.me.removeUserTrustlist(q); log += qi.nickname + " -> 信任一次 [ATUSER(" + opid + ")] √\n"; } else { log += qi.nickname + " -> 永久信任 [ATUSER(" + opid + ")] √\n"; } pass++; } else if (memberCountGroup(g.Id) >= maxmember - 10) { long gpid = getLeastMemberGroup(); MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Deny, "该群成员已达上限,请加入" + gpid); log += qi.nickname + " -> 群满 ×\n"; fail++; } else if (DataBase.me.isUserBlacklisted(q) && DataBase.me.connected)//已被拉黑 { MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Deny, "您在LUYE通用黑名单中,不允许加群。"); log += qi.nickname + " -> 已被拉黑 ×\n"; fail++; } else if (DataBase.me.whichGroupsAreTheUserIn(q).Count > 0 && DataBase.me.connected) {//重复加群 if (!DataBase.me.isMEIgnoreGroup(g.Id)) { MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Deny, "您加入了其它鹿野群"); log += qi.nickname + " -> 重复加群 ×\n"; fail++; } else { MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Allow); log += qi.nickname + " -> 不查重 √\n"; pass++; } } else { int level = ThirdPartAPIs.getQQLevel(q, 3); if (level < 0) { log += qi.nickname + " -> 等级验证失败 E\n"; fails.Add(d.Key, d.Value); } else if (level < 16) { MainHolder.session.HandleGroupApplyAsync(d.Value.igpargs, GroupApplyActions.Deny, "您的QQ等级(" + level + ")低于设定值(16)"); log += qi.nickname + " -> 等级过低 ×\n"; fail++; } else { log += qi.nickname + " -> 符合要求 √\n"; pass++; } } } } MainHolder.broadcaster.broadcastToAdminGroup("[延迟通过队列处理结果]\n" + log + "--------------\n" + pass + "通过," + fail + "拒绝," + fails.Count() + "错误\n\n处理耗时" + (DateTime.Now - start).TotalSeconds + "s"); reqs.Clear(); reqs = fails; }
public static void BoundQQ(long qq, PrivMessageSession session, PrivMessage pm, bool force = false) { if (DataBase.me.isUserBlacklisted(qq)) { session.sendMessage("[自动回复] 您不能使用该QQ号,因为它存在严重违规记录,已被禁止加群。\n如需帮助,请联系鸡蛋(QQ1250542735)"); MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + " 尝试绑定黑名单中的账号:" + qq); } else { int qqlevel = ThirdPartAPIs.getQQLevel(qq, 2); if (qqlevel < 0) { session.sendMessage("[自动回复] 该账号不存在或查询失败,请稍后重试。\n如需帮助,请联系鸡蛋(QQ1250542735)"); MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + " QQ号无效或查询失败:" + qq); return; } else if (qqlevel < 16) { session.sendMessage("[自动回复] 您不能使用该QQ号,因为它没有达到等级要求(" + qqlevel + "<16)\n如需帮助,请联系鸡蛋(QQ1250542735)"); MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + " 尝试绑定等级过低的账号(" + qqlevel + "<16):" + qq); return; } } if (DataBase.me.isBiliPending(pm.talker.uid))//等待绑定QQ { if (DataBase.me.boundBiliWithQQ(pm.talker.uid, qq)) { MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + " 绑定了TA的QQ号:" + qq); session.sendMessage("[自动回复] 好的,请扫描下方二维码入群。(转发无效)\n" + "如果您的QQ号输入错误,可随时重新发送新的QQ号,我会为您换绑。\n" + "如需帮助,请联系鸡蛋(QQ1250542735)"); session.SendImage(QunQRCode); } else { session.sendMessage("[自动回复] 系统故障,请稍后重试或联系管理员(鸡蛋QQ1250542735)"); MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + "绑定TA的QQ号:" + qq + "\n失败:似乎无法操作数据库。"); } } else { var cgroups = DataBase.me.getCrewGroup(); var oldqq = DataBase.me.getUserBoundedQQ(pm.talker.uid); var usergroup = DataBase.me.whichGroupsAreTheUserIn(oldqq, false); if ((!force) && Collides(cgroups, usergroup, out List <long> _)) { MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + "重新绑定QQ(" + oldqq + "=>" + qq + ")\n拒绝,因为原QQ已经在舰长群中"); session.sendMessage("[自动回复] 您不能换绑QQ,因为您原先绑定的QQ(" + oldqq + ")已经在舰长群中了。如果需要换绑QQ,请先将原QQ退出舰长群。\n" + "如果强行换绑,系统将会踢出原先的QQ。需强行换绑请发送:\n" + "F" + qq); } else { if (DataBase.me.boundBiliWithQQ(pm.talker.uid, qq)) { MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + "重新绑定QQ(" + oldqq + "=>" + qq + ")\n已更新数据库"); session.sendMessage("[自动回复] 您已成功换绑QQ。原先的QQ号(" + oldqq + ")将被解绑,请使用新绑定的QQ号加入舰长群。"); } else { session.sendMessage("[自动回复] 系统故障,请稍后重试或联系管理员(鸡蛋QQ1250542735)"); MainHolder.broadcaster.BroadcastToAdminGroup(pm.talker.name + "重新绑定QQ(" + oldqq + "=>" + qq + ")\n" + "该操作由于一个系统错误未能完成。"); } } } }