Commit | Line | Data |
---|---|---|
597993cf MB |
1 | ;; erc-page.el - CTCP PAGE support for ERC |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2002, 2004, 2006-2014 Free Software Foundation, Inc. |
597993cf | 4 | |
34dc21db | 5 | ;; Maintainer: emacs-devel@gnu.org |
df5d5f59 | 6 | |
597993cf MB |
7 | ;; This file is part of GNU Emacs. |
8 | ||
4ee57b2a | 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
597993cf | 10 | ;; it under the terms of the GNU General Public License as published by |
4ee57b2a GM |
11 | ;; the Free Software Foundation, either version 3 of the License, or |
12 | ;; (at your option) any later version. | |
597993cf MB |
13 | |
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
4ee57b2a | 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
597993cf MB |
21 | |
22 | ;;; Commentary: | |
23 | ||
24 | ;; Requiring this file will make ERC react to CTCP PAGE messages | |
25 | ;; received, and it will provide a new /PAGE command to send such | |
26 | ;; messages yourself. To enable it, customize the variable | |
27 | ;; `erc-page-mode'. | |
28 | ||
29 | ;;; Code: | |
30 | ||
31 | (require 'erc) | |
32 | ||
33 | ;;;###autoload (autoload 'erc-page-mode "erc-page") | |
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 | ||
865fe16f | 50 | Example for your init file: |
597993cf MB |
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 | ;; if no function is defined | |
87 | (message "%s" text) | |
88 | (beep)) | |
89 | ;; insert text into buffer | |
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 | ||
597993cf | 107 | ;;; erc-page.el ends here |
5e56b3fb MO |
108 | ;; |
109 | ;; Local Variables: | |
110 | ;; indent-tabs-mode: t | |
111 | ;; tab-width: 8 | |
112 | ;; End: | |
113 |