| 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 |
(require 'erc) |
|---|
| 69 |
(eval-when-compile (require 'cl)) |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
(defgroup erc-capab nil |
|---|
| 74 |
"Support for dancer-ircd's CAPAB settings." |
|---|
| 75 |
:group 'erc) |
|---|
| 76 |
|
|---|
| 77 |
(defcustom erc-capab-identify-prefix "*" |
|---|
| 78 |
"The prefix used for unidentified users. |
|---|
| 79 |
|
|---|
| 80 |
If you change this from the default \"*\", be sure to use a |
|---|
| 81 |
character not found in IRC nicknames to avoid confusion." |
|---|
| 82 |
:group 'erc-capab |
|---|
| 83 |
:type '(choice string (const nil))) |
|---|
| 84 |
|
|---|
| 85 |
(defface erc-capab-identify-unidentified '((t)) |
|---|
| 86 |
"Face to use for `erc-capab-identify-prefix'." |
|---|
| 87 |
:group 'erc-capab |
|---|
| 88 |
:group 'erc-faces) |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
(define-erc-module capab-identify nil |
|---|
| 94 |
"Handle dancer-ircd's CAPAB IDENTIFY-MSG and IDENTIFY-CTCP." |
|---|
| 95 |
|
|---|
| 96 |
((add-hook 'erc-server-005-functions 'erc-capab-identify-setup t) |
|---|
| 97 |
(add-hook 'erc-server-290-functions 'erc-capab-identify-activate) |
|---|
| 98 |
(add-hook 'erc-server-PRIVMSG-functions |
|---|
| 99 |
'erc-capab-identify-remove/set-identified-flag) |
|---|
| 100 |
(add-hook 'erc-server-NOTICE-functions |
|---|
| 101 |
'erc-capab-identify-remove/set-identified-flag) |
|---|
| 102 |
(add-hook 'erc-insert-modify-hook 'erc-capab-identify-add-prefix t) |
|---|
| 103 |
(mapc (lambda (buffer) |
|---|
| 104 |
(when buffer |
|---|
| 105 |
(with-current-buffer buffer (erc-capab-identify-setup)))) |
|---|
| 106 |
(erc-buffer-list 'erc-open-server-buffer-p))) |
|---|
| 107 |
((remove-hook 'erc-server-005-functions 'erc-capab-identify-setup) |
|---|
| 108 |
(remove-hook 'erc-server-290-functions 'erc-capab-identify-activate) |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
(remove-hook 'erc-insert-modify-hook 'erc-capab-identify-add-prefix))) |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
(defvar erc-capab-identify-activated nil |
|---|
| 116 |
"CAPAB IDENTIFY-MSG has been activated.") |
|---|
| 117 |
(make-variable-buffer-local 'erc-capab-identify-activated) |
|---|
| 118 |
|
|---|
| 119 |
(defvar erc-capab-identify-sent nil |
|---|
| 120 |
"CAPAB IDENTIFY-MSG and IDENTIFY-CTCP messages have been sent.") |
|---|
| 121 |
(make-variable-buffer-local 'erc-capab-identify-sent) |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
(defun erc-capab-identify-setup (&optional proc parsed) |
|---|
| 126 |
"Set up CAPAB IDENTIFY on the current server. |
|---|
| 127 |
|
|---|
| 128 |
Optional argument PROC is the current server's process. |
|---|
| 129 |
Optional argument PARSED is the current message, a response struct. |
|---|
| 130 |
|
|---|
| 131 |
These arguments are sent to this function when called as a hook in |
|---|
| 132 |
`erc-server-005-functions'." |
|---|
| 133 |
(unless erc-capab-identify-sent |
|---|
| 134 |
(erc-capab-identify-send-messages))) |
|---|
| 135 |
|
|---|
| 136 |
(defun erc-capab-identify-send-messages () |
|---|
| 137 |
"Send CAPAB IDENTIFY messages if the server supports it." |
|---|
| 138 |
(when (and (stringp erc-server-version) |
|---|
| 139 |
(string-match "^\\(dancer-ircd\\|hyperion\\)" erc-server-version) |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
(assoc "CAPAB" erc-server-parameters)) |
|---|
| 144 |
(erc-log "Sending CAPAB IDENTIFY-MSG and IDENTIFY-CTCP") |
|---|
| 145 |
(erc-server-send "CAPAB IDENTIFY-MSG") |
|---|
| 146 |
(erc-server-send "CAPAB IDENTIFY-CTCP") |
|---|
| 147 |
(setq erc-capab-identify-sent t))) |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
(defun erc-capab-identify-activate (proc parsed) |
|---|
| 151 |
"Set `erc-capab-identify-activated' and display an activation message. |
|---|
| 152 |
|
|---|
| 153 |
PROC is the current server's process. |
|---|
| 154 |
PARSED is an `erc-parsed' response struct." |
|---|
| 155 |
(when (or (string= "IDENTIFY-MSG" (erc-response.contents parsed)) |
|---|
| 156 |
(string= "IDENTIFY-CTCP" (erc-response.contents parsed))) |
|---|
| 157 |
(setq erc-capab-identify-activated t) |
|---|
| 158 |
(erc-display-message |
|---|
| 159 |
parsed 'notice 'active (format "%s activated" |
|---|
| 160 |
(erc-response.contents parsed))))) |
|---|
| 161 |
|
|---|
| 162 |
(defun erc-capab-identify-remove/set-identified-flag (proc parsed) |
|---|
| 163 |
"Remove PARSED message's id flag and add the `erc-identified' text property. |
|---|
| 164 |
|
|---|
| 165 |
PROC is the current server's process. |
|---|
| 166 |
PARSED is an `erc-parsed' response struct." |
|---|
| 167 |
(let ((msg (erc-response.contents parsed))) |
|---|
| 168 |
(when (and erc-capab-identify-activated |
|---|
| 169 |
(string-match "^\\([-\\+]\\)\\(.+\\)$" msg)) |
|---|
| 170 |
(setf (erc-response.contents parsed) |
|---|
| 171 |
(if erc-capab-identify-mode |
|---|
| 172 |
(erc-propertize (match-string 2 msg) |
|---|
| 173 |
'erc-identified |
|---|
| 174 |
(if (string= (match-string 1 msg) "+") |
|---|
| 175 |
1 |
|---|
| 176 |
0)) |
|---|
| 177 |
(match-string 2 msg))) |
|---|
| 178 |
nil))) |
|---|
| 179 |
|
|---|
| 180 |
(defun erc-capab-identify-add-prefix () |
|---|
| 181 |
"Add `erc-capab-identify-prefix' to nickname if user is unidentified." |
|---|
| 182 |
(when (and erc-capab-identify-prefix |
|---|
| 183 |
(erc-with-server-buffer erc-capab-identify-activated)) |
|---|
| 184 |
(goto-char (or (erc-find-parsed-property) (point-min))) |
|---|
| 185 |
(let ((nickname (erc-capab-identify-get-unidentified-nickname |
|---|
| 186 |
(erc-get-parsed-vector (point))))) |
|---|
| 187 |
(when (and nickname |
|---|
| 188 |
(goto-char (point-min)) |
|---|
| 189 |
|
|---|
| 190 |
(re-search-forward (regexp-quote nickname) nil t)) |
|---|
| 191 |
(goto-char (match-beginning 0)) |
|---|
| 192 |
(insert (erc-propertize erc-capab-identify-prefix |
|---|
| 193 |
'face 'erc-capab-identify-unidentified)))))) |
|---|
| 194 |
|
|---|
| 195 |
(defun erc-capab-identify-get-unidentified-nickname (parsed) |
|---|
| 196 |
"Return the nickname of the user if unidentified. |
|---|
| 197 |
PARSED is an `erc-parsed' response struct." |
|---|
| 198 |
(when (and (erc-response-p parsed) |
|---|
| 199 |
(equal 0 (get-text-property 0 'erc-identified |
|---|
| 200 |
(erc-response.contents parsed)))) |
|---|
| 201 |
(let ((nickuserhost (erc-get-parsed-vector-nick parsed))) |
|---|
| 202 |
(when nickuserhost |
|---|
| 203 |
(nth 0 (erc-parse-user nickuserhost)))))) |
|---|
| 204 |
|
|---|
| 205 |
(provide 'erc-capab) |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|