This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.43 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
const { Plugin } = require('powercord/entities');
module.exports = class Bread extends Plugin {
startPlugin() {
powercord.api.commands.registerCommand({
command: 'bread',
description: 'Get bread image',
usage: '{c} [--send]',
executor: async (args) => {
const send = args.includes('--send');
const response = await fetch('https://source.unsplash.com/random/?bread');
const bread = await this.loadImage(response.url);
let result = '';
if (!response.ok || !bread) {
result = 'Unable to get bread, try again later.'
} else {
result = send ? bread.src : {
image: {
url: bread.src,
width: bread.width,
height: bread.height,
},
footer: { // Doesn't display in embed without title.
text: 'Image from Unsplash'
}
}
}
return {
send,
result
}
}
});
}
pluginWillUnload() {
powercord.api.commands.unregisterCommand('bread');
}
loadImage(src) {
return new Promise(async (resolve, reject) => {
const img = new Image();
img.onload = () => {
resolve(img);
}
img.onerror = reject;
img.crossOrigin = 'Anonymous'
img.src = src;
});
}
}