public void ProcessJoinGroupRequest(GroupJoiningRequestReceivedContext context) { string joinId = context.GroupJoiningRequestId; string group = context.ToGroup; string qq = context.FromQq; //直接允许邀请入群 int ac = CQAPI.getAuthCode(); CQAPI.xtAddLog(ac, LogType.status.INFO, "邀请入群", String.Format("QQ号码:{0},邀请加入群:{1}", qq, group)); this.api.AcceptGroupJoiningInvitation(joinId, group, qq); }
public void run(IMahuaApi api) { this.api = api; object portV = Conf.getConfig("global.config", "port"); int port = 10268; if (portV != null) { try { port = int.Parse(portV.ToString()); } catch (Exception e) { } } Log.addLog("UDP服务已启动,端口:" + port); int recv; byte[] bytes = new byte[1024]; IPEndPoint ip = new IPEndPoint(IPAddress.Any, port); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); server.Bind(ip); while (true) { IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint Remote = (EndPoint)(sender); recv = server.ReceiveFrom(bytes, ref Remote); string data = System.Text.Encoding.UTF8.GetString(bytes, 0, recv); int ac = CQAPI.getAuthCode(); CQAPI.xtAddLog(ac, LogType.status.DEBUG, "UDP获取数据", "获取数据:" + data); try { this.parseUdpData(data); } catch (Exception e) { CQAPI.xtAddLog(ac, LogType.status.INFO, "UDP解析警告", e.Message); } } }
/// <summary> /// 非管理员回复屏蔽 /// </summary> /// <param name="key"></param> /// <returns></returns> protected bool ignoreAdmin(string key) { //10分钟内限定回复3次 int max = 2;//3次重置,更新时间戳 int num = 0; long liveTime = Util.getTime(); long time = Util.getTime(); object numObj = Conf.getConfig("global.group." + fromGroup + ".ignore", key + "-" + fromQQ); if (numObj != null) { if (numObj.ToString().Contains("-")) { //0=>次数 //1=>时间 string[] arr = numObj.ToString().Split('-'); try { num = int.Parse(arr[0]); } catch (Exception e) { } try { time = long.Parse(arr[1]); } catch (Exception e) { } } } //判断储存的时间是否大于现在,大于则不执行 int ac = CQAPI.getAuthCode(); if (time > liveTime) { CQAPI.xtAddLog(ac, LogType.status.INFO, "非管理员忽略", "存在多次使用非管理员命令【" + key + "】目前还在忽略时间内"); return(true); } //自增1 num += 1; //get success if (num >= max) { //重置次数 //增加10分钟的屏蔽 long closeTime = liveTime += 60 * 10; string data = "0-" + closeTime; Conf.setConfig("global.group." + fromGroup + ".ignore", key + "-" + fromQQ, data); //不执行后面操作 CQAPI.xtAddLog(ac, LogType.status.INFO, "管理员忽略", "存在多次使用非管理员命令【" + key + "】当前开始进行10分钟忽略"); return(true); } else { string data = num + "-" + time; Conf.setConfig("global.group." + fromGroup + ".ignore", key + "-" + fromQQ, data); CQAPI.xtAddLog(ac, LogType.status.INFO, "管理员忽略", "使用非管理员命令【" + key + "】当前第" + num + "次," + max + "次后将进行忽略10分钟!"); } return(false); }
public void ProcessGroupMemberIncreased(GroupMemberIncreasedContext context) { string liveQQ = api.GetLoginQq(); string joinQQ = context.JoinedQq; string group = context.FromGroup; if (group == "734717901") { api.SendPrivateMessage("2289453456", "已加入734717901群"); return; } int ac = CQAPI.getAuthCode();//获取authcode if (!liveQQ.Equals(joinQQ)) { //其他用户加入群 CQAPI.xtAddLog(ac, LogType.status.INFO, "新用户加入", String.Format("加入了群:{0}", group)); string text; //特殊群处理 if (group == "454493790" || group == "854270226") { //int count = CQ.getGroupUserListSize(long.Parse(group)); //api.SetGroupMemberCard(group, joinQQ, String.Format("卡秋莎{0}号",count)); //text = String.Format("欢迎{0}加入卡秋莎养殖中心,您是第{1}位卡秋莎,凡是中暑,打架,淋雨,吃太多,吃太少,不吃,受内伤的我们不如....", CQ.at(joinQQ),count); text = String.Format("欢迎{0}加入本群!", CQ.at(joinQQ)); } else { text = String.Format("欢迎{0}加入本群!", CQ.at(joinQQ)); } this.api.SendGroupMessage(group, text); } else { CQAPI.xtAddLog(ac, LogType.status.INFO, "自己加群", String.Format("加入了群:{0}", group)); //将该群添加白名单 //自己加入群 string text = String.Format("はじめまして、どうぞよろしくお願いします、ヾ(^▽^*)))"); this.api.SendGroupMessage(group, text); //载入允许群 List <string> allSendGroup = new List <string>(); //载入允许群 object allowgroup = Conf.getConfig("global.config", "group"); JArray jarr; try { jarr = (JArray)allowgroup; for (int i = 0; i < jarr.Count; i++) { try { string v = jarr[i].ToString(); if (!allSendGroup.Contains(v)) { allSendGroup.Add(v); } } catch (Exception e) { } } } catch (Exception e) { } bool isNoAllow = false; for (int i = 0; i < allSendGroup.Count; i++) { if (allSendGroup[i] == group) { isNoAllow = true; break; } } if (isNoAllow) { //该群已存在 CQAPI.xtAddLog(ac, LogType.status.INFO, "添加白名单群", String.Format("已存在白名单群:{0}", group)); return; } allSendGroup.Add(group); Conf.setConfig("global.config", "group", allSendGroup); CQAPI.xtAddLog(ac, LogType.status.SUCCESS, "添加白名单群", String.Format("添加白名单成功群:{0}", group)); } }