1 | ;;;; $Id: event.lisp 2 2004-01-05 14:13:03Z eenge $ |
---|
2 | ;;;; $Source$ |
---|
3 | |
---|
4 | ;;;; See LICENSE for licensing information. |
---|
5 | |
---|
6 | (in-package :irc) |
---|
7 | |
---|
8 | (defgeneric irc-message-event (message) |
---|
9 | (:documentation "Upon receipt of an IRC message from the |
---|
10 | connection's stream, irc-message-event will be called with the |
---|
11 | message.")) |
---|
12 | |
---|
13 | (defmethod irc-message-event ((message irc-message)) |
---|
14 | (apply-to-hooks message) |
---|
15 | (client-log (connection message) message "UNHANDLED-EVENT:")) |
---|
16 | |
---|
17 | (defmethod default-hook ((message irc-rpl_whoisuser-message)) |
---|
18 | (let ((user (find-user (connection message) |
---|
19 | (second (arguments message)))) |
---|
20 | (realname (trailing-argument message)) |
---|
21 | (username (third (arguments message))) |
---|
22 | (hostname (fourth (arguments message)))) |
---|
23 | (setf (realname user) realname) |
---|
24 | (setf (username user) username) |
---|
25 | (setf (hostname user) hostname))) |
---|
26 | |
---|
27 | (defmethod default-hook ((message irc-rpl_list-message)) |
---|
28 | (let ((connection (connection message)) |
---|
29 | (channel (second (arguments message))) |
---|
30 | (user-count (parse-integer (or (third (arguments message)) "0"))) |
---|
31 | (topic (trailing-argument message))) |
---|
32 | (add-channel connection (or (find-channel connection channel) |
---|
33 | (make-channel :name channel |
---|
34 | :topic topic |
---|
35 | :user-count user-count))))) |
---|
36 | |
---|
37 | (defmethod default-hook ((message irc-rpl_topic-message)) |
---|
38 | (setf (topic (find-channel (connection message) |
---|
39 | (second (arguments message)))) |
---|
40 | (trailing-argument message))) |
---|
41 | |
---|
42 | (defmethod default-hook ((message irc-rpl_namreply-message)) |
---|
43 | (let* ((connection (connection message)) |
---|
44 | (channel (find-channel connection (car (last (arguments message)))))) |
---|
45 | (dolist (nickname (tokenize-string (trailing-argument message))) |
---|
46 | (let ((user (find-or-make-user connection |
---|
47 | (canonicalize-nickname nickname) |
---|
48 | :username (user message) |
---|
49 | :hostname (host message)))) |
---|
50 | (unless (equal user (user connection)) |
---|
51 | (add-user connection user) |
---|
52 | (add-user channel user)))))) |
---|
53 | |
---|
54 | (defmethod default-hook ((message irc-ping-message)) |
---|
55 | (pong (connection message) (trailing-argument message))) |
---|
56 | |
---|
57 | (defmethod default-hook ((message irc-join-message)) |
---|
58 | (let* ((connection (connection message)) |
---|
59 | (user (find-or-make-user |
---|
60 | (connection message) |
---|
61 | (source message) |
---|
62 | :hostname (host message) |
---|
63 | :username (user message))) |
---|
64 | (channel (or (find-channel connection (trailing-argument message)) |
---|
65 | (make-channel :name (trailing-argument message))))) |
---|
66 | (if (self-message-p message) |
---|
67 | (add-channel connection channel) |
---|
68 | (progn |
---|
69 | (add-user connection user) |
---|
70 | (add-user channel user))))) |
---|
71 | |
---|
72 | (defmethod default-hook ((message irc-topic-message)) |
---|
73 | (setf (topic (find-channel (connection message) |
---|
74 | (first (arguments message)))) |
---|
75 | (trailing-argument message))) |
---|
76 | |
---|
77 | (defmethod default-hook ((message irc-part-message)) |
---|
78 | (let* ((connection (connection message)) |
---|
79 | (channel (find-channel connection (first (arguments message)))) |
---|
80 | (user (find-user connection (source message)))) |
---|
81 | (if (self-message-p message) |
---|
82 | (remove-channel channel user) |
---|
83 | (remove-user channel user)))) |
---|
84 | |
---|
85 | (defmethod default-hook ((message irc-quit-message)) |
---|
86 | (let ((connection (connection message))) |
---|
87 | (remove-user-everywhere connection (find-user connection (source message))))) |
---|
88 | |
---|
89 | (defmethod default-hook ((message irc-nick-message)) |
---|
90 | (let ((con (connection message))) |
---|
91 | (change-nickname con (find-user con (source message)) |
---|
92 | (trailing-argument message)))) |
---|
93 | |
---|
94 | (defmethod default-hook ((message irc-kick-message)) |
---|
95 | (let* ((connection (connection message)) |
---|
96 | (channel (find-channel connection (first (arguments message)))) |
---|
97 | (user (find-user connection (second (arguments message))))) |
---|
98 | (if (self-message-p message) |
---|
99 | (remove-channel channel user) |
---|
100 | (remove-user channel user)))) |
---|
101 | |
---|
102 | (defmethod default-hook ((message ctcp-time-message)) |
---|
103 | (multiple-value-bind (second minute hour date month year day) (get-decoded-time) |
---|
104 | (send-irc-message |
---|
105 | (connection message) |
---|
106 | :notice (make-ctcp-message |
---|
107 | (format nil "TIME ~A" |
---|
108 | (make-time-message second minute hour date month year day))) |
---|
109 | (source message)))) |
---|
110 | |
---|
111 | (defmethod default-hook ((message ctcp-source-message)) |
---|
112 | (send-irc-message |
---|
113 | (connection message) |
---|
114 | :notice (make-ctcp-message |
---|
115 | (format nil "SOURCE ~A:~A:~A" |
---|
116 | *download-host* |
---|
117 | *download-directory* |
---|
118 | *download-file*)) |
---|
119 | (source message))) |
---|
120 | |
---|
121 | (defmethod default-hook ((message ctcp-finger-message)) |
---|
122 | (let* ((user (user (connection message))) |
---|
123 | (finger-info (if (not (zerop (length (realname user)))) |
---|
124 | (realname user) |
---|
125 | (nickname user)))) |
---|
126 | (send-irc-message |
---|
127 | (connection message) |
---|
128 | :notice (make-ctcp-message |
---|
129 | (format nil "FINGER ~A" finger-info)) |
---|
130 | (source message)))) |
---|
131 | |
---|
132 | (defmethod default-hook ((message ctcp-version-message)) |
---|
133 | (send-irc-message |
---|
134 | (connection message) |
---|
135 | :notice (make-ctcp-message |
---|
136 | (format nil "VERSION ~A" *ctcp-version*)) |
---|
137 | (source message))) |
---|
138 | |
---|
139 | (defmethod default-hook ((message ctcp-ping-message)) |
---|
140 | (send-irc-message |
---|
141 | (connection message) |
---|
142 | :notice (make-ctcp-message |
---|
143 | (format nil "PING ~A" (trailing-argument message))) |
---|
144 | (source message))) |
---|
145 | |
---|
146 | (defmethod irc-message-event ((message ctcp-dcc-chat-request-message)) |
---|
147 | (apply-to-hooks message) |
---|
148 | (client-log (connection message) message)) |
---|
149 | ; (when (automatically-accept-dcc-connections (configuration (connection message))) |
---|
150 | ; (let* ((user (find-user (connection message) (source message))) |
---|
151 | ; (args (tokenize-string (trailing-argument message))) |
---|
152 | ; (remote-address (hbo-to-vector-quad (parse-integer (fourth args)))) |
---|
153 | ; (remote-port (parse-integer (fifth args) :junk-allowed t))) |
---|
154 | ; (push (make-dcc-connection :user user |
---|
155 | ; :remote-address remote-address |
---|
156 | ; :remote-port remote-port) |
---|
157 | ; *dcc-connections*)))) |
---|
158 | |
---|
159 | (defmethod irc-message-event ((message ctcp-dcc-send-request-message)) |
---|
160 | (apply-to-hooks message) |
---|
161 | (client-log (connection message) message)) |
---|
162 | ; (when (automatically-accept-dcc-downloads (configuration (connection message))) |
---|
163 | ; (let* ((user (find-user (connection message) (source message))) |
---|
164 | ; (args (tokenize-string (trailing-argument message))) |
---|
165 | ; (filename (third args)) |
---|
166 | ; (remote-address (hbo-to-vector-quad (parse-integer (fourth args)))) |
---|
167 | ; (remote-port (parse-integer (fifth args))) |
---|
168 | ; (filesize (parse-integer (sixth args) :junk-allowed t))) |
---|
169 | ; (let ((dcc-connection (make-dcc-connection :user user |
---|
170 | ; :remote-address remote-address |
---|
171 | ; :remote-port remote-port))) |
---|
172 | ; (with-open-file (stream filename :direction :output |
---|
173 | ; :if-exists :supersede) |
---|
174 | ; (write-sequence (read-message-loop dcc-connection) stream)))))) |
---|
175 | |
---|