Beispiel #1
0
            static void Main(string[] args)
            {
                CQJson j = new CQJson(1, "nnnn", "1.0.0", "tatamis", "yijuhua");

                j.auth.Add(1);
                j.auth.Add(2);
                j.auth.Add(3);
                j.auth.Add(4);
                j.auth.Add(5);

                j._event.Add(new CQevent(1, 1001, "mmm", "fun1", 30000));
                j._event.Add(new CQevent(2, 1002, "mmm", "fun2", 30000));

                CQregex r = new CQregex();

                r.key.Add("Account");
                r.key.Add("action");
                r.expression.Add("^(?<action>\\S{1,4}?)\\s*(?<Account>\\d{5,10})\\s*?$");

                j._event[1].regex = r;

                j.menu.Add(new CQmenu("menu1", "fun5"));
                j.menu.Add(new CQmenu("menu2", "fun6"));

                string output = JsonConvert.SerializeObject(j);


                Console.WriteLine("预览:");
                Console.WriteLine(output);
                Console.ReadLine();
            }
Beispiel #2
0
 public CQevent(int id, int type, string name, string function, int priority, CQregex regex)
 {
     this.id       = id;
     this.type     = type;
     this.name     = name;
     this.function = function;
     this.priority = priority;
     this.regex    = regex;
 }
Beispiel #3
0
        private static void addEVE(int Type)
        {
            var function = 取文本中间(line, "(", ")");
            var name     = function;
            var priority = 30000;
            var reg      = new CQregex();
            var msg      = false;

            switch (Type)
            {
            case 2:
            case 4:
            case 21:
                msg = true; break;
            }
            var max = 20;

            for (var end = linePos + max; linePos < end; linePos++)
            //while ( --max > 0)
            {
                line = lines[linePos];
                var s1 = line.IndexOf("//");
                var s2 = line.IndexOf("{");

                //判断大括号和双斜杠
                if (s1 != 0)//双斜杠开头,正常继续
                {
                    if (s1 > 0)
                    {
                        if (0 <= s2 && s2 < s1)
                        {
                            break;
                        }
                    }                                             //大括号在双斜杠前面,结束判断
                    else if (s2 >= 0)
                    {
                        break;              //存在大括号,结束判断
                    }
                }

                if (line.StartsWith("//name:"))
                {
                    name = line.Substring("//name:".Length);
                    //Console.WriteLine(function + ":" + name);
                }
                else if (line.StartsWith("//priority:"))
                {
                    try { priority = int.Parse(line.Substring("//priority:".Length)); } catch (Exception) { }
                }
                else if (msg)
                {
                    if (line.StartsWith("//regex-key:"))
                    {
                        var key = line.Substring("//regex-key:".Length);
                        reg.key.Add(key);
                        //Console.WriteLine("发现正则key:"+ key);
                    }
                    else if (line.StartsWith("//regex-expression:"))
                    {
                        var expression = line.Substring("//regex-expression:".Length);
                        reg.expression.Add(expression);
                        //Console.WriteLine("发现正则expression:" + expression);
                    }
                }
            }
            if (reg.expression.Count == 0)
            {
                app._event.Add(new CQevent(id: EveId++, type: Type, name: name, function: function, priority: priority));
                if (reg.key.Count != 0)
                {
                    Console.WriteLine("[提示]空正则KEY,将被忽略,事件函数名为: " + function);
                }
            }
            else
            {
                app._event.Add(new CQevent(id: EveId++, type: Type, name: name, function: function, priority: priority, regex: reg));
                //Console.WriteLine("合入正则");
            }
        }