summaryrefslogtreecommitdiffhomepage
path: root/custom/jao-custom-chats.el
blob: 7f5bfe4201d6112045e3cb4129964d1b9e4b6335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
;; -*- lexical-binding: t -*-


;;;; circe
(defvar jao-libera-channels ())
(defvar jao-oftc-channels ())
(defvar jao-bitlbee-channels ())
(defvar jao-slack-channels ())

(use-package circe
  :ensure t
  :bind (:map circe-channel-mode-map
              (("C-c C-a" . lui-track-jump-to-indicator)))
  :init
  (setq circe-chat-buffer-name "{target} - {network}"
        circe-default-realname "https://jao.io"
        circe-default-part-message ""
        circe-default-quit-message ""
        circe-ignore-list nil
        circe-server-coding-system '(undecided . undecided)
        circe-server-killed-confirmation 'ask-and-kill-all
        circe-server-auto-join-default-type :after-auth
        circe-server-buffer-name "{network} - {host}:{port}"
        circe-format-say "({nick}) {body}"
        circe-format-self-say "(jao) {body}"
        circe-new-buffer-behavior 'ignore
        circe-new-buffer-behavior-ignore-auto-joins t
        circe-nickserv-ghost-style 'after-auth
        circe-prompt-string ": "
        circe-completion-suffix ", "
        circe-reduce-lurker-spam t

        circe-lagmon-mode-line-format-string "" ;;  "%.0f "
        circe-lagmon-mode-line-unknown-lag-string "" ;; "? "
        circe-lagmon-timer-tick 120
        circe-lagmon-reconnect-interval 180

        lui-max-buffer-size 30000
        lui-fill-column 80
        lui-time-stamp-position 'right
        lui-time-stamp-format "%H:%M"
        lui-flyspell-p nil

        lui-track-indicator (if window-system 'fringe 'bar)
        lui-track-behavior 'before-tracking-next-buffer)
  :config

  (defsubst jao-circe-nick-no ()
    (if (derived-mode-p 'circe-query-mode)
        2
      (length (circe-channel-nicks))))

  (defsubst jao-circe-netowrk ()
    (or (plist-get lui-logging-format-arguments :network) ""))

  (define-minor-mode jao-circe-user-number-mode ""
    :lighter (:eval (format " [%s]" (jao-circe-nick-no))))

  (defun jao-circe-channel-hook ()
    (when jao-mode-line-in-minibuffer
      (setq header-line-format
            '(" %b" (:eval (format "@%s - %s nicks"
                                   (jao-circe-netowrk)
                                   (jao-circe-nick-no))))))
    (jao-circe-user-number-mode 1))

  (add-hook 'circe-channel-mode-hook #'jao-circe-channel-hook)
  (add-hook 'circe-query-mode-hook #'jao-circe-channel-hook)

  (defun circe-command-RECOVER (&rest _ignore)
    "Recover nick"
    (jao-with-auth "freenode" u p
      (circe-command-MSG "nickserv" (format "IDENTIFY %s %s" u p))
      (circe-command-MSG "nickserv" (format "GHOST %s" u))
      (circe-command-MSG "nickserv" (format "RELEASE %s" u))
      (circe-command-NICK u)))

  (defun circe-command-NNICKS (&rest _)
    "Echo number of nicks"
    (circe-display-server-message
     (format "%d nicks in this channel" (jao-circe-nick-no))))

  (defun circe-command-SENDFILE (line)
    "/sendfile for localslackirc"
    (circe-command-QUOTE (format "sendfile %s" line)))

  (advice-add 'circe-command-NAMES :after #'circe-command-NNICKS)

  (defun jao-circe-reconnect-unmonitored ()
    (interactive)
    (dolist (b (buffer-list))
      (with-current-buffer b
        (when (and (derived-mode-p 'circe-server-mode)
                   circe-lagmon-disabled)
          (circe-reconnect)))))

  (add-to-list 'jao-sleep-awake-functions #'jao-circe-reconnect-unmonitored)

  (setq circe-network-options
        (list (jao-with-auth "libera" u p
                (list "Libera Chat" :nick u :channels jao-libera-channels
                      :tls t :sasl-username u :sasl-password p))
              (jao-with-auth "oftc" u p
                (list "OFTC"
                      :nick u :channels jao-oftc-channels :nickserv-password p
                      :tls t :sasl-username u :sasl-password p))
              (jao-with-auth "bitlbee" u p
                (list "Bitlbee" :host "127.0.0.1" :nick u
                      :channels jao-bitlbee-channels :lagmon-disabled t
                      :nickserv-password u :user p))))

  (jao-shorten-modes 'circe-channel-mode
                     'circe-server-mode
                     'circe-query-mode)

  (enable-circe-display-images)
  (enable-lui-track)
  (circe-lagmon-mode))

;;;; telegram
(use-package telega
  :ensure t
  :custom
  (telega-use-tracking-for '(unmuted) ;; '(or unmuted mention)
                           telega-rainbow-color-custom-for nil
                           telega-msg-rainbow-title nil
                           telega-sticker-set-download t
                           telega-symbol-checkmark "·"
                           telega-symbol-heavy-checkmark "×"
                           telega-symbol-verified "*")
  :config
  (define-key global-map (kbd "C-c C-t") telega-prefix-map)
  (setq telega-chat-show-avatars nil
        telega-chat-prompt-insexp '(telega-ins "> ")
        telega-completing-read-function #'completing-read
        telega-root-show-avatars nil
        telega-emoji-use-images nil
        telega-temp-dir "/tmp/telega"
        telega-symbol-horizontal-bar
        (propertize "-" 'face 'jao-themes-f00)
        telega-symbol-vertical-bar
        (propertize "| " 'face 'jao-themes-dimm)
        telega-mode-line-string-format
        '(:eval (telega-mode-line-unread-unmuted))
        telega-use-images (display-graphic-p)
        telega-open-file-function #'jao--see
        telega-open-message-as-file
        (unless (display-graphic-p) '(photo video animation)))
  (with-eval-after-load "tracking"
    (jao-shorten-modes 'telega-chat-mode)
    (jao-tracking-faces 'telega-tracking))
  (telega-mode-line-mode 1))

(defun jao-telega ()
  (interactive)
  (jao-tracking-go-to-chats)
  (if (get-buffer telega-root-buffer-name)
      (pop-to-buffer telega-root-buffer-name)
    (telega)))

;;;; ement
(use-package ement
  :disabled t
  :ensure t
  :init (setq ement-save-sessions t
              ement-sessions-file (locate-user-emacs-file "cache/ement.el")
              ement-room-avatars nil
              ement-notify-dbus-p nil
              ement-room-left-margin-width 0
              ement-room-right-margin-width 11
              ement-room-timestamp-format "%H:%M"
              ement-room-timestamp-header-format "­­--------")

  :custom ((ement-room-message-format-spec "(%S) %B%r%R %t"))

  :config
  (defun jao-ement-track (event room session)
    (when (ement-notify--room-unread-p event room session)
      (when-let ((n (ement-room--buffer-name room))
                 (b (get-buffer n)))
        (tracking-add-buffer b))))

  (add-hook 'ement-event-hook #'jao-ement-track)
  (jao-shorten-modes 'ement-room-mode)
  (jao-tracking-cleaner "^\\*Ement Room: \\(.+\\)\\*" "@\\1"))

;;;; mastodon
(use-package mastodon
  :ensure t
  :init
  (setq mastodon-instance-url "https://fosstodon.org"
        mastodon-active-user "jao@gnu.org"
        mastodon-group-notifications t
        mastodon-images-in-notifs t
        mastodon-tl-position-after-update nil
        mastodon-toot-display-orig-in-reply-buffer t
        mastodon-media--hide-sensitive-media nil)
  :config
  ;; (defun jao-mastodon--setup ()
  ;;   (setq-local scroll-margin 12))

  ;; (add-hook 'mastodon-mode-hook #'jao-mastodon--setup)
  (with-eval-after-load "ewww"
    (define-key eww-mode-map (kbd "T") #'jao-mastodon-toot-url)))

(defun jao-mastodon-toot-url ()
  (interactive)
  (when-let (url (jao-url-around-point t))
    (jao-tracking-go-to-chats)
    (mastodon-toot--compose-buffer nil nil nil url)))

(defun jao-mastodon ()
  (interactive)
  (jao-afio-goto-chats)
  (mastodon))

;; https://0x0.st/XJ14.txt
(jao-transient-major-mode mastodon
  ["Timelines"
   ("H" "home"            mastodon-tl--get-home-timeline)
   ("L" "local"           mastodon-tl--get-local-timeline)
   ("F" "federated"       mastodon-tl--get-federated-timeline)
   ("K" "bookmarks"       mastodon-profile--view-bookmarks)
   ("V" "favorites"       mastodon-profile--view-favourites)
   ("'" "followed tags"   mastodon-tl--followed-tags-timeline)
   ("@" "mentions"        mastodon-notifications--get-mentions)
   ("N" "notifications"   mastodon-notifications-get)
   ("\\" "of remote host" mastodon-tl--get-remote-local-timeline)]

  ;; u                    mastodon-tl--update

  ["Search"
   ("s" "search"          mastodon-search--query)
   ("#" "tagged"          mastodon-tl--get-tag-timeline)
   ("\"" "followed tags"  mastodon-tl--list-followed-tags)
   ("I" "filter"          mastodon-views--view-filters)
   ("X" "lists"           mastodon-views--view-lists)]

  ["Toots"
   ("n" "next"            mastodon-tl--goto-next-item :transient t)
   ("p" "prev"            mastodon-tl--goto-prev-item :transient t)
   ("c" "spoiler"         mastodon-tl--toggle-spoiler-text-in-toot :transient t)
   ("T" "thread"          mastodon-tl--thread)
   ("b" "(un)boost"       mastodon-toot--toggle-boost :transient t)
   ("f" "(un)fav"         mastodon-toot--toggle-favourite :transient t)
   ("i" "(un)pin"         mastodon-toot--pin-toot-toggle :transient t)
   ("k" "(un)bookmark"    mastodon-toot--toggle-bookmark :transient t)
   ("v" "vote"            mastodon-tl--poll-vote)]

  ;; Z                    mastodon-tl--report-to-mods
  ;; o                    mastodon-toot--open-toot-url

  ["Own Toots"
   ("r" "replay"          mastodon-toot--reply)
   ("t" "write"           mastodon-toot)
   ("e" "edit"            mastodon-toot--edit-toot-at-point)
   ("d" "delete"          mastodon-toot--delete-toot)
   ("D" "del & redraft"   mastodon-toot--delete-and-redraft-toot)
   ("E" "show edits"      mastodon-toot--view-toot-edits)]

  ;; S                    mastodon-views--view-scheduled-toots

  ["Users"
   ("W" "follow"          mastodon-tl--follow-user)
   ("R" "follow req"      mastodon-views--view-follow-requests)
   ("G" "suggestions"     mastodon-views--view-follow-suggestions)
   ("M" "mute user"       mastodon-tl--mute-user)
   ("B" "block user"      mastodon-tl--block-user)
   ("m" "message user"    mastodon-tl--dm-user)
   ;; ""
   ;; ("," "favouriters"     mastodon-toot--list-toot-favouriters)
   ;; ("." "boosters"        mastodon-toot--list-toot-boosters)
   ]

  ;; S-RET                mastodon-tl--unmute-user
  ;; C-S-b                mastodon-tl--unblock-user

  ["Profiles"
   ("A" "author"          mastodon-profile--get-toot-author)
   ("P" "any user"        mastodon-profile--show-user)
   ("O" "own"             mastodon-profile--my-profile)
   ("U" "update own"      mastodon-profile--update-user-profile-note)]

  ["Misc"
   ("C" "copy URL"        mastodon-toot--copy-toot-url)
   ("?" "help"            describe-mode)
   ("q" "quit"            transient-quit-one)])

;;;; startup
(defun jao-chats (&optional p)
  (interactive "P")
  (when (or p (y-or-n-p "Connect to telegram? "))
    (telega))
  (when (and (fboundp 'ement-connect) (or p (y-or-n-p "Connect to matrix? ")))
    (unless (get-buffer "*Ement Rooms*")
      (jao-with-auth "matrix.org" u p (ement-connect :user-id u :password p))))
  ;; (when (and (fboundp 'mastodon) (or p (y-or-n-p "Connect to mastodon? ")))
  ;;   (mastodon))
  (dolist (c '(("Libera Chat" . "irc.libera.chat:6697")))
    (unless (get-buffer (cdr c))
      (when (or p (y-or-n-p (format "Connect to %s? " (car c))))
        (circe (car c))))))

(defun jao-all-chats ()
  (interactive)
  (when jao-tracking-use-scratch
    (jao-afio-goto-chats)
    (delete-other-windows))
  (jao-chats t))

(defun jao-chats-telega ()
  (interactive)
  (jao-buffer-same-mode '(telega-root-mode telega-chat-mode)))

(defun jao-chats-slack ()
  (interactive)
  (jao-buffer-same-mode 'slack-message-buffer-mode))

(defun jao-chats-irc ()
  (interactive)
  (jao-buffer-same-mode '(circe-channel-mode circe-query-mode erc-mode)))

;;;; consult narrowing
(defvar jao-chat-buffer-source
  (list :name "chats"
        :category 'buffer
        :action (lambda (b) (jao-afio-pop-to-buffer 0 b))
        :hidden t
        :narrow (cons ?c "chats")
        :items (jao-consult--mode-buffers 'erc-mode
                                          'circe-channel-mode
                                          'circe-query-mode
                                          'signel-chat-mode
                                          'slack-message-buffer-mode
                                          'slack-thread-message-buffer-mode
                                          'telega-root-mode
                                          'telega-chat-mode
                                          'ement-room-mode
                                          'ement-room-list-mode)))
(with-eval-after-load "consult"
  (jao-consult-add-buffer-source 'jao-chat-buffer-source))


(provide 'jao-custom-chats)