| 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 |
(require 'erc) |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
(define-erc-module page ctcp-page |
|---|
| 35 |
"Process CTCP PAGE requests from IRC." |
|---|
| 36 |
nil nil) |
|---|
| 37 |
|
|---|
| 38 |
(erc-define-catalog-entry 'english 'CTCP-PAGE "Page from %n (%u@%h): %m") |
|---|
| 39 |
|
|---|
| 40 |
(defgroup erc-page nil |
|---|
| 41 |
"React to CTCP PAGE messages." |
|---|
| 42 |
:group 'erc) |
|---|
| 43 |
|
|---|
| 44 |
(defcustom erc-page-function nil |
|---|
| 45 |
"A function to process a \"page\" request. |
|---|
| 46 |
If nil, this prints the page message in the minibuffer and calls |
|---|
| 47 |
`beep'. If non-nil, it must be a function that takes two arguments: |
|---|
| 48 |
SENDER and MSG, both strings. |
|---|
| 49 |
|
|---|
| 50 |
Example for your ~/.emacs file: |
|---|
| 51 |
|
|---|
| 52 |
\(setq erc-page-function |
|---|
| 53 |
(lambda (sender msg) |
|---|
| 54 |
(play-sound-file \"/home/alex/elisp/erc/sounds/ni.wav\") |
|---|
| 55 |
(message \"IRC Page from %s: %s\" sender msg)))" |
|---|
| 56 |
:group 'erc-page |
|---|
| 57 |
:type '(choice (const nil) |
|---|
| 58 |
(function))) |
|---|
| 59 |
|
|---|
| 60 |
(defcustom erc-ctcp-query-PAGE-hook '(erc-ctcp-query-PAGE) |
|---|
| 61 |
"List of functions to be called when a CTCP PAGE is received. |
|---|
| 62 |
This is called from `erc-process-ctcp-query'. The functions are called |
|---|
| 63 |
with six arguments: PROC NICK LOGIN HOST TO MSG. Note that you can |
|---|
| 64 |
also set `erc-page-function' to a function, which only gets two arguments, |
|---|
| 65 |
SENDER and MSG, so that might be easier to use." |
|---|
| 66 |
:group 'erc-page |
|---|
| 67 |
:type '(repeat function)) |
|---|
| 68 |
|
|---|
| 69 |
(defun erc-ctcp-query-PAGE (proc nick login host to msg) |
|---|
| 70 |
"Deal with an CTCP PAGE query, if `erc-page-mode' is non-nil. |
|---|
| 71 |
This will call `erc-page-function', if defined, or it will just print |
|---|
| 72 |
a message and `beep'. In addition to that, the page message is also |
|---|
| 73 |
inserted into the server buffer." |
|---|
| 74 |
(when (and erc-page-mode |
|---|
| 75 |
(string-match "PAGE\\(\\s-+.*\\)?$" msg)) |
|---|
| 76 |
(let* ((m (match-string 1 msg)) |
|---|
| 77 |
(page-msg (if m (erc-controls-interpret (substring m 1)) |
|---|
| 78 |
"[no message]")) |
|---|
| 79 |
text) |
|---|
| 80 |
(if m (setq m (substring m 1))) |
|---|
| 81 |
(setq text (erc-format-message 'CTCP-PAGE |
|---|
| 82 |
?n nick ?u login |
|---|
| 83 |
?h host ?m page-msg)) |
|---|
| 84 |
(if erc-page-function |
|---|
| 85 |
(funcall erc-page-function nick page-msg) |
|---|
| 86 |
|
|---|
| 87 |
(message "%s" text) |
|---|
| 88 |
(beep)) |
|---|
| 89 |
|
|---|
| 90 |
(erc-display-message |
|---|
| 91 |
nil 'notice nil text))) |
|---|
| 92 |
nil) |
|---|
| 93 |
|
|---|
| 94 |
(defun erc-cmd-PAGE (line &optional force) |
|---|
| 95 |
"Send a CTCP page to the user given as the first word in LINE. |
|---|
| 96 |
The rest of LINE is the message to send. Note that you will only |
|---|
| 97 |
receive pages if `erc-page-mode' is on." |
|---|
| 98 |
(when (string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line) |
|---|
| 99 |
(let ((nick (match-string 1 line)) |
|---|
| 100 |
(msg (match-string 2 line))) |
|---|
| 101 |
(erc-cmd-CTCP nick "PAGE" msg)))) |
|---|
| 102 |
|
|---|
| 103 |
(put 'erc-cmd-PAGE 'do-not-parse-args t) |
|---|
| 104 |
|
|---|
| 105 |
(provide 'erc-page) |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|