-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbot.js
44 lines (32 loc) · 1.15 KB
/
bot.js
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
/*
Used for communications with Twitter bot server code.
See https://github.com/devicefuture/atto-twitter for more details.
*/
import * as canvas from "./canvas.js";
import * as hid from "./hid.js";
export const EXECUTION_WAIT_TIME = 10 * 1000; // 10 seconds
export function invoke(id) {
hid.clearLog();
setTimeout(function() {
finish(id);
}, EXECUTION_WAIT_TIME);
}
export function finish(id) {
var dataUrl = canvas.getElement().toDataURL();
var imageBase64 = dataUrl.split(",")[1];
var hidLogEntries = [];
[...hid.hidLog.children].forEach(function(element) {
hidLogEntries.push(element.textContent);
});
var request = new XMLHttpRequest();
console.log("Sending request back...");
request.open("POST", `http://localhost:3000/fulfil/${id}`);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.addEventListener("load", function() {
window.location.href = "about:blank";
});
request.send(JSON.stringify({
content: imageBase64,
altText: hidLogEntries.slice(Math.max(hidLogEntries.length - canvas.TERM_ROWS, 0)).join("\n")
}));
}