1
0
Innokenty Enikev 10 лет назад
Родитель
Сommit
da96d00b63
3 измененных файлов с 25 добавлено и 16 удалено
  1. 10 6
      chatikbot.lisp
  2. 1 1
      eliza.lisp
  3. 14 9
      forecast.lisp

+ 10 - 6
chatikbot.lisp

@@ -159,7 +159,7 @@
 	      (error (e) (log:error e))))))
 	      (error (e) (log:error e))))))
     (error (e)
     (error (e)
       (log:error e)
       (log:error e)
-      (telegram-send-message chat-id "some shit happened"))))
+      (telegram-send-message chat-id "Ошибочка вышла"))))
 
 
 
 
 (defun handle-cmd-rates (chat-id message-id args)
 (defun handle-cmd-rates (chat-id message-id args)
@@ -174,11 +174,15 @@
     (telegram-send-message
     (telegram-send-message
      chat-id
      chat-id
      (if location
      (if location
-         (forecast-format (forecast
-                           (aget "latitude" location)
-                           (aget "longitude" location)
-                           :hourly (find "hourly" args :key #'string-downcase :test #'equal)
-                           :daily (find "daily" args :key #'string-downcase :test #'equal)))
+	 (handler-case
+	     (forecast-format (forecast
+			       (aget "latitude" location)
+			       (aget "longitude" location)
+			       :hourly (find "hourly" args :key #'string-downcase :test #'equal)
+			       :daily (find "daily" args :key #'string-downcase :test #'equal)))
+	   (error (e)
+	     (log:error e)
+	     "Ошибочка вышла"))
          "Так а ты чьих будешь?"))))
          "Так а ты чьих будешь?"))))
 
 
 
 

+ 1 - 1
eliza.lisp

@@ -81,7 +81,7 @@
   (let ((r (use-eliza-rules
   (let ((r (use-eliza-rules
             (read-from-string-no-punct input))))
             (read-from-string-no-punct input))))
     (cond
     (cond
-      ((null r))
+      ((null r) nil)
       ((and (consp (car r)) (eq 'function (caar r)))
       ((and (consp (car r)) (eq 'function (caar r)))
        (apply (cadar r) (cdr r)))
        (apply (cadar r) (cdr r)))
       ((keywordp (car r)) r)
       ((keywordp (car r)) r)

+ 14 - 9
forecast.lisp

@@ -4,15 +4,20 @@
 (defparameter +forecast-api-url+ "https://api.forecast.io/forecast" "forecast.io API endpoint")
 (defparameter +forecast-api-url+ "https://api.forecast.io/forecast" "forecast.io API endpoint")
 
 
 (defun forecast (lat lon &key time (currently t) minutely hourly daily alerts)
 (defun forecast (lat lon &key time (currently t) minutely hourly daily alerts)
-  (yason:parse
-   (flexi-streams:octets-to-string
-    (drakma:http-request (format
-                          nil
-                          "~A/~A/~A,~A~@[,~A~]?units=si&exclude=~:[currently,~;~]~:[minutely,~;~]~:[hourly,~;~]~:[daily,~;~]~:[alerts,~;~]flags&lang=ru"
-                          +forecast-api-url+ *forecast-api-key* lat lon time
-                          currently minutely hourly daily alerts))
-    :external-format :utf8)
-   :object-as :alist))
+  (handler-case
+      (bordeaux-threads:with-timeout (5)
+	(yason:parse
+	 (flexi-streams:octets-to-string
+	  (drakma:http-request (format
+				nil
+				"~A/~A/~A,~A~@[,~A~]?units=si&exclude=~:[currently,~;~]~:[minutely,~;~]~:[hourly,~;~]~:[daily,~;~]~:[alerts,~;~]flags&lang=ru"
+				+forecast-api-url+ *forecast-api-key* lat lon time
+				currently minutely hourly daily alerts))
+	  :external-format :utf8)
+	 :object-as :alist))
+    (bordeaux-threads:timeout (e)
+      (declare (ignore e))
+      (error "Timeout"))))
 
 
 (local-time:reread-timezone-repository :timezone-repository "/usr/share/zoneinfo/")
 (local-time:reread-timezone-repository :timezone-repository "/usr/share/zoneinfo/")