aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-27 20:26:54 +0800
committerMistivia <i@mistivia.com>2025-04-27 20:34:13 +0800
commit0f74715cd03f7bfe39facc6b67ad1b2a69e30f73 (patch)
treecd21dc62c2ba027831ed9e6955cafc93dabbc4a2 /app
parentf7a8f9c56b2eb612a736cc85ad079264e257d5a4 (diff)
检查提醒队列长度上限
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs17
1 files changed, 13 insertions, 4 deletions
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 ()