summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-10-10 07:13:19 +0300
committerGravatar Uko Kokņevičs2025-10-10 07:13:19 +0300
commit5e6b7a1248e175e8c550ce9feed7745292f17bfe (patch)
tree90ad160fe8388a7568c78d2e2deb237b225b5e5e
parentInitial commit (diff)
downloadukkoclot-5e6b7a1248e175e8c550ce9feed7745292f17bfe.tar.gz
ukkoclot-5e6b7a1248e175e8c550ce9feed7745292f17bfe.tar.xz
ukkoclot-5e6b7a1248e175e8c550ce9feed7745292f17bfe.zip
Add a helper reply-message function
-rw-r--r--src/bot.lisp2
-rw-r--r--src/bot/advanced.lisp29
-rw-r--r--src/bot/methods.lisp15
-rw-r--r--src/main.lisp237
-rw-r--r--src/tg-types/reply-parameters.lisp2
5 files changed, 101 insertions, 184 deletions
diff --git a/src/bot.lisp b/src/bot.lisp
index a51402d..78a6ad0 100644
--- a/src/bot.lisp
+++ b/src/bot.lisp
@@ -3,4 +3,4 @@
3(uiop:define-package :ukkoclot/bot 3(uiop:define-package :ukkoclot/bot
4 (:use) 4 (:use)
5 ;; Maybe should somehow hide BOT-USERNAME% and BOT-ID% but whatever 5 ;; Maybe should somehow hide BOT-USERNAME% and BOT-ID% but whatever
6 (:use-reexport :ukkoclot/bot/impl :ukkoclot/bot/methods)) 6 (:use-reexport :ukkoclot/bot/advanced :ukkoclot/bot/impl :ukkoclot/bot/methods))
diff --git a/src/bot/advanced.lisp b/src/bot/advanced.lisp
new file mode 100644
index 0000000..a6ad9ba
--- /dev/null
+++ b/src/bot/advanced.lisp
@@ -0,0 +1,29 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/bot/advanced
4 (:use :c2cl :ukkoclot/bot/impl :ukkoclot/bot/methods :ukkoclot/tg-types)
5 (:export :bot-id :bot-username :reply-message))
6(in-package :ukkoclot/bot/advanced)
7
8(defun bot-id (bot)
9 (or (bot-id% bot)
10 (progn
11 (get-me bot)
12 (bot-id% bot))))
13
14(defun bot-username (bot)
15 (or (bot-username% bot)
16 (progn
17 (get-me bot)
18 (bot-username% bot))))
19
20(defun reply-message (bot msg text &key parse-mode allow-sending-without-reply)
21 (send-message bot
22 :chat-id (message-chat-id msg)
23 :text text
24 :parse-mode parse-mode
25 :reply-parameters
26 (make-reply-parameters
27 :allow-sending-without-reply allow-sending-without-reply
28 :message-id (message-id msg)
29 :chat-id (message-chat-id msg))))
diff --git a/src/bot/methods.lisp b/src/bot/methods.lisp
index b0eca5c..99b6411 100644
--- a/src/bot/methods.lisp
+++ b/src/bot/methods.lisp
@@ -2,7 +2,7 @@
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/bot/methods 3(defpackage :ukkoclot/bot/methods
4 (:use :c2cl :ukkoclot/bot/impl :ukkoclot/tg-types :ukkoclot/tg-types/macros) 4 (:use :c2cl :ukkoclot/bot/impl :ukkoclot/tg-types :ukkoclot/tg-types/macros)
5 (:export :answer-callback-query :bot-id :bot-username :delete-message :edit-message-text :get-me :get-updates :send-message :set-my-name)) 5 (:export :answer-callback-query :delete-message :edit-message-text :get-me :get-updates :send-message :set-my-name))
6(in-package :ukkoclot/bot/methods) 6(in-package :ukkoclot/bot/methods)
7 7
8(define-tg-method (answer-callback-query boolean "answerCallbackQuery" #'identity) 8(define-tg-method (answer-callback-query boolean "answerCallbackQuery" #'identity)
@@ -12,22 +12,11 @@
12 (url (or string null) nil) 12 (url (or string null) nil)
13 (cache-time (or integer null) nil)) 13 (cache-time (or integer null) nil))
14 14
15(defun bot-id (bot)
16 (or (bot-id% bot)
17 (progn
18 (get-me bot)
19 (bot-id% bot))))
20
21(defun bot-username (bot)
22 (or (bot-username% bot)
23 (progn
24 (get-me bot)
25 (bot-username% bot))))
26
27(define-tg-method (delete-message boolean "deleteMessage" #'identity) 15(define-tg-method (delete-message boolean "deleteMessage" #'identity)
28 (chat-id (or integer string)) 16 (chat-id (or integer string))
29 (message-id integer)) 17 (message-id integer))
30 18
19;; TODO: Add a way to simply specify :message msg :)
31(define-tg-method (edit-message-text message "editMessageText" #'hash->message) 20(define-tg-method (edit-message-text message "editMessageText" #'hash->message)
32 (business-connection-id (or string null) nil) 21 (business-connection-id (or string null) nil)
33 (chat-id (or integer string null) nil) 22 (chat-id (or integer string null) nil)
diff --git a/src/main.lisp b/src/main.lisp
index af88fe6..419bb67 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -3,7 +3,7 @@
3(defpackage :ukkoclot/main 3(defpackage :ukkoclot/main
4 (:nicknames :ukkoclot) 4 (:nicknames :ukkoclot)
5 (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/log :ukkoclot/tg-types) 5 (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/log :ukkoclot/tg-types)
6 (:import-from :anaphora :aand :awhen :it) 6 (:import-from :anaphora :acond :awhen :it)
7 (:import-from :ukkoclot/bot :make-bot :bot-power-on) 7 (:import-from :ukkoclot/bot :make-bot :bot-power-on)
8 (:import-from :ukkoclot/db :with-db) 8 (:import-from :ukkoclot/db :with-db)
9 (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) 9 (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case)
@@ -105,15 +105,10 @@
105 ;; TODO: Rule 10 have fun and enjoy your time on user entry 105 ;; TODO: Rule 10 have fun and enjoy your time on user entry
106 (if (= (user-id new-member) (bot-id bot)) 106 (if (= (user-id new-member) (bot-id bot))
107 nil 107 nil
108 (send-message bot 108 (reply-message bot msg
109 :chat-id (message-chat-id msg) 109 (concatenate 'string "Hello there, " (user-format-name new-member) "! Be on your bestest behaviour now!!")
110 :text (concatenate 'string "Hello there, " (user-format-name new-member) "! Be on your bestest behaviour now!!") 110 :parse-mode "HTML"
111 :parse-mode "HTML" 111 :allow-sending-without-reply t)))
112 :reply-parameters
113 (make-reply-parameters
114 :allow-sending-without-reply t
115 :message-id (message-id msg)
116 :chat-id (message-chat-id msg)))))
117 112
118(defun is-bad-text (text) 113(defun is-bad-text (text)
119 ;; TODO: 114 ;; TODO:
@@ -140,144 +135,68 @@
140 do (on-text-command bot msg text (message-entity-extract entity text)))) 135 do (on-text-command bot msg text (message-entity-extract entity text))))
141 136
142 (cond ((equal text ":3") 137 (cond ((equal text ":3")
143 (send-message bot :chat-id (message-chat-id msg) 138 (reply-message bot msg ">:3"))
144 :text ">:3"
145 :reply-parameters (make-reply-parameters :message-id (message-id msg)
146 :chat-id (message-chat-id msg))))
147 139
148 ((equal text ">:3") 140 ((equal text ">:3")
149 (send-message bot :chat-id (message-chat-id msg) 141 (reply-message bot msg "<b>&gt;:3</b>" :parse-mode "HTML"))
150 :text "<b>&gt;:3</b>"
151 :parse-mode "HTML"
152 :reply-parameters (make-reply-parameters
153 :message-id (message-id msg)
154 :chat-id (message-chat-id msg))))
155 142
156 ((starts-with-ignore-case text "big ") 143 ((starts-with-ignore-case text "big ")
157 (let ((the-text (subseq text 4))) 144 (let ((the-text (subseq text 4)))
158 (unless (is-tg-whitespace-str the-text) 145 (unless (is-tg-whitespace-str the-text)
159 (send-message bot 146 (reply-message bot msg
160 :chat-id (message-chat-id msg) 147 (concatenate 'string
161 :text (concatenate 'string 148 "<b>"
162 "<b>" 149 (escape-xml (string-upcase the-text))
163 (escape-xml (string-upcase the-text)) 150 "</b>")
164 "</b>") 151 :parse-mode "HTML"))))
165 :parse-mode "HTML"
166 :reply-parameters
167 (make-reply-parameters
168 :message-id (message-id msg)
169 :chat-id (message-chat-id msg))))))
170 152
171 ((string-equal text "dio cane") 153 ((string-equal text "dio cane")
172 (let ((reply-msg-id (message-id msg)) 154 (reply-message bot
173 (reply-chat-id (message-chat-id msg))) 155 (or (message-reply-to-message msg) msg)
174 (awhen (message-reply-to-message msg) 156 "porco dio"))
175 (setf reply-msg-id (message-id it))
176 (setf reply-chat-id (message-chat-id it)))
177 (send-message bot
178 :chat-id (message-chat-id msg)
179 :text "porco dio"
180 :reply-parameters
181 (make-reply-parameters
182 :message-id reply-msg-id
183 :chat-id reply-chat-id))))
184 157
185 ((string-equal text "forgor") 158 ((string-equal text "forgor")
186 (send-message bot 159 (reply-message bot msg "💀"))
187 :chat-id (message-chat-id msg)
188 :text "💀"
189 :reply-parameters
190 (make-reply-parameters
191 :message-id (message-id msg)
192 :chat-id (message-chat-id msg))))
193 160
194 ((string-equal text "huh") 161 ((string-equal text "huh")
195 (send-message bot 162 (reply-message bot msg "idgi"))
196 :chat-id (message-chat-id msg)
197 :text "idgi"
198 :reply-parameters
199 (make-reply-parameters
200 :message-id (message-id msg)
201 :chat-id (message-chat-id msg))))
202 163
203 ((string= text "H") 164 ((string= text "H")
204 (send-message bot 165 (reply-message bot msg "<code>Randomly selected reminder that h &gt; H.</code>" :parse-mode "HTML"))
205 :chat-id (message-chat-id msg)
206 :text "<code>Randomly selected reminder that h &gt; H.</code>"
207 :parse-mode "HTML"
208 :reply-parameters
209 (make-reply-parameters
210 :message-id (message-id msg)
211 :chat-id (message-chat-id msg))))
212 166
213 ((string-equal text "porco dio") 167 ((string-equal text "porco dio")
214 (let ((reply-msg-id (message-id msg)) 168 (reply-message bot
215 (reply-chat-id (message-chat-id msg))) 169 (or (message-reply-to-message msg) msg)
216 (awhen (message-reply-to-message msg) 170 "dio cane"))
217 (setf reply-msg-id (message-id it))
218 (setf reply-chat-id (message-chat-id it)))
219 (send-message bot
220 :chat-id (message-chat-id msg)
221 :text "dio cane"
222 :reply-parameters
223 (make-reply-parameters
224 :message-id reply-msg-id
225 :chat-id reply-chat-id))))
226 171
227 ((starts-with-ignore-case text "say ") 172 ((starts-with-ignore-case text "say ")
228 (let ((the-text (subseq text 4))) 173 (let ((the-text (subseq text 4)))
229 (unless (is-tg-whitespace-str the-text) 174 (unless (is-tg-whitespace-str the-text)
230 (send-message bot 175 (reply-message bot msg the-text))))
231 :chat-id (message-chat-id msg)
232 :text the-text
233 :reply-parameters
234 (make-reply-parameters
235 :message-id (message-id msg)
236 :chat-id (message-chat-id msg))))))
237 176
238 ((string-equal text "uwu") 177 ((string-equal text "uwu")
239 (send-message bot 178 (reply-message bot msg "OwO"))
240 :chat-id (message-chat-id msg)
241 :text "OwO"
242 :reply-parameters
243 (make-reply-parameters
244 :message-id (message-id msg)
245 :chat-id (message-chat-id msg))))
246 179
247 ((string-equal text "waow") 180 ((string-equal text "waow")
248 (let ((reply-msg-id (message-id msg)) 181 (reply-message bot
249 (reply-chat-id (message-chat-id msg))) 182 (or (message-reply-to-message msg) msg)
250 (awhen (message-reply-to-message msg) 183 "BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED"))
251 (setf reply-msg-id (message-id it))
252 (setf reply-chat-id (message-chat-id it)))
253 (send-message bot
254 :chat-id (message-chat-id msg)
255 :text "BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED BASED"
256 :reply-parameters
257 (make-reply-parameters
258 :message-id reply-msg-id
259 :chat-id reply-chat-id))))
260 184
261 ((string-equal text "what") 185 ((string-equal text "what")
262 (send-message bot 186 (reply-message bot msg
263 :chat-id (message-chat-id msg) 187 (with-output-to-string (s)
264 :text (with-output-to-string (s) 188 (if (char= (elt text 0) #\w)
265 (if (char= (elt text 0) #\w) 189 (write-char #\g s)
266 (write-char #\g s) 190 (write-char #\G s))
267 (write-char #\G s)) 191 (if (char= (elt text 1) #\h)
268 (if (char= (elt text 1) #\h) 192 (write-string "ood " s)
269 (write-string "ood " s) 193 (write-string "OOD " s))
270 (write-string "OOD " s)) 194 (if (char= (elt text 2) #\a)
271 (if (char= (elt text 2) #\a) 195 (write-string "gir" s)
272 (write-string "gir" s) 196 (write-string "GIR" s))
273 (write-string "GIR" s)) 197 (if (char= (elt text 3) #\t)
274 (if (char= (elt text 3) #\t) 198 (write-char #\l s)
275 (write-char #\l s) 199 (write-char #\L s)))))
276 (write-char #\L s)))
277 :reply-parameters
278 (make-reply-parameters
279 :message-id (message-id msg)
280 :chat-id (message-chat-id msg))))
281 ))) 200 )))
282 201
283(defun simplify-cmd (bot cmd) 202(defun simplify-cmd (bot cmd)
@@ -293,53 +212,33 @@
293(defun on-text-command (bot msg text cmd) 212(defun on-text-command (bot msg text cmd)
294 (let ((simple-cmd (simplify-cmd bot cmd))) 213 (let ((simple-cmd (simplify-cmd bot cmd)))
295 (log-debug "text-command: ~A AKA ~A" cmd simple-cmd) 214 (log-debug "text-command: ~A AKA ~A" cmd simple-cmd)
296 (cond ((equal simple-cmd "chatid") 215 (acond
297 (send-message bot :chat-id (message-chat-id msg) 216 ((equal simple-cmd "chatid")
298 :text (format nil "<code>~A</code>" (message-chat-id msg)) 217 (reply-message bot msg (format nil "<code>~A</code>" (message-chat-id msg)) :parse-mode "HTML"))
299 :parse-mode "HTML" 218
300 :reply-parameters (make-reply-parameters :message-id (message-id msg) 219 ((and (equal simple-cmd "msginfo")
301 :chat-id (message-chat-id msg)))) 220 (message-reply-to-message msg))
302 221 (reply-message bot it
303 ((equal simple-cmd "msginfo") 222 ;; TODO: Text needs lot more massaging lol
304 (aand (message-reply-to-message msg) 223 (jzon:stringify (arg-encode it))))
305 (send-message bot :chat-id (message-chat-id msg) 224
306 ;; TODO: Text needs lot more massaging 225 ((equal simple-cmd "ping")
307 :text (jzon:stringify (arg-encode it)) 226 (let* ((start-time (get-internal-real-time))
308 :reply-parameters 227 (reply (reply-message bot msg "Pong!
309 (make-reply-parameters 228Send time: ..."))
310 :message-id (message-id msg) 229 (end-time (get-internal-real-time))
311 :chat-id (message-chat-id msg))))) 230 (time-elapsed (* (/ (- end-time start-time) internal-time-units-per-second)
312 231 1000)))
313 ((equal simple-cmd "ping") 232 (edit-message-text bot
314 (let* ((start-time (get-internal-real-time)) 233 :chat-id (message-chat-id reply)
315 (reply (send-message bot 234 :message-id (message-id reply)
316 :chat-id (message-chat-id msg) 235 :text (format nil "Pong!~2%Send time: ~Gms" time-elapsed))))
317 :text "Pong! 236
318Send time: ..." 237 ((and (equal simple-cmd "shutdown")
319 :reply-parameters 238 (message-from msg)
320 (make-reply-parameters 239 (= (user-id (message-from msg)) (config-owner (bot-config bot))))
321 :message-id (message-id msg) 240 (setf (bot-power-on bot) nil)
322 :chat-id (message-chat-id msg)))) 241 (reply-message bot msg "Initialising shutdown..." :allow-sending-without-reply t))
323 (end-time (get-internal-real-time))
324 (time-elapsed (* (/ (- end-time start-time) internal-time-units-per-second)
325 1000)))
326 (edit-message-text bot
327 :chat-id (message-chat-id msg)
328 :message-id (message-id reply)
329 :text (format nil "Pong!~2%Send time: ~Gms" time-elapsed))))
330
331 ((and (equal simple-cmd "shutdown")
332 (message-from msg)
333 (= (user-id (message-from msg)) (config-owner (bot-config bot))))
334 (setf (bot-power-on bot) nil)
335 (send-message bot
336 :chat-id (message-chat-id msg)
337 :text "Initialising shutdown..."
338 :reply-parameters
339 (make-reply-parameters
340 :allow-sending-without-reply t
341 :message-id (message-id msg)
342 :chat-id (message-chat-id msg))))
343 242
344 ))) 243 )))
345 244
diff --git a/src/tg-types/reply-parameters.lisp b/src/tg-types/reply-parameters.lisp
index 5f0595d..29d21f7 100644
--- a/src/tg-types/reply-parameters.lisp
+++ b/src/tg-types/reply-parameters.lisp
@@ -23,7 +23,7 @@
23(define-tg-type reply-parameters 23(define-tg-type reply-parameters
24 (message-id integer) 24 (message-id integer)
25 (chat-id (or integer string null) nil) 25 (chat-id (or integer string null) nil)
26 ;; Technically true if on a business account but yeah right lmao 26 ;; TODO: This should be a ternary true, false, default
27 (allow-sending-without-reply boolean nil) 27 (allow-sending-without-reply boolean nil)
28 (quote (or string null) nil) 28 (quote (or string null) nil)
29 (quote-parse-mode (or string null) nil) 29 (quote-parse-mode (or string null) nil)