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
Channels.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 | {- 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 #-}
-- | Visit, join, leave commands
--
-- Manage bot channels
module FunBot.Commands.Channels
( cmdVisit
, cmdJoin
, cmdLeave
)
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
respondVisit
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondVisit _mchan _nick [chan] send = do
memb <- botMemberOf $ Channel chan
send $ MsgContent $ if memb
then "I’m already a member of that channel. I think. Trying anyway."
else "Visiting " <> chan
joinChannel (Channel chan) Nothing
respondVisit mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 1)
cmdVisit = Command
{ cmdNames = cmds ["visit"]
, cmdRespond = respondVisit
, cmdHelp = helps
[ ( "visit <channel>"
, "ask the bot to join a given channel, without storing state. So \
\the bot won’t remember to join it next time and default settings \
\will be used. This is useful for short tests perhaps. If you’d \
\like the bot to become a permanent member, use !join."
)
]
, cmdExamples =
[ "visit #freepost"
]
}
respondJoin
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondJoin _mchan _nick [chan] send = do
memb <- botMemberOf $ Channel chan
sel <- channelSelected $ Channel chan
send $ MsgContent $ if memb && sel
then "I'm already a member of that channel. I think. Trying anyway."
else "Becoming a member of " <> chan
joinChannel (Channel chan) Nothing
addChannel $ Channel chan
respondJoin mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 1)
cmdJoin = Command
{ cmdNames = cmds ["join"]
, cmdRespond = respondJoin
, cmdHelp = helps
[ ( "join <channel>"
, "ask the bot to join a given channel, and make them a permanent \
\member, automatically joining on bot restart. You can use !leave \
\to make the bot leave. To invite the bot just for a temporary \
\session, use !visit."
)
]
, cmdExamples =
[ "join #freepost"
]
}
respondLeave
:: Maybe Channel
-> Nickname
-> [Text]
-> (MsgContent -> BotSession ())
-> BotSession ()
respondLeave Nothing _nick [] send = send $ MsgContent "This works only in a channel."
respondLeave (Just chan) nick [] send = do
unselectChannel chan
send $ MsgContent $ "Leaving the channel for now. Bye! o/"
partChannel chan $ Just $ Comment $ "Asked by " <> unNickname nick <> " to leave"
respondLeave mchan nick args _send =
failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 0)
cmdLeave = Command
{ cmdNames = cmds ["leave"]
, cmdRespond = respondLeave
, cmdHelp = helps
[ ( "leave"
, "ask me to leave the current channel, i.e. the one in which this \
\command has been used. If the channel was selected for \
\auto-joining, it is now unselected."
)
]
, cmdExamples =
[ "leave #freepost"
]
}
|