vandusen plugin mod 1 added by elf on Tue Feb 23 11:59:57 2021

(module vandusen-spam
  ()

(import chicken scheme)
(use vandusen irc sql-de-lite)

(plugin 'spam
  (lambda ()
    (define paste-db-file
      (or (and ($ 'paste-db-file) (car ($ 'paste-db-file)))
          "/var/awful/pastiche/pastiche.db"))
    (command 'spam
      '(: "spam" (+ space) (submatch (= 40 alnum))) ;; our sha1 hashes are 40 chars long
      (lambda (master hash)
        (cond ((file-exists? paste-db-file)
                (let* ((db (open-database paste-db-file))
                       (deleted-entries
                         (begin
                           (exec (sql db "delete from searchable where hash=?") hash)
                           (exec (sql db "update pastes set author='spam', title='Deleted Spam', paste='<p>This paste has been deleted as spam.</p><p>Please be more careful where you click in future.</p>' where hash=?") hash))))
                  (if (zero? deleted-entries)
                      (reply-to master "Could not find an entry with that hash")
                      (reply-to master (format "I have deleted ~a paste(s) with hash ~a successfully." deleted-entries hash)))
                  (close-database db)))
              (else (reply-to master (format "Cannot find database at ~a" paste-db-file)))))
       public: #f))))