Exemplo n.º 1
0
        public async Task Run(CommandArgs args)
        {
            MessageStatistic data = Configuration.GetConfig <MessageStatistic>();

            if (!await args.Source.HasPermission("management.query"))
            {
                string[] splits = args.Arg.Trim().Split(' ');
                if (splits.Length > 0)
                {
                    switch (splits[0])
                    {
                    case "reset":
                        lock (data.t)
                            data.t = new Dictionary <long, Dictionary <long, int> >();
                        data.Save();
                        await args.Callback("Record has been reset successfully.");

                        return;

                    case "set":
                        long gr  = splits[1] == "~" ? args.Source.FromGroup : long.Parse(splits[1]);
                        long qq  = splits[1] == "~" ? args.Source.FromQQ : long.Parse(splits[2]);
                        int  val = int.Parse(splits[3]);
                        if (gr > 0 && qq > 0)
                        {
                            lock (data.t)
                                data.t[gr][qq] = val;
                            data.Save();
                            await args.Callback($"data changed [{gr},{qq}] => {val}.");
                        }
                        else
                        {
                            await args.Callback("Invalid argument.");
                        }
                        return;
                    }
                }
            }
            string arg   = args.Arg.Trim();
            long   group = 0L;

            if (string.IsNullOrEmpty(arg))
            {
                group = args.Source.FromGroup;
            }
            else
            {
                long.TryParse(arg, out group);
            }
            if (group == 0L)
            {
                await args.Callback("Invalid group number specified");

                return;
            }
            List <Tuple <long, int> > sort;

            lock (data.t)
            {
                if (!data.t.ContainsKey(group))
                {
                    args.Callback($"No record from the group {group} till now.");
                    return;
                }

                sort = new List <Tuple <long, int> >();

                foreach (KeyValuePair <long, int> num in data.t[group])
                {
                    sort.Add(new Tuple <long, int>(num.Key, num.Value));
                }
            }

            sort.Sort(delegate(Tuple <long, int> var1, Tuple <long, int> var2)
            {
                return(var2.Item2 - var1.Item2);
            });

            string result = "";

            try
            {
                for (int i = 0; i < 10; ++i)
                {
                    result += $"{i + 1}.{await args.Source.Session.GetName(group, sort[i].Item1)} {sort[i].Item2}pcs\n";
                }
            }
            catch (ArgumentOutOfRangeException) { }

            await args.Callback(result);
        }
Exemplo n.º 2
0
 public static void Main(CommandArgs args)
 {
     args.Callback("注册 [用户名] [密码]");
 }
Exemplo n.º 3
0
 protected abstract TimeSpan DoRun(CommandArgs args);
Exemplo n.º 4
0
 public static void Main(CommandArgs args, string cmd)
 {
     args.Callback(string.Join("\n", Configuration.GetConfig <ServerManager>().GetServer(args)
                               .RunCommand(cmd.Replace("\\", " "))["response"].Select(s => s.ToString())));
 }
Exemplo n.º 5
0
 public static void Main(CommandArgs args, long qq)
 {
     //args.Source.Session.SetGroupBanSpeak(args.Source.FromGroup, qq, new TimeSpan(0, 0, new Random().Next(3600 * 24 * 30)));
 }
