diff options
| author | 2025-10-19 11:12:24 +0300 | |
|---|---|---|
| committer | 2025-10-19 11:37:39 +0300 | |
| commit | 6b544b58dba095cafd6906d78b70bfd237397439 (patch) | |
| tree | c7c4c6b061909a11c3d93cc53c3a141d9e6cae16 /src/tg/message-entity.lisp | |
| parent | Add an alpine build script for srht (diff) | |
| download | ukkoclot-6b544b58dba095cafd6906d78b70bfd237397439.tar.gz ukkoclot-6b544b58dba095cafd6906d78b70bfd237397439.tar.xz ukkoclot-6b544b58dba095cafd6906d78b70bfd237397439.zip | |
Fix lint issues
Diffstat (limited to 'src/tg/message-entity.lisp')
| -rw-r--r-- | src/tg/message-entity.lisp | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/tg/message-entity.lisp b/src/tg/message-entity.lisp index feb3e8f..1a8cd27 100644 --- a/src/tg/message-entity.lisp +++ b/src/tg/message-entity.lisp | |||
| @@ -1,13 +1,34 @@ | |||
| 1 | ;; SPDX-License-Identifier: EUPL-1.2 | 1 | ;; SPDX-License-Identifier: EUPL-1.2 |
| 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/src/tg/message-entity | 3 | (defpackage :ukkoclot/src/tg/message-entity |
| 4 | (:use :c2cl :iterate :ukkoclot/src/tg/type-macros :ukkoclot/src/tg/message-entity-type :ukkoclot/src/tg/user) | 4 | (:documentation "MessageEntity Telegram type") |
| 5 | (:use :c2cl :iterate :ukkoclot/src/enum :ukkoclot/src/tg/type-macros :ukkoclot/src/tg/user) | ||
| 5 | (:export | 6 | (:export |
| 7 | #:message-entity-type | ||
| 8 | #:mention | ||
| 9 | #:hashtag | ||
| 10 | #:cashtag | ||
| 11 | #:bot-command | ||
| 12 | #:url-entity | ||
| 13 | |||
| 14 | #:phone-number | ||
| 15 | #:bold | ||
| 16 | #:italic | ||
| 17 | #:underline | ||
| 18 | #:strikethrough | ||
| 19 | #:spoiler | ||
| 20 | #:blockquote | ||
| 21 | #:expandable-blockquote | ||
| 22 | #:code | ||
| 23 | #:pre | ||
| 24 | #:text-link | ||
| 25 | #:text-mention | ||
| 26 | #:custom-emoji | ||
| 27 | |||
| 6 | #:message-entity | 28 | #:message-entity |
| 7 | #:make-message-entity | 29 | #:make-message-entity |
| 8 | #:message-entity-p | 30 | #:message-entity-p |
| 9 | #:copy-message-entity | 31 | #:copy-message-entity |
| 10 | #:message-entity-type | ||
| 11 | #:message-entity-offset | 32 | #:message-entity-offset |
| 12 | #:message-entity-length | 33 | #:message-entity-length |
| 13 | #:message-entity-url | 34 | #:message-entity-url |
| @@ -18,6 +39,27 @@ | |||
| 18 | #:message-entity-extract)) | 39 | #:message-entity-extract)) |
| 19 | (in-package :ukkoclot/src/tg/message-entity) | 40 | (in-package :ukkoclot/src/tg/message-entity) |
| 20 | 41 | ||
| 42 | (define-enum message-entity-type | ||
| 43 | (mention "mention") | ||
| 44 | (hashtag "hashtag") | ||
| 45 | (cashtag "cashtag") | ||
| 46 | (bot-command "bot_command") | ||
| 47 | (url-entity "url") | ||
| 48 | (email "email") | ||
| 49 | (phone-number "phone_number") | ||
| 50 | (bold "bold") | ||
| 51 | (italic "italic") | ||
| 52 | (underline "underline") | ||
| 53 | (strikethrough "strikethrough") | ||
| 54 | (spoiler "spoiler") | ||
| 55 | (blockquote "blockquote") | ||
| 56 | (expandable-blockquote "expandable_blockquote") | ||
| 57 | (code "code") | ||
| 58 | (pre "pre") | ||
| 59 | (text-link "text_link") | ||
| 60 | (text-mention "text_mention") | ||
| 61 | (custom-emoji "custom_emoji")) | ||
| 62 | |||
| 21 | (define-tg-type message-entity | 63 | (define-tg-type message-entity |
| 22 | (type message-entity-type) | 64 | (type message-entity-type) |
| 23 | (offset integer) | 65 | (offset integer) |
| @@ -31,11 +73,16 @@ | |||
| 31 | (error "Some UTF-16 fuckery assumes that system chars are UTF-32")) | 73 | (error "Some UTF-16 fuckery assumes that system chars are UTF-32")) |
| 32 | 74 | ||
| 33 | (defun utf16-width (ch) | 75 | (defun utf16-width (ch) |
| 76 | "Calculate the size of char in UTF-16 units." | ||
| 77 | (declare (type character ch)) | ||
| 34 | (if (< (char-code ch) #x10000) | 78 | (if (< (char-code ch) #x10000) |
| 35 | 1 | 79 | 1 |
| 36 | 2)) | 80 | 2)) |
| 37 | 81 | ||
| 38 | (defun message-entity-extract (entity text) | 82 | (defun message-entity-extract (entity text) |
| 83 | "Extract the text corresponding to the ENTITY from the message text (in TEXT)." | ||
| 84 | (check-type entity message-entity) | ||
| 85 | (check-type text string) | ||
| 39 | (with-slots (length offset) entity | 86 | (with-slots (length offset) entity |
| 40 | (if (zerop length) | 87 | (if (zerop length) |
| 41 | "" | 88 | "" |