Browse Source

Save-load settings and minor eliza

Innokenty Enikev 10 năm trước cách đây
mục cha
commit
20664bdb5a
2 tập tin đã thay đổi với 33 bổ sung4 xóa
  1. 31 4
      chatikbot.lisp
  2. 2 0
      eliza.lisp

+ 31 - 4
chatikbot.lisp

@@ -74,7 +74,8 @@
           (send-dont-understand chat-id (preprocess-input text))))
     (when location
       (push (cons chat-id location) *chat-locations*)
-      (telegram-send-message chat-id "Взял на карандаш"))
+      (telegram-send-message chat-id "Взял на карандаш")
+      (save-settings))
     (when sticker
       (send-dont-understand chat-id))))
 
@@ -119,7 +120,8 @@
               *akb-send-to* (set-difference *akb-send-to*
                                             (list chat-id)))
         (setf *akb-send-to* (cons chat-id *akb-send-to*)))
-    (telegram-send-message chat-id message)))
+    (telegram-send-message chat-id message)
+    (save-settings)))
 
 (defvar *akb-max-count* 5 "Max number of tweets to return per run")
 (defvar *akb-last-id* 0 "id of last AKB tweet")
@@ -137,7 +139,8 @@
         (let ((id (aget "id" post)))
           (when (> id *akb-last-id*)
             (send-akb (format-akb post))
-            (setf *akb-last-id* id))))
+            (setf *akb-last-id* id)
+	    (save-settings))))
     (error (e) (log:error e))))
 
 (defun send-akb (text)
@@ -231,7 +234,8 @@
                         (progn
                           (push user users)
                           (telegram-send-message chat-id (format nil "Теперь палим ~A" username)))))))
-              (setf (gethash chat-id *fsq-send-to*) users))))
+              (setf (gethash chat-id *fsq-send-to*) users)
+	      (save-settings))))
     (error (e)
       (log:error e)
       (telegram-send-message chat-id "Ошибочка вышла"))))
@@ -286,8 +290,23 @@
              (telegram-send-message chat-id (format nil "~{~A~^~%~}" texts))))
     (error (e) (log:error e))))
 
+(defun save-settings()
+  (with-open-file (s (merge-pathnames "settings.lisp"
+				      (asdf:component-pathname
+				       (asdf:find-system '#:chatikbot)))
+		     :direction :output
+		     :if-exists :supersede
+		     :if-does-not-exist :create)
+    (write '(in-package #:chatikbot) :stream s)
+    (write
+     `(setf *fsq-send-to* (alexandria:alist-hash-table ',(alexandria:hash-table-alist *fsq-send-to*))
+	    *chat-locations* ',*chat-locations*
+	    *akb-send-to* ',*akb-send-to*
+	    *akb-last-id* ,*akb-last-id*)
+     :stream s)))
 
 (defun start ()
+  ;; Clear prev threads
   (mapc #'trivial-timers:unschedule-timer (trivial-timers:list-all-timers))
   (let ((old-updates (find "process-updates"
                             (bordeaux-threads:all-threads)
@@ -295,6 +314,13 @@
                             :test #'equal)))
     (when old-updates
       (bordeaux-threads:destroy-thread old-updates)))
+  ;; Load settings file
+  (alexandria:when-let (file (probe-file
+			      (merge-pathnames "settings.lisp"
+					       (asdf:component-pathname
+						(asdf:find-system '#:chatikbot)))))
+    (load file))
+  ;; Start timers
   (clon:schedule-function
    (lambda () (process-latest-akb))
    (clon:make-scheduler
@@ -307,6 +333,7 @@
     (clon:make-typed-cron-schedule :minute '* :hour '*)
     :allow-now-p t)
    :thread t)
+  ;; Start getUpdates thread
   (bordeaux-threads:make-thread
    (lambda ()
      (in-package #:chatikbot)

+ 2 - 0
eliza.lisp

@@ -32,6 +32,8 @@
      (#'tumblr-random-photo ,*ass-roll* ?n))
     (((?* ?a) (?or жопа жопы ягодицы зад зады ass asses) (?* ?b))
      (#'tumblr-random-photo ,*ass-roll*))
+    (((?* ?a) (?or тёлка телка телку тёлку баба бабу сука суку сучка сучку babe bitch) (?* ?b))
+     (#'tumblr-random-photo ,*ass-roll*) (#'tumblr-random-photo ,*boobs-roll*))
     (((?* ?a) (?or ты бот ботяра) (?* ?x))
      (сам ?x) (сам ты ?x) (а по ебалу?) (сейчас мы разберемся кто еще тут ?x) ,@*fuck-off*)
     (((?* x))