Antoine COMBET
3 years ago
5 changed files with 122 additions and 0 deletions
-
2.gitignore
-
26LICENSE
-
6README.org
-
50app/Main.hs
-
38botiut.cabal
@ -0,0 +1,2 @@ |
|||
dist-newstyle |
|||
*.secret |
@ -0,0 +1,26 @@ |
|||
Copyright © 2022 Antoine "Annwan" COMBET |
|||
|
|||
Redistribution and use in source and binary forms, with or without modification, |
|||
are permitted provided that the following conditions are met: |
|||
|
|||
1. Redistributions of source code must retain the above copyright notice, this |
|||
list of conditions and the following disclaimer. |
|||
|
|||
2. Redistributions in binary form must reproduce the above copyright notice, |
|||
this list of conditions and the following disclaimer in the documentation and/or |
|||
other materials provided with the distribution. |
|||
|
|||
3. Neither the name of the copyright holder nor the names of its contributors |
|||
may be used to endorse or promote products derived from this software without |
|||
specific prior written permission. |
|||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
|||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
@ -1,3 +1,9 @@ |
|||
#+title: botiut |
|||
#+author: Annwan |
|||
|
|||
** TODO List [0/3] |
|||
- [ ] Framework |
|||
- [ ] Time table [0/2] |
|||
- [ ] =edt= command |
|||
- [ ] Messages in channel |
|||
- [ ] Reminders |
@ -0,0 +1,50 @@ |
|||
{-# LANGUAGE OverloadedStrings #-} |
|||
|
|||
module Main where |
|||
|
|||
import Control.Monad |
|||
|
|||
import qualified Data.Text as T |
|||
import qualified Data.Text.IO as TIO |
|||
|
|||
import UnliftIO (liftIO) |
|||
|
|||
import Discord |
|||
import Discord.Types |
|||
import qualified Discord.Requests as R |
|||
|
|||
cmdPrefix :: T.Text |
|||
cmdPrefix = "%" |
|||
|
|||
main :: IO () |
|||
main = do |
|||
tok <- TIO.readFile "./auth.secret" |
|||
err <- runDiscord $ def { discordToken = tok |
|||
, discordOnStart = onDiscordStart |
|||
, discordOnEnd = liftIO $ putStrLn "Ended" |
|||
, discordOnEvent = onDiscordEvent |
|||
, discordOnLog = |
|||
\s -> TIO.putStrLn s >> TIO.putStrLn "" |
|||
} |
|||
TIO.putStrLn err |
|||
|
|||
onDiscordStart :: DiscordHandler () |
|||
onDiscordStart = undefined |
|||
|
|||
onDiscordEvent :: Event -> DiscordHandler () |
|||
onDiscordEvent (MessageCreate m) = when (not (fromBot m) && isCommand m) $ do |
|||
let content = messageContent m |
|||
let elements = T.words content |
|||
case head elements of |
|||
_ -> unknownCommand m elements |
|||
return () |
|||
onDiscordEvent _ = return () |
|||
|
|||
fromBot :: Message -> Bool |
|||
fromBot = userIsBot . messageAuthor |
|||
|
|||
unknownCommand :: Message -> [Text] -> DiscordHandler () |
|||
unknownCommand = |
|||
|
|||
isCommand :: Message ->Bool |
|||
isCommand = (cmdPrefix `T.isPrefixOf`) . messageContent |
@ -0,0 +1,38 @@ |
|||
cabal-version: 2.4 |
|||
name: botiut |
|||
version: 0.1.0.0 |
|||
|
|||
-- A short (one-line) description of the package. |
|||
synopsis: A discord bot |
|||
|
|||
-- A longer description of the package. |
|||
description: A discord bot |
|||
|
|||
-- A URL where users can report bugs. |
|||
-- bug-reports: |
|||
|
|||
-- The license under which the package is released. |
|||
license: BSD-3-Clause |
|||
author: Antoine "Annwan" COMBET |
|||
maintainer: annwan@outlook.fr |
|||
|
|||
-- category: |
|||
extra-source-files: |
|||
README.org |
|||
|
|||
executable botiut |
|||
main-is: Main.hs |
|||
|
|||
-- Modules included in this executable, other than Main. |
|||
-- other-modules: |
|||
|
|||
-- LANGUAGE extensions used by modules in this package. |
|||
-- other-extensions: |
|||
build-depends: |
|||
base ^>=4.15.0.0 |
|||
, discord-haskell |
|||
, control-event |
|||
, text |
|||
, unliftio |
|||
hs-source-dirs: app |
|||
default-language: Haskell2010 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue