<div dir="ltr">Hi Julien,<div><br></div><div style>Thanks for your contributions so far! This one is committed as r239.</div><div style><br></div><div style>Bye,</div><div style><br></div><div style>Erik.</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, Jan 13, 2013 at 3:04 PM, Julien Danjou <span dir="ltr"><<a href="mailto:julien@danjou.info" target="_blank">julien@danjou.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The code used into mode-message and rpl_channelmodeis-message is exactly the<br>
same, so let's factorize this a bit to less code.<br>
<br>
Signed-off-by: Julien Danjou <<a href="mailto:julien@danjou.info">julien@danjou.info</a>><br>
---<br>
event.lisp | 34 ++++++----------------------------<br>
package.lisp | 1 +<br>
utility.lisp | 15 +++++++++++++++<br>
3 files changed, 22 insertions(+), 28 deletions(-)<br>
<br>
diff --git a/event.lisp b/event.lisp<br>
index 5e6e417..57ccf51 100644<br>
--- a/event.lisp<br>
+++ b/event.lisp<br>
@@ -279,20 +279,9 @@ objects in sync."))<br>
(destructuring-bind<br>
(target channel &rest mode-arguments)<br>
arguments<br>
- (let* ((channel (find-channel connection channel))<br>
- (mode-changes<br>
- (when channel<br>
- (parse-mode-arguments connection channel mode-arguments<br>
- :server-p (user connection)))))<br>
- (dolist (change mode-changes)<br>
- (destructuring-bind<br>
- (op mode-name value)<br>
- change<br>
- (unless (has-mode-p channel mode-name)<br>
- (add-mode channel mode-name<br>
- (make-mode connection channel mode-name)))<br>
- (funcall (if (char= #\+ op) #'set-mode #'unset-mode)<br>
- channel mode-name value)))))))<br>
+ (let ((channel (find-channel connection channel)))<br>
+ (when channel<br>
+ (apply-mode-changes connection channel mode-arguments (user connection)))))))<br>
<br>
(defmethod default-hook ((message irc-mode-message))<br>
(destructuring-bind<br>
@@ -300,20 +289,9 @@ objects in sync."))<br>
(arguments message)<br>
(let* ((connection (connection message))<br>
(target (or (find-channel connection target)<br>
- (find-user connection target)))<br>
- (mode-changes<br>
- (when target<br>
- (parse-mode-arguments connection target arguments<br>
- :server-p (user connection)))))<br>
- (dolist (change mode-changes)<br>
- (destructuring-bind<br>
- (op mode-name value)<br>
- change<br>
- (unless (has-mode-p target mode-name)<br>
- (add-mode target mode-name<br>
- (make-mode connection target mode-name)))<br>
- (funcall (if (char= #\+ op) #'set-mode #'unset-mode)<br>
- target mode-name value))))))<br>
+ (find-user connection target))))<br>
+ (when target<br>
+ (apply-mode-changes connection target arguments (user connection))))))<br>
<br>
(defmethod default-hook ((message irc-nick-message))<br>
(with-slots<br>
diff --git a/package.lisp b/package.lisp<br>
index c09537a..bd5a480 100644<br>
--- a/package.lisp<br>
+++ b/package.lisp<br>
@@ -32,6 +32,7 @@<br>
:get-mode<br>
:set-mode<br>
:unset-mode<br>
+ :apply-mode-changes<br>
:parse-mode-arguments<br>
:parse-raw-message<br>
:normalize-nickname<br>
diff --git a/utility.lisp b/utility.lisp<br>
index 12c327c..9894ed0 100644<br>
--- a/utility.lisp<br>
+++ b/utility.lisp<br>
@@ -493,6 +493,21 @@ It returns a list of mode-description records."<br>
(split-sequence:split-sequence #\: x))<br>
(split-sequence:split-sequence #\, argument)))<br>
<br>
+(defun apply-mode-changes (connection target mode-arguments server-p)<br>
+ (dolist (change (parse-mode-arguments connection target mode-arguments<br>
+ :server-p server-p))<br>
+ (apply-mode-change connection target change)))<br>
+<br>
+(defun apply-mode-change (connection target change)<br>
+ (destructuring-bind<br>
+ (op mode-name value)<br>
+ change<br>
+ (unless (has-mode-p target mode-name)<br>
+ (add-mode target mode-name<br>
+ (make-mode connection target mode-name)))<br>
+ (funcall (if (char= #\+ op) #'set-mode #'unset-mode)<br>
+ target mode-name value)))<br>
+<br>
(defun parse-mode-arguments (connection target arguments &key server-p)<br>
"Create a list of mode changes with their arguments for `target'<br>
from `mode-string' and `arguments'.<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1<br>
<br>
<br>
_______________________________________________<br>
cl-irc-devel site list<br>
<a href="mailto:cl-irc-devel@common-lisp.net">cl-irc-devel@common-lisp.net</a><br>
<a href="http://common-lisp.net/mailman/listinfo/cl-irc-devel" target="_blank">http://common-lisp.net/mailman/listinfo/cl-irc-devel</a><br>
</font></span></blockquote></div><br></div>