changed parsing logic to remove lines the parser couldnt handle
fixed issues relating to posting statuses without polls
This commit is contained in:
parent
c906f4818a
commit
1262ff03fa
|
@ -6,7 +6,7 @@
|
|||
:license "NPLv1+"
|
||||
:version "0.0.1"
|
||||
:serial t
|
||||
:depends-on (#:glacier #:cl-csv #:with-user-abort)
|
||||
:depends-on (#:glacier #:cl-csv #:with-user-abort #:cl-ppcre)
|
||||
:components ((:file "package")
|
||||
(:file "df-bug-bot"))
|
||||
:entry-point "df-bug-bot:main"
|
||||
|
|
|
@ -5,23 +5,25 @@
|
|||
(defvar *csv-file* #P"df-bugs.csv")
|
||||
(defvar *parsed-csv* nil)
|
||||
(defvar *poll-chances* 0.25)
|
||||
(defvar *csv-regex* "(?m)^[0-9]{7,}.+,(open|reopened|unable to reproduce|not fixable|suspended|won't fix),.+$")
|
||||
|
||||
(defun post-poll-p ()
|
||||
(>= *poll-chances* (random 1.0)))
|
||||
|
||||
(defun parse-csv ()
|
||||
"removes all bugs that aren't currently open"
|
||||
(remove-if #'(lambda (record)
|
||||
(not (string= (nth 13 record) "open")))
|
||||
(cl-csv:read-csv *csv-file*)))
|
||||
(defun parse-csv (csv)
|
||||
"transforms the CSV to ensure that it meets our specs"
|
||||
;; remove all lines that arent actual bugs
|
||||
(ppcre:all-matches-as-strings *csv-regex*
|
||||
;; remove all non-terminated strings (to appease cl-csv
|
||||
(ppcre:regex-replace-all "(?m)\".+$" csv "")))
|
||||
|
||||
(defun refresh-csv-file ()
|
||||
"downloads the bug CSV file and writes it to *CSV-FILE*"
|
||||
(with-open-file (output *csv-file* :direction :output
|
||||
:if-exists :supersede
|
||||
:if-does-not-exist :create)
|
||||
(format output "~A~%" (drakma:http-request "https://dwarffortress.mantishub.io/csv_export.php")))
|
||||
(setf *parsed-csv* (parse-csv)))
|
||||
(let ((csv-string (drakma:http-request "https://dwarffortress.mantishub.io/csv_export.php")))
|
||||
(str:to-file *csv-file*
|
||||
(str:join (string #\newline)
|
||||
(parse-csv csv-string)))
|
||||
(setf *parsed-csv* (cl-csv:read-csv *csv-file*))))
|
||||
|
||||
(defun get-random-bug ()
|
||||
"gets a random bug from the list"
|
||||
|
@ -40,7 +42,7 @@
|
|||
;; download our csv file if it doesnt exist
|
||||
;; if its already downloaded go ahead and parse it
|
||||
(if (uiop:file-exists-p *csv-file*)
|
||||
(setf *parsed-csv* (parse-csv))
|
||||
(setf *parsed-csv* (cl-csv:read-csv *csv-file*))
|
||||
(refresh-csv-file))
|
||||
|
||||
(handler-case
|
||||
|
@ -51,15 +53,19 @@
|
|||
;; after every 4 days (and 13 min) refresh the bug list
|
||||
;; this should hopefully not overlap with the posting,
|
||||
;; because that might mess things up
|
||||
(after-every ((time-to-seconds 4 :days 13 :min) :seconds :async t)
|
||||
(after-every ((time-to-seconds 4 :days 13 :minutes) :seconds :async t)
|
||||
(refresh-csv-file))
|
||||
|
||||
;; post a random bug every hour
|
||||
(after-every (1 :hour :run-immediately t)
|
||||
(let ((poll? (post-poll-p)))
|
||||
(post (generate-post)
|
||||
:poll-options (when poll? '("Bug?" "Feature?"))
|
||||
:poll-timeout (when poll? (time-to-seconds 1 :hour)))))))
|
||||
(let ((poll? nil))
|
||||
(post (generate-post)
|
||||
:poll-options (when poll? '("Bug?" "Feature?"))
|
||||
:poll-timeout (when poll? 3600))))))
|
||||
|
||||
(error (e)
|
||||
(format t "~A~%" e)
|
||||
(uiop:quit))
|
||||
|
||||
(user-abort ()
|
||||
(uiop:quit))))
|
||||
|
|
Loading…
Reference in New Issue