+ (let ((network (lurk-context-network (lurk-current-context))))
+ (if (and params (>= (length params) 2))
+ (let ((to (car params))
+ (text (string-join (cdr params) " ")))
+ (lurk-send-msg network (lurk-msg nil nil "PRIVMSG" to text))
+ (lurk-display-message network
+ (lurk-connection-nick network)
+ to text))
+ (lurk-display-notice nil "Usage: /msg <nick> <message>"))))
+
+(defun lurk-command-me (params)
+ (let* ((ctx (lurk-current-context))
+ (network (lurk-context-network ctx)))
+ (if (and ctx (not (lurk-network-context-p ctx)))
+ (if params
+ (let* ((channel (lurk-context-channel ctx))
+ (my-nick (lurk-connection-nick network))
+ (action (string-join params " "))
+ (ctcp-text (concat "\01ACTION " action "\01")))
+ (lurk-send-msg network
+ (lurk-msg nil nil "PRIVMSG"
+ (list channel ctcp-text)))
+ (lurk-display-action network my-nick channel action))
+ (lurk-display-notice nil "Usage: /me <action>"))
+ (lurk-display-notice nil "No current channel."))))
+
+(defun lurk-command-version (params)
+ (let ((ctx (lurk-current-context)))
+ (if ctx
+ (if params
+ (let ((network (lurk-context-network ctx))
+ (nick (car params)))
+ (lurk-send-msg network
+ (lurk-msg nil nil "PRIVMSG"
+ (list nick "\01VERSION\01")))
+ (lurk-display-notice ctx "CTCP version request sent to "
+ nick " on " network))
+ (lurk-display-notice ctx "Usage: /version <nick>"))
+ (lurk-display-notice nil "No current channel."))))
+
+(defun lurk-command-users (_params)
+ (let ((ctx (lurk-current-context)))
+ (if (and ctx (not (lurk-network-context-p ctx)))
+ (let ((channel (lurk-context-channel ctx))
+ (network (lurk-context-network ctx))
+ (users (lurk-get-context-users ctx)))
+ (lurk-display-notice ctx "Users in " channel " on " network ":")
+ (lurk-display-notice ctx (string-join users " ")))
+ (lurk-display-notice nil "No current channel."))))
+
+
+;;; Command entering
+;;
+
+(defun lurk-enter-string (string)
+ (if (string-prefix-p "/" string)
+ (pcase string
+ ((rx (: "/" (let cmd-str (+ (not whitespace)))
+ (opt (+ whitespace)
+ (let params-str (+ anychar))
+ string-end)))
+ (let ((command-row (assoc (upcase cmd-str) lurk-command-table #'equal))
+ (params (if params-str
+ (split-string params-str nil t)
+ nil)))
+ (if (and command-row (elt command-row 2))
+ (funcall (elt command-row 2) params)
+ (lurk-send-msg
+ (lurk-context-network (lurk-current-context))
+ (lurk-msg nil nil (upcase cmd-str) params)))))
+ (_
+ (lurk-display-error "Badly formed command")))
+ (unless (string-empty-p string)
+ (let ((ctx (lurk-current-context)))
+ (if ctx
+ (if (not (lurk-network-context-p ctx))
+ (let ((network (lurk-context-network ctx))
+ (channel (lurk-context-channel ctx)))
+ (lurk-send-msg network
+ (lurk-msg nil nil "PRIVMSG" channel string))
+ (lurk-display-message network
+ (lurk-connection-nick network)
+ channel string))
+ (lurk-display-error "No current channel"))
+ (lurk-display-error "No current context"))))))