diff -uNr a/logbot.lisp b/logbot.lisp --- a/logbot.lisp 95a0046c0af25e21dba310217a289d7649dd86cb89709a89931bfe318a41022ffd4ba9dc046e04dac1b32bc5304239866bf5ca9ad59328b7da79b1d06437e273 +++ b/logbot.lisp 19835de2ebf3dc6a70796058ba4a79a4e4cf17ca993b73a97e821a0056d717285f5d1e3a40ecc0ef03efd1fdfaeeed7b5ed2fb43113866cb12b849091753b5cb @@ -1,17 +1,17 @@ (in-package #:logbot) -(defun get-and-purge-outbox-messages (db) +(defun get-and-purge-outbox-messages (db target) (postmodern:with-connection db (postmodern:query "with deleted as ( delete from outbox - returning target, message, queued_at + where target = $1 + returning message, queued_at ) - select target, - message + select message from deleted - order by queued_at" + order by queued_at" target :rows))) (defun make-log-entry (db target message host source user) @@ -57,18 +57,18 @@ (if (= 3 (length (arguments message))) (destructuring-bind (channel mode nick) (arguments message) (when (and (string= (host message) "services.") - (string= channel (ircbot-channel bot)) + (member channel (ircbot-channels bot) :test #'string=) (or (string= mode "+o") (string= mode "+v")) (string= nick (ircbot-nick bot))) (when (null (logbot-pg-thread bot)) (logbot-start-pg-thread bot) - (logbot-send-outbox bot)))))) + (logbot-send-outbox bot channel)))))) -(defmethod logbot-send-outbox ((bot logbot)) +(defmethod logbot-send-outbox ((bot logbot) target) (loop - for (target message) - in (get-and-purge-outbox-messages (logbot-db bot)) + for (message) + in (get-and-purge-outbox-messages (logbot-db bot) target) do (ircbot-send-message bot target message))) (defmethod logbot-start-pg-thread ((bot logbot)) @@ -78,16 +78,19 @@ (postmodern:with-connection (logbot-db bot) (postmodern:execute "listen outbox_new_message") (loop - (if (string= (cl-postgres:wait-for-notification postmodern:*database*) - "outbox_new_message") - (logbot-send-outbox bot))))) + (multiple-value-bind (channel payload pid) + (cl-postgres:wait-for-notification postmodern:*database*) + (declare (ignore pid)) + (if (string= channel + "outbox_new_message") + (logbot-send-outbox bot payload)))))) :name "logbot-pg"))) -(defun make-logbot (server port nick password channel db) +(defun make-logbot (server port nick password channels db) (make-instance 'logbot :server server :port port :nick nick :password password - :channel channel + :channels channels :db db)) diff -uNr a/logbot.sql b/logbot.sql --- a/logbot.sql dbc265a63c34c6b682694c8776aa4640c83ba92dca5400f0bd393f6a9eb5d3672011c234c3d04a7ad074f3fce560d71d78201f4bbcb506c12ed6cc90d3c59017 +++ b/logbot.sql 83bd0ba610a945ca03644bb5ea7304ac61d04622920c42dea741eae7ad22c10f6a2b00994832898f6706d2b1608a23acc26fc2af1cae17837ee7739eae36797e @@ -28,7 +28,7 @@ create trigger log_insert_notify_trigger after insert on log for each row execute procedure log_insert_notify (); - + create table outbox ( id serial primary key, target text not null, @@ -38,7 +38,7 @@ create or replace function outbox_insert_notify () returns trigger as $$ begin - perform pg_notify('outbox_new_message', NEW.id::text); + perform pg_notify('outbox_new_message', NEW.target::text); return NEW; end; $$ language plpgsql; diff -uNr a/package.lisp b/package.lisp --- a/package.lisp 29a3142e5a5a5b814921b49c16571b2d0359cdca2dfdc9ca4463734f066b1e087a4ececb6341f1667ef26f6a97b0b8ce326cedaf2539d2cfd64ca4c3fb6551df +++ b/package.lisp ed9e56e8bdcca12fa144c095493602ff389977ed28cf6df0185b474eefd151cc0fe211824d7de480d4499a9c013144ead41cc962a8b96dea7b84b2f68bab3569 @@ -11,10 +11,9 @@ :ircbot-disconnect :ircbot-reconnect :ircbot-connection - :ircbot-channel + :ircbot-channels :ircbot-send-message :ircbot-server :ircbot-port :ircbot-nick :ircbot-lag)) -