summaryrefslogtreecommitdiffstats
path: root/emacsconf-erc.el
blob: 8f47d3602d7533c41a283eaf9071faa7383e920d (plain) (blame)
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
;;; emacsconf-erc.el --- Integrate with Emacs Relay Chat  -*- lexical-binding: t; -*-

;; Copyright (C) 2022  Sacha Chua

;; Author: Sacha Chua <sacha@sachachua.com>
;; Keywords: 

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Goals:
;; - Announce talks and Q&A sessions
;; - Change talk status and trigger hooks
;;
;; Commands:
;;
;; announcements only
;; - /nowplaying slug
;; - /nowclosedq slug
;; - /nowopenq slug
;; - /nowunstreamedq slug
;; - /nowdone slug

;; use M-x emacsconf-erc-add-to-todo-hook in conf.org to have the announcements triggered by todo state changes
;; 
;; updating task status
;; - /markplaying slug
;; - /markclosedq slug
;; - /markopenq slug
;; - /markunstreamedq slug
;; - /markdone slug
;;
;; general
;; - /broadcast message
;; - /conftopic message
;; - /checkin nick
;; 
;;; Code:

(defcustom emacsconf-collaborative-pad
  (concat "https://etherpad.wikimedia.org/p/emacsconf-" emacsconf-year)
  "URL for the pad that will have questions."
  :group 'emacsconf
  :type 'string)

(defcustom emacsconf-streaming-nick nil "Set to the host's IRC nick in order to notify them."
  :group 'emacsconf
  :type 'string)

(defcustom emacsconf-erc-hallway "#emacsconf" "Channel for hallway conversations")
(defcustom emacsconf-erc-org "#emacsconf-org" "Channel for organizers")

(defcustom emacsconf-topic-templates
  '(("#emacsconf" "EmacsConf 2022 | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")
    ("#emacsconf-gen" "General track | https://emacsconf.org/2022/watch/gen/ | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")
    ("#emacsconf-dev" "Development track | https://emacsconf.org/2022/watch/dev/ | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")
    ("#emacsconf-accessible" "EmacsConf 2022 accessibility - help by describing what's happening | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")
    ("#emacsconf-org" "EmacsConf 2022 | Dedicated channel for EmacsConf organizers and speakers | this is intended as an internal, low-traffic channel; for main discussion around EmacsConf, please join #emacsconf | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")
    ("#emacsconf-questions" "EmacsConf 2022 | Low-traffic channel for questions if speakers prefer IRC and need help focusing; for main discussion around EmacsConf, please join #emacsconf | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates"))
  "List of (channel topic-template) entries for mass-setting channel topics."
  :group 'emacsconf
  :type '(repeat (list (string :tag "Channel")
                       (string :tag "Topic suffix"))))

