- 34C09AAE0020F81B9DD9A9120DAE84C0E996B578041E837785E814409F69D0D587A21C0C1454C6E39039C8CA3FD135092D4EFD006F39F0E47AC87F0314F6F92D+ 19835DE2EBF3DC6A70796058BA4A79A4E4CF17CA993B73A97E821A0056D717285F5D1E3A40ECC0EF03EFD1FDFAEEED7B5ED2FB43113866CB12B849091753B5CBlogbot/logbot.lisp(1 . 17)(1 . 17)
5 (in-package #:logbot)
6
7
8 (defun get-and-purge-outbox-messages (db)
9 (defun get-and-purge-outbox-messages (db target)
10 (postmodern:with-connection db
11 (postmodern:query
12 "with deleted as (
13 delete from outbox
14 returning target, message, queued_at
15 where target = $1
16 returning message, queued_at
17 )
18 select target,
19 message
20 select message
21 from deleted
22 order by queued_at"
23 order by queued_at" target
24 :rows)))
25
26 (defun make-log-entry (db target message host source user)
(31 . 7)(31 . 7)
28 (db :reader logbot-db :initarg :db)))
29
30 (defmethod ircbot-connect :after ((bot logbot))
31 (let ((conn (ircbot-connection bot)))
32 (let ((conn (ircbot-connection bot)))
33 (add-hook conn 'irc-mode-message (lambda (message)
34 (logbot-check-mode bot message)))
35 (add-hook conn 'irc-privmsg-message (lambda (message)
(57 . 18)(57 . 18)
37 (if (= 3 (length (arguments message)))
38 (destructuring-bind (channel mode nick) (arguments message)
39 (when (and (string= (host message) "services.")
40 (string= channel (ircbot-channel bot))
41 (member channel (ircbot-channels bot) :test #'string=)
42 (or (string= mode "+o") (string= mode "+v"))
43 (string= nick (ircbot-nick bot)))
44
45 (when (null (logbot-pg-thread bot))
46 (logbot-start-pg-thread bot)
47 (logbot-send-outbox bot))))))
48 (logbot-send-outbox bot channel))))))
49
50 (defmethod logbot-send-outbox ((bot logbot))
51 (defmethod logbot-send-outbox ((bot logbot) target)
52 (loop
53 for (target message)
54 in (get-and-purge-outbox-messages (logbot-db bot))
55 for (message)
56 in (get-and-purge-outbox-messages (logbot-db bot) target)
57 do (ircbot-send-message bot target message)))
58
59 (defmethod logbot-start-pg-thread ((bot logbot))
(78 . 16)(78 . 19)
61 (postmodern:with-connection (logbot-db bot)
62 (postmodern:execute "listen outbox_new_message")
63 (loop
64 (if (string= (cl-postgres:wait-for-notification postmodern:*database*)
65 "outbox_new_message")
66 (logbot-send-outbox bot)))))
67 (multiple-value-bind (channel payload pid)
68 (cl-postgres:wait-for-notification postmodern:*database*)
69 (declare (ignore pid))
70 (if (string= channel
71 "outbox_new_message")
72 (logbot-send-outbox bot payload))))))
73 :name "logbot-pg")))
74
75 (defun make-logbot (server port nick password channel db)
76 (defun make-logbot (server port nick password channels db)
77 (make-instance 'logbot
78 :server server
79 :port port
80 :nick nick
81 :password password
82 :channel channel
83 :channels channels
84 :db db))