diff options
author | Volpeon <git@volpeon.ink> | 2021-10-17 16:54:53 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-17 16:54:53 +0200 |
commit | 30b0adcacef48ac53aea13cbdc3288db0bd8d103 (patch) | |
tree | 402f4cc31a2fa4f0e746c81755b537b5f5137e4c /src/index.ts | |
download | feralbot-30b0adcacef48ac53aea13cbdc3288db0bd8d103.tar.gz feralbot-30b0adcacef48ac53aea13cbdc3288db0bd8d103.tar.bz2 feralbot-30b0adcacef48ac53aea13cbdc3288db0bd8d103.zip |
Init
Diffstat (limited to 'src/index.ts')
-rw-r--r-- | src/index.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7185e23 --- /dev/null +++ b/src/index.ts | |||
@@ -0,0 +1,36 @@ | |||
1 | import * as e621 from "./api/e621"; | ||
2 | import * as mastodon from "./api/mastodon"; | ||
3 | import config from "./config"; | ||
4 | |||
5 | (async () => { | ||
6 | console.log("Fetching post..."); | ||
7 | |||
8 | const post = await e621.randomPost(); | ||
9 | const source = post.sources.length ? post.sources[0] : undefined; | ||
10 | const cws = config.cw.filter((w) => post.tags.general.includes(w)); | ||
11 | |||
12 | console.log(`Got ${post.id}`); | ||
13 | console.log(`Downloading image...`); | ||
14 | |||
15 | const file = await e621.client.get(post.file.url).buffer(); | ||
16 | |||
17 | /*console.log(`Compressing...`); | ||
18 | |||
19 | const compressedFile = await sharp(file) | ||
20 | .resize(1000, 1000, { | ||
21 | fit: "inside", | ||
22 | withoutEnlargement: true, | ||
23 | }) | ||
24 | .jpeg({ quality: 85, mozjpeg: true }) | ||
25 | .toBuffer();*/ | ||
26 | |||
27 | console.log(`Uploading...`); | ||
28 | |||
29 | const attachment = await mastodon.upload(file, post.id.toString(10)); | ||
30 | |||
31 | console.log(`Posting status...`); | ||
32 | |||
33 | const status = await mastodon.createStatus(`https://e926.net/posts/${post.id}`, source, cws, attachment.id); | ||
34 | |||
35 | console.log(`Done! ${status.url}`); | ||
36 | })(); | ||