public static void RevokeHPicture(this MiraiHttpSession message, int messageId, int delay)
 {
     if (delay > 0)
     {
         Task.Delay(delay * 1000).Wait();
         message.RevokeMessageAsync(messageId);
     }
 }
Example #2
0
        public static async Task Run(MiraiHttpSession session, long groupNum)
        {
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("Unit Test successfully launched.")));
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("1. PlainTextTest")));
            var sw = new Stopwatch();

            for (int i = 0; i < 3; i++)
            {
                //start timing here
                sw.Start();
                ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("hello world")));
                //end timing here
                sw.Stop();
                ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage($"Success. time consumed : {sw.ElapsedMilliseconds}ms")));
                //reset timing here
                sw.Reset();
            }

            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("2. ImageTest")));
            sw.Start();
            //send a image
            ids.Add(await session.SendGroupMessageAsync(groupNum, new ImageMessage(null,
                                                                                   url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3581134888,2217954696&fm=26&gp=0.jpg", null)));
            sw.Stop();
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage($"Success. time consumed : {sw.ElapsedMilliseconds}ms")));
            sw.Reset();

            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("3. MessageChainTest")));
            sw.Start();
            ids.Add(
                await session.SendGroupMessageAsync(groupNum, new IMessageBase[] {
                new PlainMessage("hello world"),
                new ImageMessage(null,
                                 url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3581134888,2217954696&fm=26&gp=0.jpg",
                                 null)
            })     //SendGpMsgAsync, array
                ); //ids.Add
            sw.Stop();
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage($"Success. time consumed : {sw.ElapsedMilliseconds}ms")));
            sw.Reset();

            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("4. RevokeTest")));
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("all test messages will be revoked in 1 minutes.")));
            Thread.Sleep(TimeSpan.FromMinutes(1));
            sw.Start();
            foreach (var id in ids)
            {
                await session.RevokeMessageAsync(id);
            }
            sw.Stop();
            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage($"Success. time consumed : {sw.ElapsedMilliseconds}ms")));
            sw.Reset();

            ids.Add(await session.SendGroupMessageAsync(groupNum, new PlainMessage("Unit test done.")));
        }
Example #3
0
        public async Task <bool> GroupMessage(MiraiHttpSession session, IGroupMessageEventArgs e) // 法2: 使用 params IMessageBase[]
        {
            if (e.Chain[1].Type == "Image")
            {
                var source = (SourceMessage)e.Chain[0];
                await session.RevokeMessageAsync(source.Id);

                return(true);
            }
            var replyMsg = await GroupMessageHandler(e);

            if (replyMsg == null || replyMsg.Message == string.Empty)
            {
                return(true);
            }

            await session.SendGroupMessageAsync(e.Sender.Group.Id, new AtMessage(e.Sender.Id), replyMsg /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息

            return(false);                                                                                                         // 不阻断消息传递。如需阻断请返回true
        }
Example #4
0
        public static async Task Run(CommandParser.Config args, MiraiHttpSession session, IGroupMessageEventArgs e)
        {
            if (args.ConfigInGroup == false)
            {
                await session.SendGroupMessageAsync(e.Sender.Group.Id,
                                                    new PlainMessage("警告:未提供命令参数-g的情况下在群内试图配置用户信息。\n" +
                                                                     "为保证账号安全,停止了此操作并尝试撤回了信息。"));

                await session.RevokeMessageAsync(((SourceMessage)e.Chain[0]).Id);

                return;
            }
            await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("正在保存..."));

            var user = new User(e.Sender.Id)
            {
                Username = args.Username, Password = args.Password
            };
            bool ok = await user.TrySave();

            await session.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage(ok ? "成功更改了配置。" : "抱歉,遇到了错误,请稍后再试。"));
        }
Example #5
0
 public static Task RevokeMessageAsync(int messageID)
 => session.RevokeMessageAsync(messageID);