[cl-irc-cvs] r239 - trunk
ehuelsmann at common-lisp.net
ehuelsmann at common-lisp.net
Sun Jan 13 18:59:50 UTC 2013
Author: ehuelsmann
Date: Sun Jan 13 10:59:49 2013
New Revision: 239
Log:
Patch by Julien Danjou: Factorize mode changes.
Modified:
trunk/event.lisp
trunk/package.lisp
trunk/utility.lisp
Modified: trunk/event.lisp
==============================================================================
--- trunk/event.lisp Sun Jan 13 10:50:37 2013 (r238)
+++ trunk/event.lisp Sun Jan 13 10:59:49 2013 (r239)
@@ -279,20 +279,10 @@
(destructuring-bind
(target channel &rest mode-arguments)
arguments
- (let* ((channel (find-channel connection channel))
- (mode-changes
- (when channel
- (parse-mode-arguments connection channel mode-arguments
- :server-p (user connection)))))
- (dolist (change mode-changes)
- (destructuring-bind
- (op mode-name value)
- change
- (unless (has-mode-p channel mode-name)
- (add-mode channel mode-name
- (make-mode connection channel mode-name)))
- (funcall (if (char= #\+ op) #'set-mode #'unset-mode)
- channel mode-name value)))))))
+ (let ((channel (find-channel connection channel)))
+ (when channel
+ (apply-mode-changes connection channel
+ mode-arguments (user connection)))))))
(defmethod default-hook ((message irc-mode-message))
(destructuring-bind
@@ -300,20 +290,9 @@
(arguments message)
(let* ((connection (connection message))
(target (or (find-channel connection target)
- (find-user connection target)))
- (mode-changes
- (when target
- (parse-mode-arguments connection target arguments
- :server-p (user connection)))))
- (dolist (change mode-changes)
- (destructuring-bind
- (op mode-name value)
- change
- (unless (has-mode-p target mode-name)
- (add-mode target mode-name
- (make-mode connection target mode-name)))
- (funcall (if (char= #\+ op) #'set-mode #'unset-mode)
- target mode-name value))))))
+ (find-user connection target))))
+ (when target
+ (apply-mode-changes connection target arguments (user connection))))))
(defmethod default-hook ((message irc-nick-message))
(with-slots
Modified: trunk/package.lisp
==============================================================================
--- trunk/package.lisp Sun Jan 13 10:50:37 2013 (r238)
+++ trunk/package.lisp Sun Jan 13 10:59:49 2013 (r239)
@@ -32,6 +32,7 @@
:get-mode
:set-mode
:unset-mode
+ :apply-mode-changes
:parse-mode-arguments
:parse-raw-message
:normalize-nickname
Modified: trunk/utility.lisp
==============================================================================
--- trunk/utility.lisp Sun Jan 13 10:50:37 2013 (r238)
+++ trunk/utility.lisp Sun Jan 13 10:59:49 2013 (r239)
@@ -493,6 +493,21 @@
(split-sequence:split-sequence #\: x))
(split-sequence:split-sequence #\, argument)))
+(defun apply-mode-changes (connection target mode-arguments server-p)
+ (dolist (change (parse-mode-arguments connection target mode-arguments
+ :server-p server-p))
+ (apply-mode-change connection target change)))
+
+(defun apply-mode-change (connection target change)
+ (destructuring-bind
+ (op mode-name value)
+ change
+ (unless (has-mode-p target mode-name)
+ (add-mode target mode-name
+ (make-mode connection target mode-name)))
+ (funcall (if (char= #\+ op) #'set-mode #'unset-mode)
+ target mode-name value)))
+
(defun parse-mode-arguments (connection target arguments &key server-p)
"Create a list of mode changes with their arguments for `target'
from `mode-string' and `arguments'.
More information about the cl-irc-cvs
mailing list