From 0f74715cd03f7bfe39facc6b67ad1b2a69e30f73 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Sun, 27 Apr 2025 20:26:54 +0800 Subject: =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=8F=90=E9=86=92=E9=98=9F=E5=88=97?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/Main.hs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9f98736..72eec46 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tgtoken release/ dist-newstyle/ .stack-work/ +deploy.sh diff --git a/app/Main.hs b/app/Main.hs index cccf14a..a4e15ef 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -76,7 +76,7 @@ handleAction :: Action -> Model -> Eff Action Model handleAction action model = case action of TextMsg tmsg cid mid -> case (words $ Text.unpack tmsg) of (command:args) -> - case command of + case (takeWhile (/='@') command) of "/timer" -> handleTimerCmd model cid mid args _ -> return model [] -> return model @@ -99,16 +99,25 @@ fireEvents model ts = Eff $ do handleTimerCmd :: Model -> ChatId -> MessageId -> [String] -> Eff Action Model handleTimerCmd model chatId mid args = - let minutes :: Maybe Int = readMaybe $ intercalate " " args in + let minutes :: Maybe Integer = readMaybe $ intercalate " " args in case minutes of Nothing -> replyTextEff model chatId mid "格式:/timer <分钟数>" Just num -> Eff $ do - let acts = do + let validNumAction = do replyToMessage chatId mid $ Text.pack $ "已设置" ++ (show num) ++ "分钟提醒" curTime <- liftIO $ currentTimestamp return $ Just $ AddEvent $ Event (curTime + (toInteger num) * 60) chatId mid - tell [acts] + let invalidNumAction = do + replyToMessage chatId mid $ Text.pack $ "只能设置一天内的提醒" + return Nothing + let queueFullAction = do + replyToMessage chatId mid $ Text.pack $ "提醒队列已满" + return Nothing + if num > 1440 then tell [invalidNumAction] + else + if (length model) > 4096 then tell [queueFullAction] + else tell [validNumAction] return model run :: Token -> IO () -- cgit v1.0