git.iko.soy/rowtype-yoga/royo
on main help sign in
Extract and share code evaluation routine
1236890PureFunctor
src/Discord/DiscordJS.purs−1
@@ -40,7 +40,6 @@ type Message =
40 { channel ∷ Channel
40 { channel ∷ Channel
41 , content ∷ String {- not really... -}
41 , content ∷ String {- not really... -}
42 , author ∷ User
42 , author ∷ User
43− , id ∷ String {- Snowflake ~ String -}
44 }
43 }
45
44
46foreign import removeAllReactionsImpl ∷ Message -> Effect (Promise Unit)
45foreign import removeAllReactionsImpl ∷ Message -> Effect (Promise Unit)
src/Royo/Discord/Bot.purs+22−19
@@ -47,25 +47,28 @@ runBot yogaToken discordToken = do
47 messageUpdatedHandler _ msg = printErrors msg do
47 messageUpdatedHandler _ msg = printErrors msg do
48 when (isMention msg.content) do
48 when (isMention msg.content) do
49 msg # react rewindEmoji
49 msg # react rewindEmoji
50− messageHandler msg
50+ evaluate msg (pure unit)
51−
51+
52− messageHandler msg@{ content, channel } = printErrors msg do
52+ messageHandler msg = printErrors msg do
53− when (isMention content) do
53+ when (isMention msg.content) do
54− case parseCodeBlock content of
55− Nothing -> do
56− sendBasicInstructions msg
54+ evaluate msg (sendBasicInstructions msg)
55+
56+ evaluate msg@{ content, channel } doNothing = do
57+ case parseCodeBlock content of
58+ Nothing ->
59+ doNothing
57− Just code -> do
60+ Just code -> do
58− res <- compileAndRun yogaToken { code: prepareCode code }
61+ res <- compileAndRun yogaToken { code: prepareCode code }
59− case res of
62+ case res of
60− Left cr -> sendCompileProblem msg code cr
63+ Left cr -> sendCompileProblem msg code cr
61− Right rr -> case NES.fromString rr.stdout, NES.fromString rr.stderr of
64+ Right rr -> case NES.fromString rr.stdout, NES.fromString rr.stderr of
62− Just _, _ -> do
65+ Just _, _ -> do
63− msg # react robotMuscleEmoji
66+ msg # react robotMuscleEmoji
64− channel # sendString (NonEmptyString (prepareOutput rr.stdout))
67+ channel # sendString (NonEmptyString (prepareOutput rr.stdout))
65− Nothing, Just _ -> do
68+ Nothing, Just _ -> do
66− msg # react sirenEmoji
69+ msg # react sirenEmoji
67− sendRunProblem msg code rr.stderr
70+ sendRunProblem msg code rr.stderr
68− _, _ -> channel # sendString (NonEmptyString "Something is weird")
71+ _, _ -> channel # sendString (NonEmptyString "Something is weird")
69
72
70sendBasicInstructions :: Message -> Aff Unit
73sendBasicInstructions :: Message -> Aff Unit
71sendBasicInstructions msg = do
74sendBasicInstructions msg = do