;; For testing: (setq emacsconf-topic-templates '(("#emacsconf-test" "EmacsConf 2022 | Dedicated channel for EmacsConf organizers and speakers | this is intended as an internal, low-traffic channel; for main discussion around EmacsConf, please join #emacsconf | Subscribe to https://lists.gnu.org/mailman/listinfo/emacsconf-discuss for updates")))

(defmacro emacsconf-erc-with-channels (channel-list &rest forms)
  (declare (indent 1) (debug (form form body)))
  `(mapcar (lambda (channel)
             (unless (erc-get-buffer channel)
               (erc-join-channel channel))
             (with-current-buffer (erc-get-buffer channel)
               ,@forms))
           ,channel-list))

(defun erc-cmd-CONFTOPIC (&rest message)
  "Set the topic to MESSAGE | template in the EmacsConf channels.
If MESSAGE is not specified, reset the topic to the template."
  (mapc (lambda (template) 
          (with-current-buffer (erc-get-buffer (car template))
            (erc-cmd-TOPIC (if message (concat (if (stringp message) message (s-join " " message)) " | " (cadr template))
                             (cadr template)))))
        emacsconf-topic-templates))

(defun erc-cmd-CHECKIN (nick)
  (let* ((talk (emacsconf-complete-talk-info))
         (q-and-a (plist-get talk :q-and-a) ""))
    (save-excursion
      (emacsconf-with-talk-heading (plist-get talk :slug)
        (org-entry-put (point) "IRC" nick)
        (org-entry-put (point) "CHECK_IN" (format-time-string "%H:%M"))))
    (cond
     ((string-match "live" q-and-a)
      (erc-send-message (format "%s: Thanks for checking in! I'll send you some private messages with instructions, so please check there. Let me know if you don't get them." nick))
      (erc-cmd-ROOM nick talk))
     ((string-match "pad" q-and-a)
      (erc-send-message (format "%s: Thanks for checking in! The collaborative pad we'll be using for questions is at %s . We'll collect questions and put them there. If you'd like to open it, you can keep  an eye on questions. Please let us know if you need help, or if you want to switch to live Q&A." nick (plist-get talk :pad-url))))
     ((string-match "IRC" q-and-a)
      (erc-send-message (format "#%s: Thanks for checking in! Feel free to keep an eye on %s for questions and discussion, and we'll copy things from the pad to there. If the volume gets overwhelming, let us know and we can /msg you questions or add them to the pad. If you'd like to try Q&A over live video or the collaborative pad instead, or if you need help, please let us know." nick
                                (plist-get (emacsconf-get-track (plist-get talk :track)) :channel))))
     (t (erc-send-message (format "%s: Thanks for checking in! How would you like to handle Q&A today - live video, the collaborative Etherpad at %s , or IRC (like this)?" nick (plist-get) emacsconf-collaborative-pad))))
    (when (functionp 'emacsconf-upcoming-insert-or-update)
      (emacsconf-with-talk-heading (plist-get talk :slug)
        (emacsconf-upcoming-insert-or-update nil t)))))

(defun erc-cmd-BBB (nick &optional talk)
  "Send live Q&A instructions to NICK."
  (setq talk (or talk (emacsconf-complete-talk-info)))
  (erc-message "PRIVMSG" (format "%s You can use this BBB room: %s . We'll join you there shortly to set up the room and do the last-minute tech check." nick (plist-get talk :bbb-room)))
  (erc-message "PRIVMSG" (format "%s The collaborative pad we'll be using for questions is at %s . We'll collect questions from #emacsconf and put them there. If you'd like to jump to your part of the document, you might be able to keep an eye on questions. Alternatively, we can read questions to you." nick (plist-get talk :pad-url)))
  (erc-message "PRIVMSG" (format "%s The host will join and give you the go-ahead when you go on air. See you in the BBB room!" nick)))

(defun erc-cmd-READY (&rest filter)
  "Notify #emacsconf-org and `emacsconf-streaming-nick' that the speaker is ready."
  (let ((talk (emacsconf-find-talk-info filter))
        pronunciation)
    (unless talk (error "Could not find talk"))
    (setq pronunciation (plist-get talk :pronunciation))
    (emacsconf-erc-with-channels (list emacsconf-erc-org)
      (erc-send-message (format "Ready: %s (%s)" (plist-get talk :title) (plist-get talk :speakers))))
    (mapc (lambda (nick)
            (erc-message "PRIVMSG" 
                         (format "%s ready in %s: %s (%s) %s %s"
                                 emacsconf-nick
                                 (plist-get talk :bbb-room)
                                 (plist-get talk :title)
                                 (plist-get talk :speakers-with-pronouns)
                                 (or pronunciation ""))))
          (if (listp emacsconf-streaming-nick) emacsconf-streaming-nick (list emacsconf-streaming-nick)))))

;;; Announcements

(defvar emacsconf-erc-check-against-recent-announcements 10
	"Number of minutes since most recent announcement.")

(defun emacsconf-erc-recently-announced (string)
	"Return non-nil if STRING was recently announced."
	(when emacsconf-erc-check-against-recent-announcements
		(let ((threshold-time
					 (time-add (current-time)
										 (seconds-to-time
											(* 60 emacsconf-erc-check-against-recent-announcements)))))
			(seq-find (lambda (entry)
									(and (string-match (regexp-quote string) (car entry))
											 (time-less-p (cdr entry)
																		threshold-time)))
								emacsconf-erc-recent-announcements))))

(defun erc-cmd-NOWPLAYING (talk)
  "Set the channel topics to announce TALK."
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (or (emacsconf-find-talk-info talk) (error "Could not find talk %s" talk)))) 
  ;; Announce it in the track's channel
	(if (emacsconf-erc-recently-announced (format "---- %s:" (plist-get talk :slug)))
			(message "Recently announced, skipping")
		(when (plist-get talk :track)
			(emacsconf-erc-with-channels (list (concat "#" (plist-get talk :channel)))
				(erc-cmd-TOPIC (format "%s: %s (%s) pad: %s Q&A: %s | %s"
															 (plist-get talk :slug)
															 (plist-get talk :title)                               
															 (plist-get talk :speakers)
															 (plist-get talk :pad-url)
															 (plist-get talk :qa-info)
															 (car (assoc-default (concat "#" (plist-get talk :channel)) emacsconf-topic-templates))))
				(erc-send-message (format "---- %s: %s - %s ----"
																	(plist-get talk :slug)
																	(plist-get talk :title)
																	(plist-get talk :speakers-with-pronouns)))
				(erc-send-message (concat "Add your notes/questions to the pad: " (plist-get talk :pad-url)))
				(cond
				 ((string-match "live" (or (plist-get talk :q-and-a) ""))
					(erc-send-message (concat "Live Q&A: " (plist-get talk :bbb-redirect))))
				 ((plist-get talk :irc)
					(erc-send-message (format "or discuss the talk on IRC (nick: %s)"
																		(plist-get talk :irc)))))))
		;; Short announcement in #emacsconf
		(emacsconf-erc-with-channels (list emacsconf-erc-hallway emacsconf-erc-org)
			(erc-send-message (format "-- %s track: %s: %s (watch: %s, pad: %s, channel: #%s)"
																(plist-get talk :track)
																(plist-get talk :slug)
																(plist-get talk :title)                               
																(plist-get talk :watch-url)
																(plist-get talk :pad-url)
																(plist-get talk :channel))))))

