@@ -5,11 +5,16 @@ module Bot.Replies where
55
66import Data.Aeson
77import qualified Data.ByteString.Lazy as BS
8+ import Data.Functor
89import qualified Data.Map as M
10+ import Data.Maybe
11+ import Data.Proxy
912import qualified Data.Text as T
1013import Effect
14+ import Entity
1115import HyperNerd.Comonad
1216import Network.HTTP.Simple (getResponseBody , parseRequest )
17+ import Property
1318import Reaction
1419import Regexp
1520import Text.InterpolatedString.QM
@@ -79,14 +84,73 @@ onlyForRoles reply roles reaction =
7984onlyForMods :: Reaction Message a -> Reaction Message a
8085onlyForMods = onlyForRoles " Only for mods" authorityRoles
8186
82- nonEmptyRoles :: T. Text -> Reaction Message a -> Reaction Message a
83- nonEmptyRoles reply reaction =
87+ nonEmptyRoles :: Reaction Message a -> Reaction Message a
88+ nonEmptyRoles reaction =
8489 transR duplicate $
8590 ifR
8691 (null . senderRoles . messageSender)
87- (cmapR ( const reply) $ Reaction replyMessage )
92+ (Reaction noTrust )
8893 (cmapR extract reaction)
8994
95+ data NoTrustReply = NoTrustReply
96+ { noTrustCommandReply :: T. Text
97+ , noTrustLinkReply :: T. Text
98+ } deriving (Eq )
99+
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+
106+ instance IsEntity NoTrustReply where
107+ nameOfEntity Proxy = " NoTrustReply"
108+ toProperties reply =
109+ M. fromList
110+ [ (" command" , PropertyText $ noTrustCommandReply reply)
111+ , (" link" , PropertyText $ noTrustLinkReply reply)
112+ ]
113+ fromProperties properties =
114+ NoTrustReply <$> extractProperty " command" properties <*>
115+ extractProperty " link" properties
116+
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+
134+ noTrustReply :: Effect (Entity NoTrustReply )
135+ noTrustReply = do
136+ reply <- listToMaybe <$> selectEntities Proxy (Take 1 All )
137+ case reply of
138+ Just reply' -> return reply'
139+ Nothing ->
140+ createEntity Proxy $
141+ NoTrustReply
142+ [qms |You have to be trusted to use this command.
143+ Mods can change this message with
144+ !config reply command <message>|]
145+ [qms |You have to be trusted to send links.
146+ Mods can change this message with
147+ !config reply link <message>|]
148+
149+ noTrust :: Message a -> Effect ()
150+ noTrust Message {messageSender = sender} = do
151+ reply <- entityPayload <$> noTrustReply
152+ replyToSender sender $ noTrustCommandReply reply
153+
90154onlyForTwitch :: Reaction Message a -> Reaction Message a
91155onlyForTwitch reaction =
92156 Reaction $ \ msg ->
0 commit comments