-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirchat-cta.el
465 lines (399 loc) · 14.8 KB
/
irchat-cta.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
;;; -*- emacs-lisp -*-
;;;
;;; see file irchat-copyright.el for change log and copyright info
(eval-when-compile
(require 'irchat-inlines))
(eval-and-compile
(require 'irchat-vars))
;;;
;;; decode and encode of binary data
;;;
(defun irchat-quote-decode (string-to-decode)
(interactive)
(save-excursion
(set-buffer (get-buffer-create "*IRC DECODE*"))
(delete-region (point-min) (point-max))
(insert string-to-decode)
(goto-char (point-min))
(replace-string "\\\\" "\\")
(goto-char (point-min))
(replace-string "\\a" "")
(goto-char (point-min))
(replace-string "\\n" "\n")
(goto-char (point-min))
(replace-string "\\r" "\r")
(setq string-to-decode (buffer-substring (point-min) (point-max)))
string-to-decode))
(defun irchat-quote-encode (string)
(interactive)
(save-excursion
(set-buffer (get-buffer-create "*IRC ENCODE*"))
(delete-region (point-min) (point-max))
(insert string)
(goto-char (point-min))
(while (search-forward "\\" nil 1)
(insert "\\"))
(goto-char (point-min))
(while (search-forward "" nil 1)
(delete-char -1)
(insert "\\a"))
(goto-char (point-min))
(while (search-forward "" nil 1)
(delete-char -1)
(insert "\\0"))
(goto-char (point-min))
(while (search-forward "\n" nil 1)
(delete-char -1)
(insert "\\n"))
(goto-char (point-min))
(while (search-forward "\r" nil 1)
(delete-char -1)
(insert "\\r"))
(setq string (buffer-substring (point-min) (point-max)))
string))
(defun irchat-ctl-a-action-msg (from chnl rest)
(if (string-ci-equal chnl irchat-current-channel)
(irchat-w-insert irchat-D-buffer
(format "%sAction: %s %s\n" irchat-info-prefix from rest))
(irchat-w-insert irchat-D-buffer
(format "%sAction to %s: %s %s\n"
irchat-info-prefix chnl from rest))))
(defun irchat-ctl-a-msg (from chnl rest)
"It's ctl-a request, act on it."
(let* (left now right message rest-of-line hook)
(if (string-match "^\\([^]*\\)\\([^]*\\)\\(.*\\)" rest)
(progn
(setq left (matching-substring rest 1))
(setq now (matching-substring rest 2))
(setq right (matching-substring rest 3))
(setq rest (concat left right))
(if (string-match "^\\([^ ]*\\) \\(.*\\)" now)
(progn
(setq message (downcase (matching-substring now 1)))
(setq rest-of-line (matching-substring now 2)))
(if (string-match "^\\([^ ]*\\)" now)
(progn
(setq message (downcase (matching-substring now 1)))
(setq rest-of-line nil))
(progn
(setq message "errmsg")
(setq rest-of-line "Couldn't figure out what was said."))))
(if (and (boundp
(setq hook
(intern
(concat "irchat-ctl-a-" message "-msg-hook"))))
(eval hook)
(eq (eval (list hook from rest-of-line)) t))
;; If we have a hook, and it returns T, do nothing more
nil
;; else call the handler
(if (fboundp (setq fun (intern
(concat "irchat-ctl-a-" message "-msg"))))
(progn
(eval (list fun from chnl rest-of-line)))
(progn
; (irchat-send "NOTICE %s :ERRMSG %s :%s"
; from
; (upcase message)
; (format irchat-client-error-msg (upcase message)))
(message (format "CLIENT %s query from %s (ignored)."
(upcase message) from)))
))))
rest))
(defun irchat-ctl-a-client-msg (from chnl rest)
(let* (message rest-of-line hook)
(if rest
(progn
(if (string-match "^\\([^ ]*\\) \\(.*\\)" rest)
(progn
(setq message (downcase (matching-substring rest 1)))
(setq rest-of-line (matching-substring rest 2)))
(if (string-match "^\\([^ ]*\\)" rest)
(progn
(setq message (downcase (matching-substring rest 1)))
(setq rest-of-line nil))
(progn
(setq message "errmsg")
(setq rest-of-line "Couldn't figure out what was said."))))
(if (and (boundp
(setq hook
(intern
(concat "irchat-ctl-a-" message "-msg-hook"))))
(eval hook)
(eq (eval (list hook from rest-of-line)) t))
;; If we have a hook, and it returns T, do nothing more
nil
;; else call the handler
(if (fboundp (setq fun (intern
(concat "irchat-ctl-a-" message "-msg"))))
(progn
(eval (list fun from rest-of-line)))
(message (format
"IRCHAT: Unknown CLIENT message from %s \"%s\""
from (upcase message)))))))))
(defun irchat-ctl-a-version-msg (from chnl rest)
(if (not (equal 'none irchat-external-version-string))
(let ((version-string
(if (not (stringp irchat-external-version-string))
(if irchat-use-ancient-version-format
(format "%s %s :%s for %s"
irchat-version
irchat-emacs-version-name
irchat-version
irchat-emacs-version-name)
(format "%s :%s for %s"
irchat-version
irchat-client-name
irchat-emacs-version-name))
irchat-external-version-string)))
(irchat-send-delayed (format "NOTICE %s :VERSION %s"
from
version-string))))
(if (string-ci-equal chnl irchat-real-nickname)
(message (format "CLIENT VERSION query from %s%s."
from
(if (equal 'none irchat-external-version-string)
". Ignored" "")))
(message (format "CLIENT VERSION query from %s (%s)%s."
from
chnl
(if (equal 'none irchat-external-version-string)
". Ignored" "")))))
(defun irchat-ctl-a-userinfo-msg (from chnl rest)
(irchat-send-delayed "NOTICE %s :USERINFO %s"
from irchat-client-userinfo)
(message (format "CLIENT USERINFO query from %s." from)))
(defun irchat-ctl-a-clientinfo-msg (from chnl rest)
(irchat-send-delayed
(format
"NOTICE %s :CLIENTINFO :VERSION USERINFO CLIENTINFO X-FACE HELP ERRMSG" from))
(message (format "CLIENT CLIENTINFO query from %s." from)))
(defun irchat-ctl-a-help-msg (from chnl rest)
(irchat-send-delayed
(format
"NOTICE %s :HELP :VERSION gives version of this client"
from))
(irchat-send-delayed
(format
"NOTICE %s :HELP :USERINFO gives user supplied info (if any)"
from))
(irchat-send-delayed
(format
"NOTICE %s :HELP :CLIENTINFO gives commands this client knows"
from))
(irchat-send-delayed
(format
"NOTICE %s :HELP :X-FACE gives you user supplied X-Face (if exists)"
from))
(irchat-send-delayed
(format
"NOTICE %s :HELP :HELP gives this help message"
from))
(irchat-send-delayed
(format
"NOTICE %s :HELP :ERRMSG tells you your command was not valid"
from))
(message (format "CLIENT HELP query from %s." from)))
(defun irchat-ctl-a-comment-msg (from chnl rest)
(message (format "CLIENT COMMENT query from %s." from)))
(defun irchat-ctl-a-xyzzy-msg (from chnl rest)
(irchat-send-delayed "NOTICE %s :Nothing happens.(xyzzy inactive)" from)
(message (format "CLIENT XYZZY query from %s." from)))
(defun irchat-ctl-a-ping-msg (from chnl rest)
(if (not rest)
(setq rest ""))
(irchat-send-delayed "NOTICE %s :PING %s" from rest)
(message (format "CLIENT PING query from %s." from)))
(defun irchat-ctl-a-x-face-msg (from chnl rest)
(irchat-send-delayed "NOTICE %s :X-FACE %s"
from irchat-client-x-face)
(message (format "CLIENT X-FACE query from %s." from)))
;;;
;;; read CLIENT messages from notice, no postprocessing done
;;;
(defun irchat-ctl-a-notice (prefix rest)
"Ctl-a notice."
(let* (message rest-of-line hook)
(if (string-match "\\([^ ]*\\) \\(.*\\)" rest)
(setq message (downcase (matching-substring rest 1))
rest-of-line (matching-substring rest 2))
(if (string-match "\\([^ ]*\\)" rest)
(setq message (downcase (matching-substring rest 1))
rest-of-line nil)
(setq message "errmsg"
rest-of-line "Couldn't figure out what was said.")))
(if (and (boundp
(setq hook
(intern (concat "irchat-ctl-a-" message "-notice-hook"))))
(eval hook)
(eq (eval (list hook prefix rest-of-line)) t))
;; If we have a hook, and it returns T, do nothing more
nil
;; else call the handler
(if (fboundp (setq fun (intern
(concat "irchat-ctl-a-" message "-notice"))))
(progn
(eval (list fun prefix rest-of-line)))
(message (format
"IRCHAT: Unknown ctl-a notice \":%s %s %s\""
prefix (upcase message) rest-of-line))))))
(defun irchat-ctl-a-file-notice (prefix rest)
(if irchat-file-accept
(let* (message file-name rest-of-line hook)
(string-match "^\\([^ ]*\\) \\([^ ]*\\) :\\(.*\\)" rest)
(setq message (downcase (matching-substring rest 1)))
(setq file-name (matching-substring rest 2))
(setq rest-of-line (matching-substring rest 3))
(if (and (boundp
(setq hook
(intern (concat "irchat-file-" message "-hook"))))
(eval hook)
(eq (eval (list hook prefix file-name rest-of-line)) t))
;; If we have a hook, and it returns T, do nothing more
nil
;; else call the handler
(if (fboundp (setq fun (intern
(concat "irchat-file-" message))))
(progn
(eval (list fun prefix file-name rest-of-line)))
(message (format
"IRCHAT: Unknown FILE message \":%s %s %s %s\""
prefix (upcase message) file-name rest-of-line)))))
(message (format
"FILE: %s sending, set irchat-file-accept and ask to resend"
prefix))))
(defun irchat-file-start (prefix name data)
(save-excursion
(set-buffer (get-buffer-create (format "*IRC R_FILE_%s*" name)))
(delete-region (point-min) (point-max))
(insert data)))
(defun irchat-file-cont (prefix name data)
(save-excursion
(set-buffer (get-buffer-create (format "*IRC R_FILE_%s*" name)))
(goto-char (point-max))
(insert data)))
(defun irchat-file-end (prefix name data)
(save-excursion
(set-buffer (get-buffer-create (format "*IRC R_FILE_%s*" name)))
(goto-char (point-max))
(insert data)
(let (str)
(setq str (buffer-string))
(delete-region (point-min) (point-max))
(insert (irchat-quote-decode str)))
(goto-char (point-min))
(if (and irchat-file-confirm-save
(not (y-or-n-p "Save file?")))
nil
(progn
(if (not (file-exists-p "~/.irchat"))
(shell-command (format "mkdir %s"
(expand-file-name ".irchat" "$HOME"))))
(write-region (point-min) (point-max) (expand-file-name
(file-name-nondirectory
(format "%s(%s)" name prefix))
"~/.irchat"))
(kill-buffer (get-buffer-create (format "*IRC R_FILE_%s*" name)))))))
(defun irchat-ctl-a-client-notice (prefix rest)
(let* (message rest-of-line hook)
(if (string-match "^\\([^ ]*\\) \\(.*\\)" rest)
(setq message (downcase (matching-substring rest 1))
rest-of-line (matching-substring rest 2))
(if (string-match "^\\([^ ]*\\)" rest)
(setq message (downcase (matching-substring rest 1))
rest-of-line nil)
(setq message "errmsg"
rest-of-line "Couldn't figure out what was said.")))
(if (and (boundp (setq hook
(intern (concat
"irchat-client-" message "-notice-hook"))))
(eval hook)
(eq (eval (list hook prefix rest-of-line)) t))
;; If we have a hook, and it returns T, do nothing more
nil
;; else call the handler
(if (fboundp (setq fun (intern
(concat "irchat-client-" message "-notice"))))
(progn
(eval (list fun prefix rest-of-line)))
(message (format
"IRCHAT: Unknown CLIENT notice \":%s %s %s %s\""
prefix (upcase message) rest-of-line))))))
(defvar irchat-client-message "CLIENT@%s: %s\n"
"*Message in which info of other clients is displayed.")
(defun irchat-client-version-notice (prefix rest)
(if rest
(if (string-match "^\\([^:]*\\):\\(.*\\)" rest)
(irchat-w-insert irchat-D-buffer
(format irchat-client-message prefix
(concat (matching-substring rest 1)
(matching-substring rest 2))))
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(message (format "Empty CLIENT version notice from \"%s\"." prefix))))
(defun irchat-client-clientinfo-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-client-userinfo-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-client-help-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-client-x-face-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-client-errmsg-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-client-comment-notice (from rest)
(message (format "CLIENT COMMENT query from %s." from)))
(defun irchat-client-ping-notice (from rest)
(let ((timenow (current-time)))
(irchat-w-insert
irchat-Dialogue-buffer
(format
"PING time from %s: %ds\n"
from
(+ (* 65536 (- (car timenow) (car irchat-ctcp-ping-time)))
(- (car (cdr timenow)) (car (cdr irchat-ctcp-ping-time))))))))
;;;
(defun irchat-ctl-a-version-notice (prefix rest)
(if rest
(if (string-match "^\\([^:]*\\):\\(.*\\)" rest)
(irchat-w-insert irchat-D-buffer
(format irchat-client-message prefix
(concat (matching-substring rest 1)
(matching-substring rest 2))))
(if (string-match "^\\([^ ]*\\) \\([^ ]*\\) \\([^ ]*\\) \\(.*\\)" rest)
(irchat-w-insert irchat-D-buffer
(format irchat-client-message
prefix
(format "%s %s for %s: %s"
(matching-substring rest 1)
(matching-substring rest 2)
(matching-substring rest 3)
(matching-substring rest 4))))
(irchat-w-insert irchat-D-buffer
(format irchat-client-message prefix rest))))
(message (format "Empty CLIENT version notice from \"%s\"." prefix))))
(defun irchat-ctl-a-clientinfo-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-ctl-a-userinfo-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-ctl-a-help-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-ctl-a-errmsg-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-ctl-a-x-face-notice (prefix rest)
(irchat-w-insert irchat-D-buffer (format irchat-client-message prefix rest)))
(defun irchat-ctl-a-comment-notice (from rest)
(message (format "CLIENT COMMENT query from %s." from)))
(defun irchat-ctl-a-ping-notice (from rest)
(let ((timenow (current-time)))
(irchat-w-insert
irchat-Dialogue-buffer
(format
"PING time from %s: %ds\n"
from
(+ (* 65536 (- (car timenow) (car irchat-ctcp-ping-time)))
(- (car (cdr timenow)) (car (cdr irchat-ctcp-ping-time))))))))
(eval-and-compile
(provide 'irchat-cta))
;;;
;;; eof
;;;