blob: c712821e1902537de5347922f20e22144509073b (
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
|
;;; emacsconf-spookfox.el --- Spookfox browser automation -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Sacha Chua
;; Author: Sacha Chua <sacha@sachachua.com>
;; Keywords: convenience
;; 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:
;;; Code:
(defun emacsconf-spookfox-create-bbb (group)
"Create a BBB room for this group of talks.
GROUP is (email . (talk talk talk)).
Needs a Spookfox connection."
(let* ((bbb-name
(format "%s (%s) - %s%s"
(mapconcat (lambda (o) (plist-get o :slug)) (cdr group) ", ")
(or (plist-get (cadr group) :speakers) "emacsconf")
emacsconf-id
emacsconf-year))
path
(retrieve-command
(format
"window.location.origin + [...document.querySelectorAll('h4.room-name-text')].find((o) => o.textContent.trim() == '%s').closest('tr').querySelector('.delete-room').getAttribute('data-path')"
bbb-name))
(create-command (format "document.querySelector('#create-room-block').click();
document.querySelector('#create-room-name').value = \"%s\";
document.querySelector('#room_mute_on_join').click();
document.querySelector('.create-room-button').click();"
bbb-name)))
(setq path (spookfox-js-injection-eval-in-active-tab retrieve-command t))
(unless path
(dolist (cmd (split-string create-command ";"))
(spookfox-js-injection-eval-in-active-tab cmd t)
(sleep-for 2))
(sleep-for 2)
(setq path (spookfox-js-injection-eval-in-active-tab retrieve-command t)))
(when path
(dolist (talk (cdr group))
(save-window-excursion
(emacsconf-with-talk-heading talk
(org-entry-put (point) "ROOM" path))))
(cons bbb-name path))))
(defun emacsconf-spookfox-create-bbb-for-live-talks ()
"Create BBB rooms for talks that don't have them yet."
(let* ((talks (seq-filter
(lambda (o)
(and (string-match "live" (or (plist-get o :q-and-a) ""))
(not (string= (plist-get o :status) "CANCELLED"))
(not (plist-get o :bbb-room))))
(emacsconf-publish-prepare-for-display (emacsconf-get-talk-info))))
(groups (and talks (emacsconf-mail-groups talks))))
(dolist (group groups)
(emacsconf-spookfox-create-bbb group))))
(defun emacsconf-spookfox-create-bbb-for-all-talks ()
"Create BBB rooms for talks that don't have them yet."
(interactive)
(let* ((talks (seq-remove
(lambda (o) (plist-get o :bbb-room))
(emacsconf-publish-prepare-for-display (emacsconf-get-talk-info))))
(groups (and talks (emacsconf-mail-groups talks))))
(dolist (group groups)
(emacsconf-spookfox-create-bbb group))))
(defun emacsconf-spookfox-update-bbb-settings (talk settings)
(spookfox-js-injection-eval-in-active-tab
(format
"current = document.querySelector('a[href=\"%s\"]'); current.querySelector('.fa-ellipsis-v').click(); console.debug(current.querySelector('h4').textContent)"
(replace-regexp-in-string
(regexp-quote "https://bbb.emacsverse.org")
""
(plist-get talk :bbb-room))) t)
(spookfox-js-injection-eval-in-active-tab "current.querySelector('.update-room').click()" t)
(let (will-change)
(dolist (o settings)
(setq will-change
(or
will-change
(eq
(spookfox-js-injection-eval-in-active-tab
(format
"document.querySelector('#%s').checked != %s"
(car o)
(cdr o))
t)
t))))
(dolist (o settings)
(spookfox-js-injection-eval-in-active-tab
(format "document.querySelector('#%s').checked = %s"
(car o)
(cdr o))
t))
(if will-change
(progn
(spookfox-js-injection-eval-in-active-tab
"document.querySelector('input.update-only').click()"
t)
(message "%s changed" (plist-get talk :slug))
(sleep-for 5))
(message "%s confirmed" (plist-get talk :slug))
(spookfox-js-injection-eval-in-active-tab
"document.querySelector('button.create-room-button[data-dismiss=\"modal\"]').click()"
t)
(sleep-for 1))))
(provide 'emacsconf-spookfox)
;;; emacsconf-spookfox.el ends here
|