|
@@ -13,6 +13,17 @@
|
|
|
(db-init)
|
|
(db-init)
|
|
|
;; Load settings
|
|
;; Load settings
|
|
|
(load-settings)
|
|
(load-settings)
|
|
|
|
|
+;; Load plugins
|
|
|
|
|
+(defsetting *plugins* nil "List of enabled plugins")
|
|
|
|
|
+(dolist (plugin *plugins*)
|
|
|
|
|
+ (handler-case
|
|
|
|
|
+ (load (merge-pathnames (format nil "~A.lisp" plugin)
|
|
|
|
|
+ (asdf:component-pathname
|
|
|
|
|
+ (asdf:find-system '#:chatikbot))))
|
|
|
|
|
+ (error (e) (log:error e))))
|
|
|
|
|
+;; Init plugin's database
|
|
|
|
|
+(with-db (db)
|
|
|
|
|
+ (run-hooks :db-init db))
|
|
|
|
|
|
|
|
(defvar *telegram-last-update* nil "Telegram last update_id")
|
|
(defvar *telegram-last-update* nil "Telegram last update_id")
|
|
|
|
|
|
|
@@ -32,36 +43,6 @@
|
|
|
unless (equal "update_id" key)
|
|
unless (equal "update_id" key)
|
|
|
do (run-hooks (string-to-event (format nil "update-~A" key)) value)))
|
|
do (run-hooks (string-to-event (format nil "update-~A" key)) value)))
|
|
|
|
|
|
|
|
-(defun send-dont-understand (chat-id &optional text reply-id)
|
|
|
|
|
- (let ((resp (eliza text)))
|
|
|
|
|
- (log:info text resp)
|
|
|
|
|
- (when resp
|
|
|
|
|
- (send-response chat-id resp reply-id))))
|
|
|
|
|
-
|
|
|
|
|
-(defun handle-unknown-message (message)
|
|
|
|
|
- (let ((chat-id (aget "id" (aget "chat" message)))
|
|
|
|
|
- (text (aget "text" message)))
|
|
|
|
|
- (log:info "handle-unknown-message" message)
|
|
|
|
|
- (send-dont-understand chat-id (preprocess-input text))
|
|
|
|
|
- t))
|
|
|
|
|
-(add-hook :update-message 'handle-unknown-message t)
|
|
|
|
|
-
|
|
|
|
|
-;; Schedule
|
|
|
|
|
-(defmacro defcron (name (&rest schedule) &body body)
|
|
|
|
|
- (let ((schedule (or schedule '(:minute '* :hour '*))))
|
|
|
|
|
- `(progn
|
|
|
|
|
- (defun ,name ()
|
|
|
|
|
- (handler-case (progn ,@body)
|
|
|
|
|
- (error (e) (log:error e))))
|
|
|
|
|
- (add-hook :starting #'(lambda ()
|
|
|
|
|
- (clon:schedule-function
|
|
|
|
|
- ',name (clon:make-scheduler
|
|
|
|
|
- (clon:make-typed-cron-schedule
|
|
|
|
|
- ,@schedule)
|
|
|
|
|
- :allow-now-p t)
|
|
|
|
|
- :name ',name :thread t)
|
|
|
|
|
- (values))))))
|
|
|
|
|
-
|
|
|
|
|
(defcron process-watchdog ()
|
|
(defcron process-watchdog ()
|
|
|
(close
|
|
(close
|
|
|
(open (merge-pathnames ".watchdog"
|
|
(open (merge-pathnames ".watchdog"
|
|
@@ -71,25 +52,19 @@
|
|
|
:if-exists :supersede
|
|
:if-exists :supersede
|
|
|
:if-does-not-exist :create)))
|
|
:if-does-not-exist :create)))
|
|
|
|
|
|
|
|
-(defsetting *plugins* nil "List of enabled plugins")
|
|
|
|
|
|
|
|
|
|
-(defun start ()
|
|
|
|
|
|
|
+(defun cleanup ()
|
|
|
;; Clear prev threads
|
|
;; Clear prev threads
|
|
|
(mapc #'trivial-timers:unschedule-timer (trivial-timers:list-all-timers))
|
|
(mapc #'trivial-timers:unschedule-timer (trivial-timers:list-all-timers))
|
|
|
(let ((old-updates (find "process-updates"
|
|
(let ((old-updates (find "process-updates"
|
|
|
- (bordeaux-threads:all-threads)
|
|
|
|
|
- :key #'bordeaux-threads:thread-name
|
|
|
|
|
- :test #'equal)))
|
|
|
|
|
|
|
+ (bordeaux-threads:all-threads)
|
|
|
|
|
+ :key #'bordeaux-threads:thread-name
|
|
|
|
|
+ :test #'equal)))
|
|
|
(when old-updates
|
|
(when old-updates
|
|
|
- (bordeaux-threads:destroy-thread old-updates)))
|
|
|
|
|
|
|
+ (bordeaux-threads:destroy-thread old-updates))))
|
|
|
|
|
|
|
|
- ;; Load plugins
|
|
|
|
|
- (dolist (plugin *plugins*)
|
|
|
|
|
- (handler-case
|
|
|
|
|
- (load (merge-pathnames (format nil "~A.lisp" plugin)
|
|
|
|
|
- (asdf:component-pathname
|
|
|
|
|
- (asdf:find-system '#:chatikbot))))
|
|
|
|
|
- (error (e) (log:error e))))
|
|
|
|
|
|
|
+(defun start ()
|
|
|
|
|
+ (cleanup)
|
|
|
|
|
|
|
|
;; Run 'starting' hooks to set up schedules
|
|
;; Run 'starting' hooks to set up schedules
|
|
|
(run-hooks :starting)
|
|
(run-hooks :starting)
|