diff options
author | Volpeon <git@volpeon.ink> | 2021-10-18 13:50:57 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-18 13:50:57 +0200 |
commit | 8a6ad69c1e859db373a67c75f893853986750603 (patch) | |
tree | 92ddcffc840dc444c1a28a883a62fc8eea01958c /src/api | |
parent | Add presenting to excluded tags (diff) | |
download | feralbot-8a6ad69c1e859db373a67c75f893853986750603.tar.gz feralbot-8a6ad69c1e859db373a67c75f893853986750603.tar.bz2 feralbot-8a6ad69c1e859db373a67c75f893853986750603.zip |
Support posting a specific picture
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/e621/index.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/api/e621/index.ts b/src/api/e621/index.ts index c8e0f44..411edae 100644 --- a/src/api/e621/index.ts +++ b/src/api/e621/index.ts | |||
@@ -26,7 +26,23 @@ export const client = got.extend({ | |||
26 | }, | 26 | }, |
27 | }); | 27 | }); |
28 | 28 | ||
29 | export async function randomPost() { | 29 | export async function getPost(id: number) { |
30 | const response = await client | ||
31 | .get("https://e926.net/posts.json", { | ||
32 | searchParams: { | ||
33 | tags: `id:${id}`, | ||
34 | }, | ||
35 | }) | ||
36 | .json<{ posts: readonly Post[] }>(); | ||
37 | |||
38 | if (!response.posts.length) { | ||
39 | throw new Error("No posts received"); | ||
40 | } | ||
41 | |||
42 | return response.posts[0]; | ||
43 | } | ||
44 | |||
45 | export async function getRandomPost() { | ||
30 | const queryIndex = Math.floor(Math.random() * config.e621.queries.length); | 46 | const queryIndex = Math.floor(Math.random() * config.e621.queries.length); |
31 | const query = config.e621.queries[queryIndex]; | 47 | const query = config.e621.queries[queryIndex]; |
32 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; | 48 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; |