(defun erc-cmd-NOWCLOSEDQ (talk)
  "Announce TALK has started Q&A, but the host has not yet opened it up."
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (or (emacsconf-find-talk-info talk) (error "Could not find talk %s" talk))))
	(if (emacsconf-erc-recently-announced (format "-- Q&A beginning for \"%s\"" (plist-get talk :slug)))
			(message "Recently announced, skipping")
		(emacsconf-erc-with-channels (list (concat "#" (plist-get talk :channel)))
			(erc-send-message (format "-- Q&A beginning for \"%s\" (%s) Watch: %s Add notes/questions: %s"
																(plist-get talk :title)
																(plist-get talk :qa-info)
																(plist-get talk :watch-url)
																(plist-get talk :pad-url))))  
		(emacsconf-erc-with-channels (list emacsconf-erc-hallway emacsconf-erc-org)
			(erc-send-message (format "-- Q&A beginning for \"%s\" in the %s track (%s) Watch: %s Add notes/questions: %s . Chat: #%s"
																(plist-get talk :title)
																(plist-get talk :track)
																(plist-get talk :qa-info)
																(plist-get talk :watch-url)
																(plist-get talk :pad-url)
																(plist-get talk :channel))))))

(defun erc-cmd-NOWOPENQ (talk)
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (or (emacsconf-find-talk-info talk) (error "Could not find talk %s" talk))))
	(if (emacsconf-erc-recently-announced (format "-- Q&A now open for \"%s\"" (plist-get talk :slug)))
			(message "Recently announced, skipping")
		(emacsconf-erc-with-channels (list (concat "#" (plist-get talk :channel)))
			(erc-send-message (format "-- Q&A now open for \"%s\" (%s). Watch: %s Add notes/questions: %s ."
																(plist-get talk :title)
																(plist-get talk :qa-info)
																(plist-get talk :watch-url)
																(plist-get talk :pad-url))))  
		(emacsconf-erc-with-channels (list emacsconf-erc-hallway emacsconf-erc-org)
			(erc-send-message (format "-- Q&A now open for \"%s\" in the %s track (%s). Watch: %s Add notes/questions: %s IRC: #%s"
																(plist-get talk :title)
																(plist-get talk :track)
																(plist-get talk :qa-info)
																(plist-get talk :watch-url)
																(plist-get talk :pad-url)
																(plist-get talk :channel))))))