Exemplo n.º 6
0
        public void Run(CommandArgs args)
        {
            string[] splits = args.Arg.Trim().Split(' ');
            if (splits.Length < 1)
            {
                args.Callback("/find <refresh/count/id> ...");
                return;
            }
            switch (splits[0])
            {
            case "refresh":
                if (!args.IsAdmin)
                {
                    args.Callback("Access denied!");
                    return;
                }
                infos.Clear();
                args.Callback($"refreshing...please wait.");
                foreach (var group in (groups = args.Source.Session.GetGroupList()))
                {
                    foreach (var member in args.Source.Session.GetMemberList(group.Id) ?? new List <GroupMemberInfo>())
                    {
                        infos.Add(member);
                    }
                }
                var idhash    = new HashSet <long>(groups.Select((group) => group.Id));
                var groupfile = Path.Combine("groups.json");
                if (File.Exists(groupfile))
                {
                    try
                    {
                        args.Callback("reading from groups.json...");
                        var json = JArray.Parse(File.ReadAllText(groupfile));
                        foreach (JObject group in json)
                        {
                            GroupInfo info = new GroupInfo
                            {
                                Id   = (long)group["id"],
                                Name = (string)group["name"]
                            };
                            if (!idhash.Contains(info.Id))
                            {
                                groups.Add(info);
                                idhash.Add(info.Id);
                            }
                            foreach (JObject member in group["members"])
                            {
                                infos.Add(new GroupMemberInfo
                                {
                                    QQId       = (long)member["qq"],
                                    PermitType = (PermitType)Enum.Parse(typeof(PermitType), (string)member["position"]),
                                    GroupId    = info.Id
                                });
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        args.Callback(e.ToString());
                    }
                }
                args.Callback($"Member info has refreshed succussfully. ({infos.Count} records in {groups.Count} groups)");
                break;

            case "count":
                var      users = new HashSet <long>();
                DateTime active;
                try
                {
                    active = DateTime.Parse(splits[1]);
                }
                catch
                {
                    active = new DateTime(0);
                }
                foreach (var member in infos)
                {
                    users.Add(member.QQId);
                }
                args.Callback(@$ "{
                        new HashSet<long>(infos
                            .Select((info) => info.QQId)).Count
                        } members in total {(active.Ticks == 0 ? " " : " is active after " + active.ToString())} (counting in {groups.Count} groups).");
                break;
Exemplo n.º 7
0
 public override async Task Run(CommandArgs args)
 {
     await base.Run(args);
 }
Exemplo n.º 8
0
 public void Run(CommandArgs args)
 {
     args.Callback(PCRManager.Instance.GetRankStatistic(int.Parse(args.Arg.Trim())));
 }
Exemplo n.º 9
0
 protected override void Run(CommandArgs args)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
        public async Task Run(CommandArgs args)
        {
            var track = await Utils.GetHttp($"https://bitbucket.org/sekai-world/sekai-event-track/raw/main/event{MasterData.Instance.events.Last().id}.json");

            await args.Callback(string.Join('\n', new int[] { 100, 500, 1000, 2000, 5000, 10000, 50000 }.Select(i => $"rank{i} pt={track[$"rank{i}"].Single()["score"]}")));
        }
Exemplo n.º 11
0
        public void Run(CommandArgs args)
        {
            if (!string.IsNullOrEmpty(args.Arg))
            {
                return;
            }
            var js       = Utils.GetHttpContent("https://static.biligame.com/pcr/gw/calendar.js");
            var start    = js.IndexOf("var data = ") + 11;
            var end      = js.IndexOf("window.__calendar = data;");
            var json     = JArray.Parse(js.Substring(start, end - start));
            var now      = DateTime.Now.AddHours(-5);
            var alist    = new List <string>();
            var datelist = new Dictionary <string, HashSet <int> >();

            //analyze
            int i;

            for (i = 0; i < 21; ++i)
            {
                var date = now.AddDays(i);
                var data = json.SingleOrDefault(token =>
                                                int.Parse(token.Value <string>("year")) == date.Year &&
                                                int.Parse(token.Value <string>("month")) == date.Month)
                           ?.Value <JObject>("day")
                           ?.Value <JObject>(date.Day.ToString());

                if (data == null)
                {
                    break;
                }

                var set = new HashSet <int>();
                foreach (var prop in data.Properties())
                {
                    var regex2 = new Regex("<div class='cl-t'>(.*?)</div><div class='cl-d'>(.*?)</div>");

                    foreach (Match match in regex2.Matches(prop.Value.Value <string>()))
                    {
                        var val = $"{match.Groups[1].Value}";
                        var id  = alist.IndexOf(val);

                        if (id == -1)
                        {
                            id = alist.Count;
                            alist.Add(val);
                        }

                        set.Add(id);
                    }
                }

                datelist.Add(date.ToShortDateString(), set);
            }

            //draw
            //border 10px, color 20px, date 80x, desc 200px

            const int wborder = 10, wsquare = 20, wdesc = 200, wdate = 80;
            var       width  = wborder + wdate + wsquare * alist.Count + wborder + wsquare + wdesc + wborder;
            var       height = wborder + Math.Max(datelist.Count * wsquare, alist.Count * wsquare) + wborder;
            var       font   = new Font(FontFamily.GenericMonospace, 8);

            var img    = new Bitmap(width, height);
            var canvas = Graphics.FromImage(img);

            canvas.Clear(Color.White);

            //col lines and alist descriptions
            int m = alist.Count, n = datelist.Count;
            var descStart = wborder + wdate + wsquare * alist.Count + wborder;

            i = 0;
            foreach (var pair in datelist)
            {
                canvas.DrawString(pair.Key, font, Brushes.Black, wborder, wborder + i * wsquare + 6);

                foreach (var id in pair.Value)
                {
                    canvas.FillRectangle(new SolidBrush(ColorHue(id)), new Rectangle(wborder + wdate + wsquare * id, wborder + i * wsquare, wsquare, wsquare));
                }

                canvas.DrawLine(Pens.Black, wborder, wborder + i * wsquare, wborder + wdate + m * wsquare, wborder + i * wsquare);
                ++i;
            }
            canvas.DrawLine(Pens.Black, wborder, wborder + i * wsquare, wborder + wdate + m * wsquare, wborder + i * wsquare);

            canvas.DrawLine(Pens.Black, wborder, wborder, wborder, wborder + n * wsquare);
            for (i = 0; i < m; ++i)
            {
                canvas.FillRectangle(new SolidBrush(ColorHue(i)), new Rectangle(descStart, wborder + i * wsquare, wsquare, wsquare));
                canvas.DrawRectangle(Pens.Black, new Rectangle(descStart, wborder + i * wsquare, wsquare, wsquare));
                canvas.DrawString(alist[i], font, Brushes.Black, descStart + wsquare, wborder + i * wsquare + 6);
                canvas.DrawLine(Pens.Black, wborder + wdate + i * wsquare, wborder, wborder + wdate + i * wsquare, wborder + n * wsquare);
            }
            canvas.DrawLine(Pens.Black, wborder + wdate + i * wsquare, wborder, wborder + wdate + i * wsquare, wborder + n * wsquare);


            canvas.Dispose();

            args.Callback(Utils.GetImageCode(img));

            img.Dispose();
        }
Exemplo n.º 12
0
 protected abstract void Run(CommandArgs args);
Exemplo n.º 13
0
        protected override void Run(CommandArgs args)
        {
            string[] splits = args.Arg.Trim().Split(' ');
            if (string.IsNullOrWhiteSpace(args.Arg.Trim()))
            {
                args.Callback("/reply <add/del/list>[1234] ...\n1 is string comparision\n2 is regex match\n3 is regex match without at(requires admin).\n4 is c# code");
                return;
            }

            var config = Configuration.GetConfig <ReplyHandler>();
            var qq     = args.Source.FromQQ;

            switch (splits[0])
            {
            case "save":
                if (args.IsAdmin)
                {
                    config.Save();
                    args.Callback("configuration has been saved successfully.");
                }
                break;

            case "add1":
            case "add2":
            case "add3":
            case "add4":
            {
                if (splits.Length < 3)
                {
                    args.Callback("Invalid argument count.");
                    return;
                }
                switch (splits[0])
                {
                case "add1":

                    break;
                }
                if (splits[0] == "add1" || splits[0] == "add2")
                {
                    try
                    {
                        new Regex($"^{Utils.FixRegex(splits[1])}$");
                    }
                    catch
                    {
                        args.Callback("Invalid regular expression format.");
                        return;
                    }
                }

                var reply = new Reply
                {
                    qq    = qq,
                    reply = string.Concat(splits.Skip(2).Select((s) => s + ' ')).Trim()
                };

                var data = config[int.Parse(splits[0].Substring(3))];

                if ((splits[0] == "add3" || splits[0] == "add4") && !args.IsAdmin)
                {
                    args.Callback("Access denied!");
                    return;
                }

                if (data.TryGetValue(splits[1], out var list))
                {
                    foreach (var rep in list)
                    {
                        if (rep.reply == reply.reply)
                        {
                            args.Callback($"`{splits[1]}` => `{reply.reply}` already exists!");
                            return;
                        }
                    }
                    list.Add(reply);
                }
                else
                {
                    data.Add(splits[1], new List <Reply> {
                            reply
                        });
                }

                if (splits[0] == "add4")
                {
                    try
                    {
                        config.ReloadAssembly();
                    }
                    catch (Exception e)
                    {
                        args.Callback(e.ToString());
                        try
                        {
                            config.Load();
                        }
                        catch
                        {
                            config.LoadDefault();
                        }
                        break;
                    }
                }

                config.Save();
                args.Callback($"successfully added {(splits[0] == "add" ? "" : "regular expression")}`{splits[1]}` => `{reply.reply}`");

                break;
            }

            case "del1":
            case "del2":
            case "del3":
            case "del4":
            {
                if (splits.Length < 3)
                {
                    args.Callback("Invalid argument count.");
                    return;
                }

                var data       = config[int.Parse(splits[0].Substring(3))];
                var result     = Utils.TryGetValueStart(data, (pair) => pair.Key, splits[1], out var list);
                var replystart = string.Concat(splits.Skip(2).Select((s) => s + ' ')).Trim();

                if (string.IsNullOrEmpty(result))
                {
                    var result2 = Utils.TryGetValueStart(list.Value, (reply) => reply.reply, replystart, out var reply);
                    if (string.IsNullOrEmpty(result2))
                    {
                        if (reply.qq == qq || args.IsAdmin)
                        {
                            list.Value.Remove(reply);
                            if (list.Value.Count == 0)
                            {
                                data.Remove(list.Key);
                            }
                            config.Save();
                            args.Callback($"successfully removed `{list.Key}` => `{reply.reply}`");
                        }
                        else
                        {
                            args.Callback("Access denied.");
                        }
                    }
                    else
                    {
                        args.Callback(result2);
                    }
                }
                else
                {
                    args.Callback(result);
                }

                break;
            }

            case "list1":
            case "list2":
            case "list3":
            case "list4":
            {
                var data = config[int.Parse(splits[0].Substring(4))];
                if (splits.Length == 1)
                {
                    if (!args.IsAdmin)
                    {
                        args.Callback("Access denied.");
                        return;
                    }
                    args.Callback("All valid replies:\n" + string.Concat(data.Select((pair) => pair.Key + "\n")));
                }
                else if (splits.Length == 2)
                {
                    var result = Utils.TryGetValueStart(data, (pair) => pair.Key, splits[1], out var list);

                    if (string.IsNullOrEmpty(result))
                    {
                        args.Callback($"All valid replies for `{list.Key}`:\n{string.Concat(list.Value.Select((reply) => $"`{reply.reply}` (by {reply.qq})\n"))}");
                    }
                    else
                    {
                        args.Callback(result);
                    }
                }
                else
                {
                    args.Callback("Invalid argument count.");
                }
                break;
            }
            }
        }
Exemplo n.º 14
0
 protected override void Run(CommandArgs args)
 {
     args.Callback(PCRClientTest.PCRManager.Instance.GetRankStatistic(int.Parse(args.Arg.Trim())));
 }
Exemplo n.º 15
0
 public async Task Run(CommandArgs args)
 {
     await args.Callback($"{args.Source.FromGroup}{(args.Source.IsGuild ? $"{MessageHandler.GetGroupCache(args.Source.FromGroup)}" : "")} {args.Source.FromQQ}");
 }
Exemplo n.º 16
0
        public void Run(CommandArgs args)
        {
            string[] splits = args.Arg.Trim().Split(' ');
            if (string.IsNullOrWhiteSpace(args.Arg.Trim()))
            {
                args.Callback("/reply <add/del/list>[1234] ...\n1 is string comparision\n2 is regex match\n3 is regex match without at(requires admin).\n4 is c# code");
                return;
            }

            var config = Configuration.GetConfig <ReplyHandler>();
            var qq     = args.Source.FromQQ;

            switch (splits[0])
            {
            case "reload":
                if (args.IsAdmin)
                {
                    config.Load();
                    args.Callback("configuration has been reloaded successfully.");
                }
                break;

            case "save":
                if (args.IsAdmin)
                {
                    config.Save();
                    args.Callback("configuration has been saved successfully.");
                }
                break;

            case "add2":
            case "add3":
            case "add4":
            {
                if (splits.Length < 3)
                {
                    args.Callback("Invalid argument count.");
                    return;
                }

                try
                {
                    new Regex($"^{Utils.FixRegex(splits[1])}$");
                }
                catch
                {
                    args.Callback("Invalid regular expression format.");
                    return;
                }

                var reply = new Reply
                {
                    qq    = qq,
                    reply = string.Concat(splits.Skip(2).Select((s) => s + ' ')).Trim()
                };

                var data = config[int.Parse(splits[0].Substring(3))];

                if (splits[0] == "add4" && !args.IsAdmin)
                {
                    args.Callback("Access denied!");
                    return;
                }

                var t = data.SingleOrDefault(data => data.Item1.ToString()[1..^ 1] == splits[1]);