-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathmain.js
32 lines (27 loc) · 899 Bytes
/
main.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
const { Text, Color } = require("scenegraph");
const { alert, error } = require("./lib/dialogs.js");
async function randomQuote() {
const response = await fetch("https://api.quotable.io/random");
const data = await response.json();
return data;
}
async function quoteHandlerFunction(selection) {
try {
const quote = await randomQuote();
const node = new Text();
node.text = `${quote.content} - ${quote.author}`;
node.fill = new Color().clone();
node.fontSize = 18;
node.areaBox = { width: 800, height: 200 };
selection.insertionParent.addChild(node);
node.moveInParentCoordinates(20, 20);
} catch (ex) {
console.log("Detailed error: ", ex);
await error("Oops", "Please check your network connection.");
}
}
module.exports = {
commands: {
getQuote: quoteHandlerFunction
}
};