mirror of https://codeberg.org/cage/tinmop/
- [TUI] added conversion of shortcodes to emoji when composing a fediverse post.
This commit is contained in:
parent
29e562e669
commit
b14dd9e87e
31
LICENSES.org
31
LICENSES.org
|
@ -641,3 +641,34 @@
|
||||||
[CC BY 3.0 us (https://creativecommons.org/licenses/by/3.0/us/deed.en)],
|
[CC BY 3.0 us (https://creativecommons.org/licenses/by/3.0/us/deed.en)],
|
||||||
via Wikimedia Commons
|
via Wikimedia Commons
|
||||||
https://commons.wikimedia.org/wiki/Farm-Fresh_web_icons
|
https://commons.wikimedia.org/wiki/Farm-Fresh_web_icons
|
||||||
|
|
||||||
|
- data/emoji-shortcodes.json
|
||||||
|
|
||||||
|
got from:
|
||||||
|
|
||||||
|
https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/shortcodes/github.raw.json
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright © 2017-2019 Miles Johnson
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
according to:
|
||||||
|
https://github.com/milesj/emojibase
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -951,10 +951,50 @@
|
||||||
(":glad:" . "😃")
|
(":glad:" . "😃")
|
||||||
(":gleeful:" . "😀")))
|
(":gleeful:" . "😀")))
|
||||||
|
|
||||||
|
(defun load-table ()
|
||||||
|
(let ((file (res:get-data-file (text-utils:strcat "data/" "emoji-shortcodes.json"))))
|
||||||
|
(with-open-file (stream file :direction :input)
|
||||||
|
(let ((table (yason:parse stream))
|
||||||
|
(results '()))
|
||||||
|
(labels ((code->emoji (code)
|
||||||
|
(if (cl-ppcre:scan "-" code)
|
||||||
|
(let ((codes (mapcar (lambda (a) (code-char (parse-integer a
|
||||||
|
:radix 16)))
|
||||||
|
(cl-ppcre:split "-" code))))
|
||||||
|
(format nil "~{~c~}" codes))
|
||||||
|
(format nil "~c" (code-char (parse-integer code :radix 16)))))
|
||||||
|
(append-emoji (code-point shortcode)
|
||||||
|
(setf results (acons (format nil ":~a:" shortcode)
|
||||||
|
(code->emoji code-point)
|
||||||
|
results)))
|
||||||
|
(maybe-append-kebab (code-point shortcode)
|
||||||
|
(when (cl-ppcre:scan "_" shortcode)
|
||||||
|
(format t "s ~a~%" shortcode)
|
||||||
|
(append-emoji code-point
|
||||||
|
(cl-ppcre:regex-replace-all "_"
|
||||||
|
shortcode
|
||||||
|
"-")))))
|
||||||
|
(maphash (lambda (code-point shortcodes)
|
||||||
|
(etypecase shortcodes
|
||||||
|
(string
|
||||||
|
(maybe-append-kebab code-point shortcodes)
|
||||||
|
(append-emoji code-point shortcodes))
|
||||||
|
(list
|
||||||
|
(loop for shortcode in shortcodes do
|
||||||
|
(maybe-append-kebab code-point shortcode)
|
||||||
|
(append-emoji code-point shortcode)))))
|
||||||
|
table)
|
||||||
|
results)))))
|
||||||
|
|
||||||
|
(defun initialize ()
|
||||||
|
(ignore-errors (setf *shortcodes-db* (load-table))))
|
||||||
|
|
||||||
(defun shortcode-lookup (key)
|
(defun shortcode-lookup (key)
|
||||||
(assoc key *shortcodes-db* :test #'string-equal))
|
(assoc key *shortcodes-db* :test #'string-equal))
|
||||||
|
|
||||||
(defun emojify (text)
|
(defun emojify (text)
|
||||||
(loop for mapping in *shortcodes-db* do
|
(loop for mapping in *shortcodes-db* do
|
||||||
(setf text (cl-ppcre:regex-replace-all (car mapping) text (cdr mapping))))
|
(setf text (cl-ppcre:regex-replace-all (text-utils:strcat "(?i)" (car mapping))
|
||||||
|
text
|
||||||
|
(cdr mapping))))
|
||||||
text)
|
text)
|
||||||
|
|
|
@ -268,6 +268,7 @@ etc.) happened"
|
||||||
"The entry point function of the program"
|
"The entry point function of the program"
|
||||||
(init-i18n)
|
(init-i18n)
|
||||||
(res:init)
|
(res:init)
|
||||||
|
(emoji-shortcodes:initialize)
|
||||||
(command-line:manage-opts)
|
(command-line:manage-opts)
|
||||||
(cond
|
(cond
|
||||||
(command-line:*start-dummy-server*
|
(command-line:*start-dummy-server*
|
||||||
|
|
|
@ -1216,6 +1216,7 @@
|
||||||
(defpackage :emoji-shortcodes
|
(defpackage :emoji-shortcodes
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
(:export
|
(:export
|
||||||
|
:initialize
|
||||||
:shortcode-lookup
|
:shortcode-lookup
|
||||||
:emojify))
|
:emojify))
|
||||||
|
|
||||||
|
|
|
@ -1443,7 +1443,13 @@ It an existing file path is provided the command will refuse to run."
|
||||||
0)
|
0)
|
||||||
(> (fs:get-stat-mtime temp-file)
|
(> (fs:get-stat-mtime temp-file)
|
||||||
reference-open-file))
|
reference-open-file))
|
||||||
(let ((body (fs:slurp-file temp-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)
|
(setf (sending-message:body *message-to-send*) body)
|
||||||
(add-language)))))))
|
(add-language)))))))
|
||||||
(add-body)))
|
(add-body)))
|
||||||
|
|
Loading…
Reference in New Issue