예제 #1
0
        async Task <bool> ITempMessage.TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
        {
            if (BotInfo.BannedUser.Contains(e.Sender.Id))
            {
                return(false);
            }
            if (BotInfo.DebugMode)
            {
                if (BotInfo.DebugReplyAdminOnly)
                {
                    if (!BotInfo.AdminQQ.Contains(e.Sender.Id))
                    {
                        return(false);
                    }
                }
            }
            if (e.Chain.Length > 1)  //普通消息
            {
                switch (e.Chain[1].Type)
                {
                case "Plain":
                    PlainMessageHandler.HandleFriendMesage(session, e.Chain, e.Sender.Id);
                    break;

                case "Image":
                    for (int i = 1; i < e.Chain.Length; i++)
                    {
                        ImageMessage imgMsg = e.Chain[i] as ImageMessage;
                        await SearchPictureHandler.SearchPicture(imgMsg, picStream => session.UploadPictureAsync(UploadTarget.Group, picStream), msg => session.SendTempMessageAsync(e.Sender.Id, e.Sender.Group.Id, msg));
                    }
                    break;
                }
            }
            return(false);
        }
예제 #2
0
        public async Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
        {
            if (e.Chain.Length != 2 || !(e.Chain[1] is PlainMessage))
            {
                return(false);
            }
            var cmd = ((PlainMessage)e.Chain[1]).Message.Split(' ').Where(s => s != string.Empty).ToArray();

            if (!CalenderBot.Config.CommandStart.Contains(cmd[0]))
            {
                return(false);
            }
            var helpMsg = new StringBuilder();

            using var writer = new StringWriter(helpMsg);
            var parser = new Parser(config => config.HelpWriter = writer);
            await parser.ParseArguments <CommandParser.Default,
                                         CommandParser.Config,
                                         CommandParser.GenerateCalender>(cmd.Skip(1))
            .WithParsedAsync <CommandParser.Config>(async with => await ConfigUser.RunTemp(with, session, e));

            if (helpMsg.Length != 0)
            {
                await session.SendGroupMessageAsync(e.Sender.Group.Id, new IMessageBase[] { new AtMessage(e.Sender.Id), new PlainMessage("\r\n" + helpMsg.ToString()) });
            }
            return(false);
        }
예제 #3
0
        public async Task HandleMessageAsync(IMiraiHttpSession client, ITempMessageEventArgs e)
        {
            MsgReplyTemp r = new MsgReplyTemp()
            {
                fromGroup = e.Sender.Group.Id, qq = e.Sender.Id
            };

            ProcessMessage(r, e.Chain);
            return;
        }
예제 #4
0
 public async Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
 {
     OnMessage(session, Utils.GetCQMessage(e.Chain), new Source
     {
         FromGroup = 0,
         FromQQ    = e.Sender.Id,
         Session   = session,
         IsTemp    = true
     });
     return(false);
 }
예제 #5
0
 public async Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
 {
     foreach (var item in e.Chain)
     {
         if (item.Type.Equals("Plain"))
         {
             string    message   = item.ToString();
             GameInput gameInput = new GameInput(session, message, e.Sender, e.Sender.Group);
             try
             {
                 await GameSelector.DealCommand(gameInput);
             }
             catch (Exception ex)
             {
                 await gameInput.ReplyGroup("命令错误!" + ex.Message);
             }
         }
     }
     return(false);
 }
예제 #6
0
 public Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
 {
     BotCore.OnMessage(new MessageSource(e.Sender.Group.Id, e.Sender.Id, true), new QMessage(e.Chain));
     return(Task.FromResult(true));
 }
예제 #7
0
 public async Task <bool> TempMessage(MiraiHttpSession session, ITempMessageEventArgs e)
 {
     qc.chainReceived(e.Sender, e.Chain, 2);
     return(false);
 }
예제 #8
0
        public static async Task RunTemp(CommandParser.Config args, MiraiHttpSession session, ITempMessageEventArgs e)
        {
            await session.SendGroupMessageAsync(e.Sender.Group.Id, new AtMessage(e.Sender.Id), new PlainMessage("\r\n正在保存..."));

            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 AtMessage(e.Sender.Id), new PlainMessage(ok ? "\r\n成功更改了配置。" : "抱歉,遇到了错误,请稍后再试。"));
        }