summaryrefslogtreecommitdiff
path: root/src/main.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.lisp')
-rw-r--r--src/main.lisp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main.lisp b/src/main.lisp
index f9720c9..cd9e755 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -4,6 +4,7 @@
4 (:nicknames :ukkoclot) 4 (:nicknames :ukkoclot)
5 (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) 5 (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg)
6 (:import-from :anaphora :acond :awhen :it) 6 (:import-from :anaphora :acond :awhen :it)
7 (:import-from :com.dieggsy.f-string :enable-f-strings)
7 (:import-from :log) 8 (:import-from :log)
8 (:import-from :ukkoclot/db :with-db) 9 (:import-from :ukkoclot/db :with-db)
9 (:import-from :ukkoclot/serializing :fixup-value) 10 (:import-from :ukkoclot/serializing :fixup-value)
@@ -15,6 +16,8 @@
15 (:export :main)) 16 (:export :main))
16(in-package :ukkoclot/main) 17(in-package :ukkoclot/main)
17 18
19(enable-f-strings)
20
18(defvar *in-prod* t) 21(defvar *in-prod* t)
19 22
20(defmacro reporty ((evt) &body body) 23(defmacro reporty ((evt) &body body)
@@ -240,7 +243,9 @@
240 ;; TODO: Replace this cond with a nicer dispatch. Something like string-case? 243 ;; TODO: Replace this cond with a nicer dispatch. Something like string-case?
241 (acond 244 (acond
242 ((equal simple-cmd "chatid") 245 ((equal simple-cmd "chatid")
243 (reply-message bot msg (format nil "<code>~A</code>" (message-chat-id msg)) :parse-mode html)) 246 (reply-message bot msg
247 #f"<code>{(message-chat-id msg)}</code>"
248 :parse-mode html))
244 249
245 ((and (equal simple-cmd "msginfo") 250 ((and (equal simple-cmd "msginfo")
246 (message-reply-to-message msg)) 251 (message-reply-to-message msg))
@@ -248,15 +253,14 @@
248 253
249 ((equal simple-cmd "ping") 254 ((equal simple-cmd "ping")
250 (let* ((start-time (get-internal-real-time)) 255 (let* ((start-time (get-internal-real-time))
251 (reply (reply-message bot msg "Pong! 256 (reply (reply-message bot msg #f"Pong!{;~2%}Send time: ..."))
252Send time: ..."))
253 (end-time (get-internal-real-time)) 257 (end-time (get-internal-real-time))
254 (time-elapsed (* (/ (- end-time start-time) internal-time-units-per-second) 258 (time-elapsed (* (/ (- end-time start-time) internal-time-units-per-second)
255 1000))) 259 1000)))
256 (edit-message-text bot 260 (edit-message-text bot
257 :chat-id (message-chat-id reply) 261 :chat-id (message-chat-id reply)
258 :message-id (message-id reply) 262 :message-id (message-id reply)
259 :text (format nil "Pong!~2%Send time: ~Gms" time-elapsed)))) 263 :text #f"Pong!{;~2%}Send time: {time-elapsed;~G}ms")))
260 264
261 ((and (equal simple-cmd "shutdown") 265 ((and (equal simple-cmd "shutdown")
262 (message-from msg) 266 (message-from msg)
@@ -264,11 +268,12 @@ Send time: ..."))
264 (setf (bot-power-on bot) nil) 268 (setf (bot-power-on bot) nil)
265 (reply-message bot msg "Initialising shutdown..." :allow-sending-without-reply t))))) 269 (reply-message bot msg "Initialising shutdown..." :allow-sending-without-reply t)))))
266 270
271(defun escape-xml-obj (obj)
272 (escape-xml #f"{obj}"))
273
267(defun report-error (bot evt err) 274(defun report-error (bot evt err)
268 (log:error "While handling ~A: ~A" evt err) 275 (log:error "While handling ~A: ~A" evt err)
269 (let ((msg (format nil "<code>~A</code> while handling ~&<pre>~A</pre>" 276 (let ((msg #f"<code>{(escape-xml-obj err)}</code> while handling{;~%}<pre>{(escape-xml-obj evt)}</pre>"))
270 (escape-xml (format nil "~A" err))
271 (escape-xml (format nil "~A" evt)))))
272 (send-message bot 277 (send-message bot
273 :chat-id (config-dev-group (bot-config bot)) 278 :chat-id (config-dev-group (bot-config bot))
274 :text msg 279 :text msg