From 59ee28eef66244e649aed6b9e4ce956009f10417 Mon Sep 17 00:00:00 2001 From: js0ny Date: Thu, 27 Feb 2025 03:26:18 +0000 Subject: [PATCH] feat(emacs-org): Add telegram notifications --- LICENSE | 2 +- tools/doom/+pomodoro-telegram.el | 51 ++++++++++++++++++++++++++++++++ tools/doom/.gitignore | 2 ++ tools/doom/custom.el | 15 ---------- tools/doom/init.el | 17 ++++++----- tools/doom/org.el | 2 ++ 6 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 tools/doom/+pomodoro-telegram.el create mode 100644 tools/doom/.gitignore delete mode 100644 tools/doom/custom.el diff --git a/LICENSE b/LICENSE index f288702..e00be19 100644 --- a/LICENSE +++ b/LICENSE @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Copyright (C) + dotfiles Copyright (C) 2024-2025 js0ny This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/tools/doom/+pomodoro-telegram.el b/tools/doom/+pomodoro-telegram.el new file mode 100644 index 0000000..e6493fd --- /dev/null +++ b/tools/doom/+pomodoro-telegram.el @@ -0,0 +1,51 @@ +;;; org-pomodoro-telegram-notifier.el --- 发送 Telegram 通知当 org-pomodoro 休息结束 + +(require 'org-pomodoro) +(require 'request) + +(defcustom org-pomodoro-telegram-bot-token "" + "你的 Telegram Bot Token。" + :type 'string + :group 'org-pomodoro) + +(defcustom org-pomodoro-telegram-chat-id "" + "接收通知的 Telegram Chat ID。" + :type 'string + :group 'org-pomodoro) + +(defcustom org-pomodoro-telegram-break-end-message "休息时间结束" + "休息结束时发送的消息。" + :type 'string + :group 'org-pomodoro) + +(defun org-pomodoro-send-telegram-message (message) + (interactive) + "使用 Telegram bot 发送消息。" + (when (and (not (string-empty-p org-pomodoro-telegram-bot-token)) + (not (string-empty-p org-pomodoro-telegram-chat-id))) + (request + (format "https://api.telegram.org/bot%s/sendMessage" org-pomodoro-telegram-bot-token) + :type "POST" + :data `(("chat_id" . ,org-pomodoro-telegram-chat-id) + ("text" . ,"⏳[Emacs] org-pomodoro: 休息时间结束") + ("parse_mode" . "HTML")) + :parser 'json-read + :success (cl-function + (lambda (&key data &allow-other-keys) + (message "成功发送 Telegram 通知"))) + :error (cl-function + (lambda (&key error-thrown &allow-other-keys) + (message "发送 Telegram 通知失败: %S" error-thrown)))) + ) + ) + +(defun org-pomodoro-telegram-break-finished-hook () + "当休息时间结束时发送 Telegram 通知。" + (org-pomodoro-send-telegram-message org-pomodoro-telegram-break-end-message)) + +(add-hook 'org-pomodoro-break-finished-hook #'org-pomodoro-telegram-break-finished-hook) +(add-hook 'org-pomodoro-long-break-finished-hook #'org-pomodoro-telegram-break-finished-hook) + + +(provide 'org-pomodoro-telegram-notifier) +;;; org-pomodoro-telegram-notifier.el ends here diff --git a/tools/doom/.gitignore b/tools/doom/.gitignore new file mode 100644 index 0000000..57fbc5e --- /dev/null +++ b/tools/doom/.gitignore @@ -0,0 +1,2 @@ +org-pomo-music.el +.custom.el diff --git a/tools/doom/custom.el b/tools/doom/custom.el deleted file mode 100644 index 9f75dcb..0000000 --- a/tools/doom/custom.el +++ /dev/null @@ -1,15 +0,0 @@ -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(custom-safe-themes - '("5c7720c63b729140ed88cf35413f36c728ab7c70f8cd8422d9ee1cedeb618de5" "e4a702e262c3e3501dfe25091621fe12cd63c7845221687e36a79e17cf3a67e0" "456697e914823ee45365b843c89fbc79191fdbaff471b29aad9dcbe0ee1d5641" "3c08da65265d80a7c8fc99fe51df3697d0fa6786a58a477a1b22887b4f116f62" "df6dfd55673f40364b1970440f0b0cb8ba7149282cf415b81aaad2d98b0f0290" "0325a6b5eea7e5febae709dab35ec8648908af12cf2d2b569bedc8da0a3a81c1" "d6b934330450d9de1112cbb7617eaf929244d192c4ffb1b9e6b63ad574784aad" "56044c5a9cc45b6ec45c0eb28df100d3f0a576f18eef33ff8ff5d32bac2d9700" "2b501400e19b1dd09d8b3708cefcb5227fda580754051a24e8abf3aff0601f87" default))) -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(org-verbatim ((t (:foreground "orange"))))) -(put 'customize-face 'disabled nil) -(put 'customize-variable 'disabled nil) diff --git a/tools/doom/init.el b/tools/doom/init.el index dbcb574..369e5e5 100644 --- a/tools/doom/init.el +++ b/tools/doom/init.el @@ -121,7 +121,7 @@ ;;coq ; proofs-as-programs ;;crystal ; ruby at the speed of c ;;csharp ; unity, .NET, and mono shenanigans - ;;data ; config/data formats + data ; config/data formats ;;(dart +flutter) ; paint ui and not much else ;;dhall ;;elixir ; erlang done right @@ -140,15 +140,15 @@ (haskell +lsp) ; a language that's lazier than I am ;;hy ; readability of scheme w/ speed of python ;;idris ; a language you can depend on - ;;json ; At least it ain't XML + (json +lsp +tree-sitter) ; At least it ain't XML ;;(java +lsp) ; the poster child for carpal tunnel syndrome ;;javascript ; all(hope(abandon(ye(who(enter(here)))))) ;;julia ; a better, faster MATLAB ;;kotlin ; a better, slicker Java(Script) - latex ; writing papers in Emacs has never been so fun + (latex +latexmk +cdlatex +lsp) ; writing papers in Emacs has never been so fun ;;lean ; for folks with too much to prove ;;ledger ; be audit you can be - lua ; one-based indices? one-based indices + ;lua ; one-based indices? one-based indices markdown ; writing docs for people to ignore ;;nim ; python + lisp at the speed of c ;;nix ; I hereby declare "nix geht mehr!" @@ -164,7 +164,7 @@ ;;plantuml ; diagrams for confusing people more ;;graphviz ; diagrams for confusing yourself even more ;;purescript ; javascript, but functional - python ; beautiful is better than ugly + (python +lsp +tree-sitter +pyright) ; beautiful is better than ugly ;;qt ; the 'cutest' gui framework ever ;;racket ; a DSL for DSLs ;;raku ; the artist formerly known as perl6 @@ -174,13 +174,13 @@ ;;(rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap() ;;scala ; java, but good (scheme +guile) ; a fully conniving family of lisps - sh ; she sells {ba,z,fi}sh shells on the C xor + (sh +lsp +tree-sitter +fish) ; she sells {ba,z,fi}sh shells on the C xor ;;sml ;;solidity ; do you need a blockchain? No. ;;swift ; who asked for emoji variables? ;;terra ; Earth and Moon in alignment for performance. ;;web ; the tubes - ;;yaml ; JSON, but readable + (yaml +lsp +tree-sitter) ; JSON, but readable ;;zig ; C, but simpler :email @@ -198,3 +198,6 @@ :config ;;literate (default +bindings +smartparens)) + +(setq custom-file (expand-file-name ".custom.el" doom-user-dir)) +(load custom-file t) diff --git a/tools/doom/org.el b/tools/doom/org.el index efe108f..7849347 100644 --- a/tools/doom/org.el +++ b/tools/doom/org.el @@ -100,3 +100,5 @@ (if (bound-and-true-p ISMAC) (setq org-babel-C-compiler "clang")) + +(load! "+pomodoro-telegram.el")