Skip to content

Commit

Permalink
Update flake
Browse files Browse the repository at this point in the history
  • Loading branch information
simmsb committed Jan 22, 2023
1 parent 7219edc commit 4dfb58a
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 110 deletions.
49 changes: 27 additions & 22 deletions bot/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

module Main (main) where

import Calamity
import Calamity.Cache.InMemory
import Calamity.Commands
import Calamity.Commands.Context (useFullContext, FullContext (FullContext))
import Calamity.Commands.Context (useFullContext, FullContext)
import qualified Calamity.Interactions as I
import Calamity.Metrics.Noop
import Calamity.Utils.CDNUrl (assetHashFile)
import Control.Concurrent
import Optics
import Control.Monad
import qualified Data.Text as T
import qualified Di
import qualified DiPolysemy as DiP
import Optics
import qualified Polysemy as P
import qualified Polysemy.Async as P
import qualified Polysemy.State as P
import System.Environment (getEnv)
import TextShow
import Calamity.Utils.CDNUrl (assetHashFile)
import Calamity (RawEmoji)
import Data.Foldable (for_)

data MyViewState = MyViewState
{ numOptions :: Int
Expand All @@ -48,21 +49,23 @@ main :: IO ()
main = do
token <- T.pack <$> getEnv "BOT_TOKEN"
Di.new $ \di ->
void . P.runFinal . P.embedToFinal . DiP.runDiToIO di
void
. P.runFinal
. P.embedToFinal
. DiP.runDiToIO di
. runCacheInMemory
. runMetricsNoop
. useConstantPrefix "!"
. useFullContext
$ runBotIO (BotToken token) defaultIntents $ do
$ runBotIO (BotToken token) defaultIntents
$ do
addCommands $ do
helpCommand
-- just some examples

command @'[User] "pfp" \ctx u -> do
Right pfp <- fetchAsset (u ^. #avatar)
let name = case u ^. #avatar % #hash of
Just hash -> assetHashFile hash
Nothing -> "default.png"
let name = maybe "default.png" assetHashFile (u ^. #avatar % #hash)
file = CreateMessageAttachment name (Just "Your avatar") pfp
void $ tell ctx file
command @'[User] "utest" \ctx u -> do
Expand All @@ -86,8 +89,7 @@ main = do

command @'[[RawEmoji]] "reactpls" \ctx emojis -> do
DiP.debug @T.Text ("emojis: " <> showt emojis)
forM_ emojis \e ->
invoke $ CreateReaction ctx ctx e
for_ emojis $ invoke . CreateReaction ctx ctx

-- views!

Expand Down Expand Up @@ -164,21 +166,24 @@ main = do

pure ()

react @( 'CustomEvt (CtxCommandError FullContext)) \(CtxCommandError ctx e) -> do
react @('CustomEvt (CtxCommandError FullContext)) \(CtxCommandError ctx e) -> do
DiP.info $ "Command failed with reason: " <> showt e
case e of
ParseError n r ->
void . tell ctx $
"Failed to parse parameter: " <> codeline n
"Failed to parse parameter: "
<> codeline n
<> ", with reason: "
<> codeblock' Nothing r
CheckError n r ->
void . tell ctx $
"The following check failed: " <> codeline n
"The following check failed: "
<> codeline n
<> ", with reason: "
<> codeblock' Nothing r
InvokeError n r ->
void . tell ctx $
"The command: " <> codeline n
"The command: "
<> codeline n
<> ", failed with reason: "
<> codeblock' Nothing r
8 changes: 2 additions & 6 deletions calamity-commands/calamity-commands.cabal
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
cabal-version: 1.18

-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack
cabal-version: 2.0

name: calamity-commands
version: 0.4.0.0
Expand All @@ -18,7 +14,7 @@ license: MIT
license-file: LICENSE
build-type: Simple
tested-with:
GHC == 8.10.7, GHC == 9.2.2
GHC == 9.4.4
extra-source-files:
README.md
ChangeLog.md
Expand Down
6 changes: 1 addition & 5 deletions calamity/calamity.cabal
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
cabal-version: 2.0

-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack

name: calamity
version: 0.7.1.0
synopsis: A library for writing discord bots in haskell
Expand All @@ -18,7 +14,7 @@ license: MIT
license-file: LICENSE
build-type: Simple
tested-with:
GHC == 8.10.7, GHC == 9.2.5
GHC == 9.4.4
extra-source-files:
README.md
ChangeLog.md
Expand Down
123 changes: 93 additions & 30 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4dfb58a

Please sign in to comment.