示例#1
0
        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);
        }
示例#2
0
 /// <summary>
 /// 初始化数据
 /// </summary>
 /// <param name="command"></param>
 /// <param name="value"></param>
 /// <param name="fromGroup"></param>
 /// <param name="fromQQ"></param>
 /// <param name="rootQQ"></param>
 public void __init(string command, string value, long fromGroup, long fromQQ, List <long> rootQQ, long debugQQ)
 {
     this.api       = MahuaRobotManager.Instance.CreateSession().MahuaApi;
     this.value     = value;
     this.fromGroup = fromGroup;
     this.command   = command;
     this.fromQQ    = fromQQ;
     this.rootQQ    = rootQQ;
     this.debugQQ   = debugQQ;
     this.args      = value.Split(' ');
     CQAPI.xtAddLog(LogType.status.DEBUG, "RUN_MODULE", "执行命令:" + command);
 }
示例#3
0
文件: App.cs 项目: balrogsxt/xtBot
 /// <summary>
 /// 获取Authcode
 /// </summary>
 /// <returns></returns>
 public static int getAuthCode()
 {
     if (App.authCode == 0)
     {
         App.authCode = CQAPI.getCQPAuthCode();
         if (App.authCode != 0)
         {
             Log.addLog("SET_AUTHCODE", "已获取最新AuthCode:" + App.authCode);
         }
     }
     return(App.authCode);
 }
示例#4
0
        /// <summary>
        /// 在当前群发送群消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="isReplace"></param>
        protected void sendMessage(object data, bool isReplace)
        {
            if (Util.checkEmpty(data.ToString()))
            {
                return;
            }
            string message = data.ToString();

            if (isReplace)
            {
                message = CQ.CQString(message);
            }
            CQAPI.xtAddLog(LogType.status.DEBUG, "群聊消息", "[来自" + this.command + "发送的数据]");
            this.api.SendGroupMessage(this.fromGroup.ToString(), message);
        }
示例#5
0
        /// <summary>
        /// 延迟间隔请求过滤
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public bool checkSleep(int s)
        {
            string str = String.Format("{0}-{1}-{2}", this.fromGroup, this.fromQQ, this.command);

            if (yc.ContainsKey(str))
            {
                long ls = yc[str];
                if (ls > Util.getTime())
                {
                    string ss = "命令:" + this.command + "->" + this.fromGroup + "->" + this.fromQQ + "延迟请求,解除剩余时间:" + (ls - Util.getTime()) + "秒";
                    CQAPI.xtAddLog(LogType.status.DEBUG, "频繁忽略", ss);
                    //throw new NoException(ss);
                    //throw new Exception(ss);

                    return(true);
                }
                yc.Remove(str);
            }
            yc.Add(str, Util.getTime() + s);
            return(false);
        }
示例#6
0
        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);
                }
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
        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));
            }
        }