1
0
Fork 0

- added comments when composing posts.

This commit is contained in:
cage 2024-09-01 12:06:23 +02:00
parent 11a77bca07
commit 8d1bc99472
4 changed files with 72 additions and 11 deletions

View File

@ -40,7 +40,7 @@ editor = "nano --locking"
# prefix for comments line when composing a post
# line starting with this prefix will *not* be sent to the server
post.comment-line.prefix = ";;"
post.comment-line.prefix = ";"
# allowed languages post, if the regex does not match the post's
# language the post is discarded

View File

@ -997,3 +997,48 @@
text
(cdr mapping))))
text)
(defun print-comment-prefix (stream
format-argument
colon-modifier-supplied-p
at-sign-modifier-supplied-p
&optional (repetitions 1))
(declare (ignore format-argument
colon-modifier-supplied-p
at-sign-modifier-supplied-p
repetitions))
(write-string (swconf:config-post-comment-prefix) stream))
(defun emoji-shortcode-as-comment ()
(let ((emojis (list "🤬" "🧐" "🤯" "🤮" "🤨" "🤫"
"🤪" "🤩" "👿" "😈" "😠" "😡"
"😫" "😩" "😓" "😞" "😣" "😖"
"😭" "😢" "😥" "😰" "😨" "😧"
"😳" "😲" "😯" "😮" "🙁" "😟"
"🤓" "😎" "😵" "🤕" "🤒" "😷"
"🤭" "😤" "😱" "😦" "😕" "😴"
"😪" "😔" "😌" "😬" "🙄" "😒"
"😏" "😶" "😑" "🤐" "🤔" "🤗"
"🤑" "😝" "😜" "😛" "😋" "😙"
"😚" "😗" "😘" "😍" "😇" "😊"
"😉" "🙃" "🙂" "😂" "😅" "😆"
"😁" "😄" "😃" "😀" "🤠" "🤧"
"🤢" "🤤" "🤥" "🤣" "👏" "👊"
"✊" "🖕" "🤘" "👌" "🖖" "✋"
"👋" "🤝" "🤜" "🤛" "🤙" "🤞"
"🤚" "🙏" "👍")))
(with-output-to-string (stream)
(format stream
"~{~/emoji-shortcodes::print-comment-prefix/ ~a~^~a~^~a~^~a~^~%~}"
(mapcar (lambda (emoji)
(a:when-let ((shortcodes-found (remove-if-not (lambda (a)
(string= emoji
(cdr a)))
*shortcodes-db*)))
(with-output-to-string (emoji-stream)
(loop for shortcode in shortcodes-found do
(format emoji-stream
"~a ~a "
(car shortcode)
(cdr shortcode))))))
emojis)))))

View File

@ -1215,10 +1215,12 @@
(defpackage :emoji-shortcodes
(:use :cl)
(:local-nicknames (:a :alexandria))
(:export
:initialize
:shortcode-lookup
:emojify))
:emojify
:emoji-shortcode-as-comment))
(defpackage :software-configuration
(:use

View File

@ -1429,6 +1429,17 @@ It an existing file path is provided the command will refuse to run."
:initial-value (swconf:config-default-post-language)
:prompt (_ "Add language of the post: ")
:complete-fn #'complete:language-codes)))
(remove-comments (body)
(when-let* ((lines (split-lines body))
(comment-re (strcat "^" (swconf:config-post-comment-prefix) ".*"))
(stripped (remove-if #'string-empty-p
(mapcar (lambda (a)
(cl-ppcre:regex-replace comment-re
a
""))
lines))))
(join-with-strings stripped
(format nil "~%"))))
(add-body ()
(let ((temp-file (fs:temporary-file)))
(insert-header-text temp-file)
@ -1443,15 +1454,18 @@ It an existing file path is provided the command will refuse to run."
0)
(> (fs:get-stat-mtime temp-file)
reference-open-file))
(let ((body (emoji-shortcodes:emojify (fs:slurp-file temp-file))))
;; saving "emojified" message
(with-open-file (stream temp-file
:direction :output
:if-exists :supersede
:if-exists :error)
(write-string body stream))
(setf (sending-message:body *message-to-send*) body)
(add-language)))))))
(let ((body (remove-comments
(emoji-shortcodes:emojify
(fs:slurp-file temp-file)))))
(when (string-not-empty-p body)
;; saving "emojified" and uncommented message
(with-open-file (stream temp-file
:direction :output
:if-exists :supersede
:if-exists :error)
(write-string body stream))
(setf (sending-message:body *message-to-send*) body)
(add-language))))))))
(add-body)))
(defun edit-posted-message ()