updated setup for latest apache script dependency
[iankelling.org] / iank-mod.el
1 ;; Copyright (C) 2016 Ian Kelling
2
3 ;; This program is free software: you can redistribute it and/or modify
4 ;; it under the terms of the GNU General Public License as published by
5 ;; the Free Software Foundation, either version 3 of the License, or
6 ;; (at your option) any later version.
7
8 ;; This program is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details.
12
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17 ;; generally, use m-x iankmod-start. c-u to run on local testing
18 ;; instance. Alternatively, run get-comments with whatever args,
19 ;; manually open /tmp/hcomments, then run (iankmod).
20
21 (defun iankmod-start (arg)
22 (interactive "P")
23 (setq iankmod-last-arg (if (equal arg '(4)) " -l" ""))
24 (let ((cmd (concat "/a/h/get-comments" iankmod-last-arg)))
25 (shell-command cmd "*messages*")
26 (find-file "/tmp/hcomments")
27 (iankmod 1)))
28
29 (defun iankmod-save ()
30 (interactive)
31 (basic-save-buffer)
32 (let ((cmd (concat "/a/h/set-comments" iankmod-last-arg)))
33 (shell-command cmd "*messages*")))
34
35
36 (defun iankmod-set-state (state)
37 (beginning-of-line)
38 (re-search-forward "|" nil t)
39 (re-search-forward "[^|]*" nil t)
40 (replace-match state)
41 (forward-line))
42
43 (defun iankmod-pick ()
44 (interactive)
45 (iankmod-set-state "picked"))
46
47 (defun iankmod-ban ()
48 (interactive)
49 (iankmod-set-state "banned"))
50
51 ;; for test comments, or comments we just want to delete from the
52 ;; db for whatever reason.
53 (defun iankmod-delete ()
54 (interactive)
55 (iankmod-set-state "delete"))
56
57 (defun iankmod-moderate ()
58 (interactive)
59 (iankmod-set-state "moderated"))
60
61 (define-minor-mode iankmod
62 "Moderation of comments for iankelling.org"
63 :keymap (let ((map (make-sparse-keymap)))
64 (define-key map (kbd "p") 'iankmod-pick)
65 (define-key map (kbd "b") 'iankmod-ban)
66 (define-key map (kbd "m") 'iankmod-moderate)
67 (define-key map (kbd "x") 'iankmod-save)
68 (define-key map (kbd "d") 'iankmod-delete)
69 map))