(defun erc-cmd-NOWUNSTREAMEDQ (talk)
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (or (emacsconf-find-talk-info talk) (error "Could not find talk %s" talk))))
	(if (emacsconf-erc-recently-announced (format "-- Q&A continues off-stream for \"%s\"" (plist-get talk :slug)))
			(message "Recently announced, skipping")
		(emacsconf-erc-with-channels (list (concat "#" (plist-get talk :channel)))
			(erc-send-message (format "-- Q&A continues off-stream for \"%s\" (%s) Add notes/questions: %s ."
																(plist-get talk :title)
																(plist-get talk :qa-info)
																(plist-get talk :pad-url))))  
		(emacsconf-erc-with-channels (list emacsconf-erc-hallway emacsconf-erc-org)
			(erc-send-message (format "-- Q&A continues off-stream for \"%s\" in the %s track (%s) Add notes/questions: %s IRC: #%s"
																(plist-get talk :title)
																(plist-get talk :track)
																(plist-get talk :qa-info)
																(plist-get talk :pad-url)
																(concat "#" (plist-get talk :channel)))))))

(defun erc-cmd-NOWDONE (talk)
	(interactive (list (emacsconf-complete-talk-info)))
	(when (stringp talk) (setq talk (or (emacsconf-find-talk-info talk) (error "Could not find talk %s" talk))))
	(if (emacsconf-erc-recently-announced (format "-- Q&A finished for \"%s\"" (plist-get talk :slug)))
			(message "Recently announced, skipping")
		(emacsconf-erc-with-channels (list (concat "#" (plist-get talk :channel)))
			(erc-send-message (format "-- Q&A finished for \"%s\". Add notes/questions: %s %s"
																(plist-get talk :title)
																(plist-get talk :pad-url)
																(emacsconf-surround " Speaker IRC nick: " (plist-get talk :irc) "" ""))))
		(emacsconf-erc-with-channels (list emacsconf-erc-hallway emacsconf-erc-org)
			(erc-send-message (format "-- Q&A finished for \"%s\" in the %s track. Add notes/questions: %s %s"
																(plist-get talk :title)
																(plist-get talk :track)
																(plist-get talk :pad-url)
																(emacsconf-surround " Speaker IRC nick: " (plist-get talk :irc) "" ""))))))

;;; For todo hooks

