An IRC bot for learning, fun and collaboration in the Freepost community.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/VvM9v
SSH:
git clone USERNAME@vervis.peers.community:VvM9v
Branches
Tags
Settings.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | {- This file is part of funbot.
-
- Written in 2015, 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- ♡ Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
{-# LANGUAGE OverloadedStrings #-}
-- | Get, set, enable and disable commands
--
-- Manage bot settings
module FunBot.Commands.Settings
( cmdGet
, cmdSet
, cmdReset
, cmdEnable
, cmdDisable
)
where
import Control.Monad (unless, when)
import Data.List (find, intercalate)
import Data.Monoid ((<>))
import Data.Settings.Types (showOption)
import Data.Text (Text)
import FunBot.History (quote, reportHistory')
import FunBot.Memos (submitMemo)
import FunBot.Settings
import FunBot.Settings.Sections.Channels (addChannel)
import FunBot.Settings.Sections.Feeds (addFeed, deleteFeed)
import FunBot.Settings.Sections.Repos
import FunBot.Settings.Sections.Shortcuts (addShortcut, deleteShortcut)
import FunBot.Types
import FunBot.UserOptions
import FunBot.Util (getHistoryLines, cmds, helps)
import Network.IRC.Fun.Bot.Behavior
import Network.IRC.Fun.Bot.Chat
import Network.IRC.Fun.Bot.State
import Network.IRC.Fun.Bot.Types
import Text.Read (readMaybe)
import Network.IRC.Fun.Types.Base
import qualified Data.CaseInsensitive as CI
import qualified Data.Text as T
import qualified Data.Text.Read as TR
respondGet
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondGet _mchan _nick [] send = respondGet' "" send
respondGet _mchan _nick [path] send = respondGet' path send
respondGet mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 1)
respondSet
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondSet _mchan _nick [name, val] send = respondSet' name val send
respondSet mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 2)
respondReset
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondReset _mchan _nick [name] send = respondReset' name send
respondReset mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 1)
-- Given a boolean, create an enable/disable response accordingly
respondBool
:: Bool
-> Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondBool val _mchan _nick [name] send =
respondSet' name (showOption val) send
respondBool _val mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 1)
respondEnable
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondEnable = respondBool True
respondDisable
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondDisable = respondBool False
cmdGet = Command
{ cmdNames = cmds ["get"]
, cmdRespond = respondGet
, cmdHelp = helps
[ ( "get <option>"
, "get the value of a settings option at the given path"
)
]
, cmdExamples =
[ "get channels.#freepost.welcome"
]
}
cmdSet = Command
{ cmdNames = cmds ["set"]
, cmdRespond = respondSet
, cmdHelp = helps
[ ( "set <option> <value>"
, "set a settings option at the given path to the given value"
)
]
, cmdExamples =
[ "set channels.#freepost.welcome yes"
]
}
cmdReset = Command
{ cmdNames = cmds ["reset"]
, cmdRespond = respondReset
, cmdHelp = helps
[ ( "reset <option>"
, "set a settings option at the given path to its default value"
)
]
, cmdExamples =
[ "reset channels.#freepost.welcome"
]
}
cmdEnable = Command
{ cmdNames = cmds ["enable"]
, cmdRespond = respondEnable
, cmdHelp = helps
[ ( "enable <option>"
, "set a settings option at the given path to True"
)
]
, cmdExamples =
[ "enable channels.#freepost.welcome"
]
}
cmdDisable = Command
{ cmdNames = cmds ["disable"]
, cmdRespond = respondDisable
, cmdHelp = helps
[ ( "disable <option>"
, "set a settings option at the given path to False"
)
]
, cmdExamples =
[ "disable channels.#freepost.welcome"
]
}
|