module Network.Skype.Command.User where
import Control.Monad.Trans
import Control.Monad.Trans.Control
import Data.Monoid ((<>))
import Network.Skype.Command.Utils
import Network.Skype.Core
import Network.Skype.Protocol
import qualified Data.Text.Encoding as T
getFullName :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserFullName
getFullName userID = executeCommandWithID command $ \response ->
case response of
User _ (UserFullName fullName) -> return $ Just fullName
_ -> return Nothing
where
command = "GET USER " <> userID <> " FULLNAME"
getBirthday :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m (Maybe UserBirthday)
getBirthday userID = executeCommandWithID command $ \response ->
case response of
User _ (UserBirthday birthday) -> return $ Just birthday
_ -> return Nothing
where
command = "GET USER " <> userID <> " BIRTHDAY"
getSex :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserSex
getSex userID = executeCommandWithID command $ \response ->
case response of
User _ (UserSex sex) -> return $ Just sex
_ -> return Nothing
where
command = "GET USER " <> userID <> " SEX"
getLanguage :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m (Maybe (UserLanguageISOCode, UserLanguage))
getLanguage userID = executeCommandWithID command $ \response ->
case response of
User _ (UserLanguage language) -> return $ Just language
_ -> return Nothing
where
command = "GET USER " <> userID <> " LANGUAGE"
getCountry :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m (Maybe (UserCountryISOCode, UserCountry))
getCountry userID = executeCommandWithID command $ \response ->
case response of
User _ (UserCountry country) -> return $ Just country
_ -> return Nothing
where
command = "GET USER " <> userID <> " COUNTRY"
getProvince :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserProvince
getProvince userID = executeCommandWithID command $ \response ->
case response of
User _ (UserProvince province) -> return $ Just province
_ -> return Nothing
where
command = "GET USER " <> userID <> " PROVINCE"
getCity :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserCity
getCity userID = executeCommandWithID command $ \response ->
case response of
User _ (UserCity city) -> return $ Just city
_ -> return Nothing
where
command = "GET USER " <> userID <> " CITY"
getHomePhone :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserPhone
getHomePhone userID = executeCommandWithID command $ \response ->
case response of
User _ (UserHomePhone phone) -> return $ Just phone
_ -> return Nothing
where
command = "GET USER " <> userID <> " PHONE_HOME"
getOfficePhone :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserPhone
getOfficePhone userID = executeCommandWithID command $ \response ->
case response of
User _ (UserOfficePhone phone) -> return $ Just phone
_ -> return Nothing
where
command = "GET USER " <> userID <> " PHONE_OFFICE"
getMobilePhone :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserPhone
getMobilePhone userID = executeCommandWithID command $ \response ->
case response of
User _ (UserMobilePhone phone) -> return $ Just phone
_ -> return Nothing
where
command = "GET USER " <> userID <> " PHONE_MOBILE"
getHomepage :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserHomepage
getHomepage userID = executeCommandWithID command $ \response ->
case response of
User _ (UserHomepage homepage) -> return $ Just homepage
_ -> return Nothing
where
command = "GET USER " <> userID <> " HOMEPAGE"
getAbout :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserAbout
getAbout userID = executeCommandWithID command $ \response ->
case response of
User _ (UserAbout about) -> return $ Just about
_ -> return Nothing
where
command = "GET USER " <> userID <> " ABOUT"
isVideoCapable :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
isVideoCapable userID = executeCommandWithID command $ \response ->
case response of
User _ (UserIsVideoCapable videoCapable) -> return $ Just videoCapable
_ -> return Nothing
where
command = "GET USER " <> userID <> " IS_VIDEO_CAPABLE"
isVoicemailCapable :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
isVoicemailCapable userID = executeCommandWithID command $ \response ->
case response of
User _ (UserIsVoicemailCapable voicemailCapable) -> return $ Just voicemailCapable
_ -> return Nothing
where
command = "GET USER " <> userID <> " IS_VOICEMAIL_CAPABLE"
getBuddyStatus :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserBuddyStatus
getBuddyStatus userID = executeCommandWithID command $ \response ->
case response of
User _ (UserBuddyStatus displayName) -> return $ Just displayName
_ -> return Nothing
where
command = "GET USER " <> userID <> " BUDDYSTATUS"
removeFromContactList :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m ()
removeFromContactList userID = executeCommandWithID command $ \response ->
case response of
User _ (UserBuddyStatus _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " BUDDYSTATUS 1"
askAuthorization :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> UserAuthRequestMessage
-> SkypeT m ()
askAuthorization userID message = executeCommandWithID command $ \response ->
case response of
User _ (UserBuddyStatus _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " BUDDYSTATUS 2"
<> T.encodeUtf8 message
isAuthorized :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
isAuthorized userID = executeCommandWithID command $ \response ->
case response of
User _ (UserIsAuthorized authorized) -> return $ Just authorized
_ -> return Nothing
where
command = "GET USER " <> userID <> " ISAUTHORIZED"
setAuthorized :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> Bool
-> SkypeT m ()
setAuthorized userID authorized = executeCommandWithID command $ \response ->
case response of
User _ (UserIsAuthorized _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " ISAUTHORIZED "
<> if authorized then "TRUE" else "FALSE"
isBlocked :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
isBlocked userID = executeCommandWithID command $ \response ->
case response of
User _ (UserIsBlocked blocked) -> return $ Just blocked
_ -> return Nothing
where
command = "GET USER " <> userID <> " ISBLOCKED"
setBlocked :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> Bool
-> SkypeT m ()
setBlocked userID blocked = executeCommandWithID command $ \response ->
case response of
User _ (UserIsBlocked _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " ISBLOCKED "
<> (if blocked then "TRUE" else "FALSE")
getOnlineStatus :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserOnlineStatus
getOnlineStatus userID = executeCommandWithID command $ \response ->
case response of
User _ (UserOnlineStatus status) -> return $ Just status
_ -> return Nothing
where
command = "GET USER " <> userID <> " ONLINESTATUS"
getLastOnlineTimestamp :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Timestamp
getLastOnlineTimestamp userID = executeCommandWithID command $ \response ->
case response of
User _ (UserLastOnlineTimestamp lastOnlineTime) -> return $ Just lastOnlineTime
_ -> return Nothing
where
command = "GET USER " <> userID <> " LASTONLINETIMESTAMP"
canLeaveVoicemail :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
canLeaveVoicemail userID = executeCommandWithID command $ \response ->
case response of
User _ (UserCanLeaveVoicemail canLeave) -> return $ Just canLeave
_ -> return Nothing
where
command = "GET USER " <> userID <> " CAN_LEAVE_VM"
getSpeedDial :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserSpeedDial
getSpeedDial userID = executeCommandWithID command $ \response ->
case response of
User _ (UserSpeedDial speedDial) -> return $ Just speedDial
_ -> return Nothing
where
command = "GET USER " <> userID <> " SPEEDDIAL"
setSpeedDial :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> UserSpeedDial
-> SkypeT m ()
setSpeedDial userID speedDial = executeCommandWithID command $ \response ->
case response of
User _ (UserSpeedDial _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " SPEEDDIAL " <> (T.encodeUtf8 speedDial)
getMoodText :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserMoodText
getMoodText userID = executeCommandWithID command $ \response ->
case response of
User _ (UserMoodText moodText) -> return $ Just moodText
_ -> return Nothing
where
command = "GET USER " <> userID <> " MOOD_TEXT"
getTimezone :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserTimezoneOffset
getTimezone userID = executeCommandWithID command $ \response ->
case response of
User _ (UserTimezone timezone) -> return $ Just timezone
_ -> return Nothing
where
command = "GET USER " <> userID <> " TIMEZONE"
isCallForwardingActive :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Bool
isCallForwardingActive userID = executeCommandWithID command $ \response ->
case response of
User _ (UserIsCallForwardingActive callForwardingActive) -> return $ Just callForwardingActive
_ -> return Nothing
where
command = "GET USER " <> userID <> " IS_CF_ACTIVE"
getNumberOfAuthedBuddies :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m Int
getNumberOfAuthedBuddies userID = executeCommandWithID command $ \response ->
case response of
User _ (UserNumberOfAuthedBuddies numberOfAuthedBuddies) -> return $ Just numberOfAuthedBuddies
_ -> return Nothing
where
command = "GET USER " <> userID <> " NROF_AUTHED_BUDDIES"
getDisplayName :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> SkypeT m UserDisplayName
getDisplayName userID = executeCommandWithID command $ \response ->
case response of
User _ (UserDisplayName displayName) -> return $ Just displayName
_ -> return Nothing
where
command = "GET USER " <> userID <> " DISPLAYNAME"
setDisplayName :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> UserID
-> UserDisplayName
-> SkypeT m ()
setDisplayName userID displayName = executeCommandWithID command $ \response ->
case response of
User _ (UserDisplayName _) -> return $ Just ()
_ -> return Nothing
where
command = "SET USER " <> userID <> " DISPLAYNAME " <> (T.encodeUtf8 displayName)
getCurrentUserHandle :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> SkypeT m UserID
getCurrentUserHandle = executeCommandWithID command $ \response ->
case response of
CurrentUserHandle userID -> return $ Just userID
_ -> return Nothing
where
command = "GET CURRENTUSERHANDLE"
searchAllFriends :: (MonadBaseControl IO m, MonadIO m, MonadSkype m)
=> SkypeT m [UserID]
searchAllFriends = executeCommandWithID command $ \response ->
case response of
Users userIDs -> return $ Just userIDs
_ -> return Nothing
where
command = "SEARCH FRIENDS"