(defun emacsconf-erc-announce-on-change (talk)
  "Announce talk."
  (let ((func
         (pcase org-state
           ("PLAYING" #'erc-cmd-NOWPLAYING)
           ("CLOSED_Q" #'erc-cmd-NOWCLOSEDQ)
           ("OPEN_Q" #'erc-cmd-NOWOPENQ)
           ("UNSTREAMED_Q" #'erc-cmd-NOWUNSTREAMEDQ)
           ("TO_ARCHIVE" #'erc-cmd-NOWDONE))))
    (when func
      (funcall func talk))))

;;; Change TODO states
(defun erc-cmd-MARKPLAYING (talk)
  "Mark TALK as starting streaming."
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (emacsconf-find-talk-info talk)))
  (save-window-excursion
    (emacsconf-with-talk-heading talk (org-todo "PLAYING"))))

(defun erc-cmd-MARKCLOSEDQ (talk)
  "Mark TALK as starting closed Q&A."
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (emacsconf-find-talk-info talk)))
  (save-window-excursion
    (emacsconf-with-talk-heading talk (org-todo "CLOSED_Q"))))

(defun erc-cmd-MARKOPENQ (talk)
  "Mark TALK as starting open Q&A."
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (emacsconf-find-talk-info talk)))
  (save-window-excursion
    (emacsconf-with-talk-heading talk (org-todo "OPEN_Q"))))

(defun erc-cmd-MARKDONE (talk)
  "Mark TALK as done with the streaming and Q&A"
  (interactive (list (emacsconf-complete-talk-info)))
  (when (stringp talk) (setq talk (emacsconf-find-talk-info talk)))
  (save-window-excursion
    (emacsconf-with-talk-heading talk (org-todo "TO_ARCHIVE"))))

;;; Other commands

(defun erc-cmd-OPME ()
  "Request chanserv to op me."
  (erc-message "PRIVMSG"
							 (format "chanserv op %s %s"
											 (erc-default-target)
											 (erc-current-nick)) nil))

(defun erc-cmd-DEOPME ()
  "Deop myself from current channel."
  (erc-cmd-DEOP (format "%s" (erc-current-nick))))

(defun erc-cmd-OPALL (&optional nick)
  (emacsconf-erc-with-channels (mapcar 'car emacsconf-topic-templates)
    (if nick
				(erc-cmd-OP nick)
      (erc-cmd-OPME))))

(defun erc-cmd-DEOPALL (&optional nick)
  (emacsconf-erc-with-channels (mapcar 'car emacsconf-topic-templates)
    (if nick
	      (erc-cmd-DEOP nick)
      (erc-cmd-DEOPME))))

(defun erc-cmd-BROADCAST (&rest message)
  "Say MESSAGE in all the emacsconference channels."
  (emacsconf-erc-with-channels (mapcar 'car emacsconf-topic-templates)
    (erc-send-message (string-join message " "))))

(defun erc-cmd-JUMP (talk)
  (emacsconf-go-to-talk talk))

(defun erc-cmd-SETPROP (property talk value)
  (save-window-excursion
    (emacsconf-with-talk-heading talk
      (org-entry-put (point) (upcase property) value))))

(defun erc-cmd-GETPROP (property talk)
  (save-window-excursion
    (emacsconf-with-talk-heading talk
      (message "%s" (org-entry-get (point) (upcase property))))))

(defun emacsconf-set-start-time-for-slug (slug time)
  (interactive (list (emacsconf-complete-talk) (read-string "Start: ")))
  (emacsconf-with-talk-heading slug
    (emacsconf-org-set-start-time (emacsconf-time-or-offset-to-time time))))

(defun emacsconf-org-set-qa-end (slug time)
  (interactive (list (emacsconf-complete-talk) (read-string "Q&A end: ")))
  (emacsconf-with-talk-heading slug
    (org-entry-put (point) "Q_AND_A_END"
                   (org-format-time-string (cdr org-time-stamp-formats) (emacsconf-time-or-offset-to-time time)))
    (let ((info (list :title (org-entry-get (point) "ITEM"))))
      (when emacsconf-tasks-file
        (with-current-buffer (find-file-noselect emacsconf-tasks-file)
          (goto-char (point-max))
          (insert (emacsconf-replace-plist-in-string info "\n* TODO [#C] Process Q&A for ${title}

")))))))

(defun emacsconf-end-current-talk (time)
  (interactive (read-string "Time: "))
  (with-current-buffer (find-file-noselect emacsconf-org-file)
    (org-map-entries
     (lambda ()
       (org-todo "DONE")
       (when (and (string-match "live" (org-entry-get (point) "Q_AND_A"))
                  (null (org-entry-get (point) "Q_AND_A_END")))
         (save-excursion
           (emacsconf-org-set-qa-end
            (org-entry-get (point) "SLUG")
            time)))
       (emacsconf-update-talk))
     "SLUG=.+TODO=\"STARTED\"")))

(defun emacsconf-announce (slug time)
  "Announce that the talk SLUG has started. Optionally, set the start time to TIME."
  (interactive (list (emacsconf-complete-talk) (read-string "Start: ")))
  ;; mark the previous talk done
  (emacsconf-end-current-talk time)
  ;; mark the current talk started
  (emacsconf-with-talk-heading slug
    (erc-cmd-ANNOUNCE (org-entry-get (point) "SLUG"))
    (emacsconf-org-set-start-time (emacsconf-time-or-offset-to-time time))))

(defun emacsconf-org-set-start-time (time)
  "Set the start time of the current entry to TIME.
TIME can be hh:mm or an offset such as -2 (two minutes ago) based on current time."
  (interactive "MStart: ")
  (let ((sched (org-timestamp-from-string (org-entry-get (point) "SCHEDULED")))
        info)
    (org-todo "STARTED")
    (org-set-property "SCHEDULED"
                      (org-format-time-string "%Y-%m-%d %H:%M" (emacsconf-time-or-offset-to-time time)))
    (org-entry-put (point) "FIXED_TIME" "1")
    (org-entry-put (point) "PUBLIC" "1")
    (setq info (emacsconf-get-talk-info-for-subtree))
    (setq info (append info
                       (list :video-description (emacsconf-video-description info)
                             :conf-year emacsconf-year
                             :conf-directory emacsconf-directory)))
    (emacsconf-update-talk)
    (when emacsconf-tasks-file
      (with-current-buffer (find-file-noselect emacsconf-tasks-file)
        (goto-char (point-max))
        (unless (re-search-backward "TODO.*Update schedule on wiki" nil t)
          (insert "\n* TODO [#B] Update schedule on wiki\n"))
        (goto-char (point-max))
        (insert (emacsconf-replace-plist-in-string info 
                                                   "\n* TODO [#B] Check ${title} on https://media.emacsconf.org/${conf-year}

,* TODO [#B] Commit the page update for ${title} and check https://emacsconf.org/${conf-year}/talks/${slug}/

[[elisp:(magit-status-setup-buffer \"${conf-directory}\"]]

,* TODO [#C] Publish ${title} on YouTube and ToobNix

${video-description}

"))))
    (emacsconf-publish-files)
    (emacsconf-update-media)))


(defun erc-cmd-START (talk &optional time)
  "Adjusts the start time and sets the FIXED_TIME property.
/FIXSTART news 9:03  - set it to start at that time
/FIXSTART news -2    - two minutes ago"
  (save-window-excursion
    (emacsconf-with-talk-heading talk
      (emacsconf-org-set-start-time time))))

(defun emacsconf-org-log-note (note)
  "Add NOTE to the current entry's logbook."
  (interactive "MNote: ")
  (setq org-log-note-window-configuration (current-window-configuration))
  (move-marker org-log-note-return-to (point))
  (move-marker org-log-note-marker (point))
  (setq org-log-note-purpose 'note)
  (with-temp-buffer
    (insert note)
    (org-store-log-note)))

(defun erc-cmd-CONFLOG (talk &rest notes)
  "Go to TALK and store NOTES in the :LOGBOOK:.
Usage: /conflog keyword notes go here"
  (save-window-excursion
    (emacsconf-with-talk-heading talk (emacsconf-org-log-note (string-join notes " ")))))

(defun erc-cmd-GIT (&optional location)
  (if (string= location "conf")
      (magit-status (file-name-directory emacsconf-org-file))
    (magit-status emacsconf-directory)))

(defun erc-cmd-CONF (&rest args)
  (cond
   ((string= (car args) "checkin")
    (apply 'erc-cmd-CHECKIN (cdr args)))
   ((string= (car args) "start")
    (apply 'erc-cmd-START (cdr args)))
   ((string= (car args) "git")
    (apply 'erc-cmd-GIT (cdr args)))
   ((string= (car args) "log")
    (apply 'erc-cmd-CONFLOG (cdr args)))
   (t (message "checkin start git log"))))

;;; Hooks for noticing

;; (with-eval-after-load 'erc (add-hook 'erc-insert-pre-hook 'emacsconf-erc-notice-announcements))

(defvar emacsconf-erc-announcement-nicks '("sachac" "emacsconf"))
(defvar emacsconf-erc-recent-announcements nil "List of time and recent announcements.")
(defvar emacsconf-erc-recent-announcements-length 100 "How many entries to keep.")
(defun emacsconf-erc-notice-announcements (string)
	"Try to avoid spamming the announcement channels."
	(when (string-match (concat "\\`<@?" (regexp-opt emacsconf-erc-announcement-nicks) "> \\(--.*\\)") string)
		(setq emacsconf-erc-recent-announcements
					(cons (cons (match-string-no-properties 1 string) (current-time))
								(seq-take emacsconf-erc-recent-announcements (1- emacsconf-erc-recent-announcements-length))))))

(provide 'emacsconf-erc)
;;; emacsconf-erc.el ends here