From fec434a4e2d0ff65510581e461d87a945d25759a Mon Sep 17 00:00:00 2001
From: Uko Kokņevičs
Date: Thu, 23 Oct 2025 10:17:00 +0300
Subject: Use serapeum's -> & defsubst
---
src/main.lisp | 41 +++++++++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 12 deletions(-)
(limited to 'src/main.lisp')
diff --git a/src/main.lisp b/src/main.lisp
index e68ca40..4cb8c19 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -7,7 +7,7 @@
(:import-from :com.dieggsy.f-string :enable-f-strings)
(:import-from :conf)
(:import-from :log)
- (:import-from :serapeum :drop)
+ (:import-from :serapeum :-> :drop)
(:import-from :state :*state* :make-state)
(:import-from :str)
(:import-from :ukkoclot/src/db :with-db)
@@ -22,13 +22,13 @@
(defvar *in-prod* nil)
+(-> main () (values &optional))
(defun main ()
(unwind-protect
(progn
(conf:load-config #P"config.lisp")
(log:info "Starting up ~A" (conf:bot-name))
- (main-with-config)
- nil)
+ (main-with-config))
(log:info "Quitting!")))
(defmacro reporty ((evt) &body body)
@@ -38,6 +38,7 @@
(error (err) (report-error ,evt err))))
(t ,@body)))
+(-> main-with-config () (values &optional))
(defun main-with-config ()
(unwind-protect
(with-db (db (conf:db-path))
@@ -46,6 +47,7 @@
(wrapped-main))
(log:info "We're done!")))
+(-> wrapped-main () (values &optional))
(defun wrapped-main ()
(when *in-prod*
(send-message :chat-id (conf:dev-group) :text "Initializing..."))
@@ -65,8 +67,10 @@
(setf gup-offset (1+ (update-update-id update)))))))
;; One last getUpdates to make sure offset is stored on server
(get-updates :timeout 0 :limit 1 :offset gup-offset))
- (send-message :chat-id (conf:dev-group) :text "Shutting down..."))
+ (send-message :chat-id (conf:dev-group) :text "Shutting down...")
+ (values))
+(-> on-callback-query (callback-query) (values &optional))
(defun on-callback-query (cb)
(let ((data (callback-query-data cb)))
(cond ((and data
@@ -95,9 +99,10 @@
(log:info "Unrecognised callback query data: ~A" data)
(answer-callback-query :callback-query-id (callback-query-id cb)
:text "Unallowed callback query, don't press the button again"
- :show-alert t)))))
-
+ :show-alert t))))
+ (values))
+(-> on-message (message) (values &optional))
(defun on-message (msg)
(block nil
(when-let (inline-bot (message-via-bot msg))
@@ -110,8 +115,10 @@
(when-let (new-chat-members (message-new-chat-members msg))
(iter
(for new-chat-member in-vector new-chat-members)
- (on-new-member msg new-chat-member)))))
+ (on-new-member msg new-chat-member))))
+ (values))
+(-> on-new-member (message user) (values &optional))
(defun on-new-member (msg new-member)
(if (= (user-id new-member) (bot-id))
(reply-animation msg #P"blob/rule-11.mp4"
@@ -122,13 +129,16 @@
"! Be on your bestest behaviour now!!")
:parse-mode html
:caption-above t
- :allow-sending-without-reply t)))
+ :allow-sending-without-reply t))
+ (values))
+(-> is-bad-text (string) boolean)
(defun is-bad-text (text)
(declare (ignore text))
;; TODO:
nil)
+(-> on-text-message (message string) (values &optional))
(defun on-text-message (msg text)
(block nil
(when (is-bad-text text)
@@ -141,7 +151,7 @@
;; 5 current warns: Ban
;;
;; warn gets removed after a month of no warns
- (return))
+ (return (values)))
(when-let (entities (message-entities msg))
(iter
@@ -223,8 +233,10 @@
(write-char #\l s)
(write-char #\L s)))))
- (t nil))))
+ (t nil)))
+ (values))
+(-> simplify-cmd (string) (or string null))
(defun simplify-cmd (cmd)
(let ((at-idx (position #\@ cmd)))
(if (null at-idx)
@@ -235,6 +247,7 @@
(subseq cmd 1 at-idx)
nil)))))
+(-> on-text-command (message string string) (values &optional))
(defun on-text-command (msg text cmd)
(declare (ignore text))
(let ((simple-cmd (simplify-cmd cmd)))
@@ -264,14 +277,18 @@
(message-from msg)
(= (user-id (message-from msg)) (conf:owner)))
(setf (state:power-on) nil)
- (reply-message msg "Initialising shutdown..." :allow-sending-without-reply t)))))
+ (reply-message msg "Initialising shutdown..." :allow-sending-without-reply t))))
+ (values))
+(-> escape-xml-obj (t) string)
(defun escape-xml-obj (obj)
(escape-xml #f"{obj}"))
+(-> report-error (t t) (values &optional))
(defun report-error (evt err)
(log:error "While handling ~A: ~A" evt err)
(let ((msg #f"{(escape-xml-obj err)} while handling{;~%}
{(escape-xml-obj evt)}"))
(send-message :chat-id (conf:dev-group)
:text msg
- :parse-mode html)))
+ :parse-mode html))
+ (values))
--
cgit v1.2.3