Skip to content

Commit 6c5ef63

Browse files
committed
Implement command for configuring NoTrust messages
1 parent 2fdc90b commit 6c5ef63

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/Bot.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ builtinCommands =
480480
[ ( "help"
481481
, subcommand
482482
[("setgist", setHelpGistId), ("refresh", refreshHelpGistId)])
483+
, ( "reply"
484+
, subcommand
485+
[ ("link", setNoTrustLinkReplyCommand)
486+
, ("command", setNoTrustCommandReplyCommand)
487+
])
483488
]))
484489
, ( "version"
485490
, mkBuiltinCommand

src/Bot/Replies.hs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Entity
1818
import Data.Proxy
1919
import Property
2020
import Data.Maybe
21+
import Data.Functor
2122

2223
sayMessage :: Reaction Message T.Text
2324
sayMessage =
@@ -96,6 +97,12 @@ data NoTrustReply = NoTrustReply
9697
, noTrustLinkReply :: T.Text
9798
} deriving (Eq)
9899

100+
updateNoTrustCommandReply :: T.Text -> NoTrustReply -> NoTrustReply
101+
updateNoTrustCommandReply value reply = reply {noTrustCommandReply = value}
102+
103+
updateNoTrustLinkReply :: T.Text -> NoTrustReply -> NoTrustReply
104+
updateNoTrustLinkReply value reply = reply {noTrustLinkReply = value}
105+
99106
instance IsEntity NoTrustReply where
100107
nameOfEntity Proxy = "NoTrustReply"
101108
toProperties reply =
@@ -107,6 +114,23 @@ instance IsEntity NoTrustReply where
107114
NoTrustReply <$> extractProperty "command" properties <*>
108115
extractProperty "link" properties
109116

117+
setNoTrustLinkReplyCommand :: Reaction Message T.Text
118+
setNoTrustLinkReplyCommand =
119+
liftR
120+
(\msg -> do
121+
reply <- noTrustReply
122+
void $ updateEntityById $ fmap (updateNoTrustLinkReply msg) reply) $
123+
cmapR (const "Updated not trust link reply message") $ Reaction replyMessage
124+
125+
setNoTrustCommandReplyCommand :: Reaction Message T.Text
126+
setNoTrustCommandReplyCommand =
127+
liftR
128+
(\msg -> do
129+
reply <- noTrustReply
130+
void $ updateEntityById $ fmap (updateNoTrustCommandReply msg) reply) $
131+
cmapR (const "Updated not trust command reply message") $
132+
Reaction replyMessage
133+
110134
noTrustReply :: Effect (Entity NoTrustReply)
111135
noTrustReply = do
112136
reply <- listToMaybe <$> selectEntities Proxy (Take 1 $ All)
@@ -116,9 +140,11 @@ noTrustReply = do
116140
createEntity Proxy $
117141
NoTrustReply
118142
[qms|You have to be trusted to use this command.
119-
Mods can change this message with !TODO|]
143+
Mods can change this message with
144+
!config reply command <message>|]
120145
[qms|You have to be trusted to send links.
121-
Mods can change this message with !TODO|]
146+
Mods can change this message with
147+
!config reply link <message>|]
122148

123149
noTrust :: Message a -> Effect ()
124150
noTrust Message {messageSender = sender} = do

0 commit comments

Comments
 (0)