-
Notifications
You must be signed in to change notification settings - Fork 0
/
cybercritic.lisp
120 lines (106 loc) · 4.26 KB
/
cybercritic.lisp
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
;; cybercritic.lisp - The main generate-and-blog code.
;; Copyright (C) 2009 Rob Myers rob@robmyers.org
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :cybercritic)
(defclass cybercritic (microblog-bot:daily-task-bot
microblog-bot:microblog-follower-bot)
((aesthetic :initarg :aesthetic
:accessor cybercritic-aesthetic)))
(defmethod serialise ((bot cybercritic))
"Serialise the bot to the alist"
(call-next-method)
(list* (cons 'cybercritic-aesthetic
(aesthetic:serialise-aesthetic (cybercritic-aesthetic bot)))
(call-next-method)))
(defmethod deserialise ((bot cybercritic) alist)
"Deserialise the bot from the alist, providing defaults when value absent"
(call-next-method)
(setf (cybercritic-aesthetic bot)
(or (aesthetic:deserialise-aesthetic (assoc 'cybercritic-aesthetic
alist))
(aesthetic:make-aesthetic))))
(defmethod post-aesthetic ((bot cybercritic))
"Post a description of the bot's aesthetic"
(multiple-value-bind (good bad)
(aesthetic:describe-aesthetic (cybercritic-aesthetic bot))
(let ((desc (concatenate 'string good " " bad)))
;; If the description is short enough to post all in one go, do so
(if (<= (length desc) 140)
(microblog-bot:queue-update bot desc)
;; Otherwise post in two sections, truncating if they are too long
(progn
(when (> (length good) 140)
(setf good
(format nil "~a..." (subseq good 0 137))))
(microblog-bot:queue-update bot good)
(when (> (length bad) 140)
(setf bad
(format nil "~a..." (subseq bad 0 137))))
(microblog-bot:queue-update bot bad))))))
(defmethod microblog-bot:daily-task ((bot cybercritic))
"Update the aesthetic and dent it."
(aesthetic:update-aesthetic (cybercritic-aesthetic bot))
(post-aesthetic bot))
(defmethod microblog-bot:filter-posts ((bot cybercritic) posts)
"Ignore @replies."
(loop for post in posts
if (not (response-p bot post))
collect post))
(defmethod microblog-bot:response-for-post ((bot cybercritic) mention)
"Respond to the artwork by critiquing it."
(critique-artwork (cl-twit:status-text mention)
(cybercritic-aesthetic bot)
(format nil
"http://identi.ca/notice/~a"
(cl-twit:status-id mention))))
(defvar *username* nil)
(defvar *password* nil)
(defvar *follow* nil)
(defun configure (username password follow
&optional (host "https://identi.ca/api"))
"Configure the global state."
(setf *random-state* (make-random-state t))
(microblog-bot:set-microblog-service host "cybercritic")
(setf *username* username)
(setf *password* password)
(setf *follow* follow))
(defun cli-configure ()
"Configure from the command line arguments."
(assert (>= (length sb-ext:*posix-argv*) 3))
(configure (second sb-ext:*posix-argv*)
(third sb-ext:*posix-argv*)
(fourth sb-ext:*posix-argv*)))
(defun make-microblog-bot ()
(assert (and *username* *password* *follow*))
(let ((bot (make-instance 'cybercritic
:nickname *username*
:password *password*
:follow-screen-name *follow*
:source-url
"http://robmyers.org/git/?p=cybernetic-artworld.git"
:aesthetic (aesthetic:make-aesthetic))))
(microblog-bot:with-microblog-user bot
(post-aesthetic bot)
;; Publish the aesthetic straight away
(microblog-bot::post-updates bot))
bot))
(defun run-cybercritic ()
"Configure and run the bot"
(cli-configure)
(microblog-bot:run-bot (make-microblog-bot)))
(defun test-run-cybercritic (username password follow)
(require 'cybercritic)
(configure username password follow "http://localhost/laconica/api")
(microblog-bot:test-run-bot (make-microblog-bot) 10 :post t))