diff options
author | Volpeon <git@volpeon.ink> | 2021-10-19 19:25:03 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-19 19:25:03 +0200 |
commit | 163d8119c109c42e64ab37b01dec131f2cb5bf61 (patch) | |
tree | ee0abce3ce349482ca63b4064fcbebc0e5d2f4ff /src/index.ts | |
parent | Code improvements (diff) | |
download | feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.tar.gz feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.tar.bz2 feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.zip |
Code improvements, support a manual post queue
Diffstat (limited to 'src/index.ts')
-rw-r--r-- | src/index.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts index 5558540..86d55ed 100644 --- a/src/index.ts +++ b/src/index.ts | |||
@@ -1,13 +1,20 @@ | |||
1 | import config from "./config"; | 1 | import config from "./config"; |
2 | import * as jobs from "./services/jobs"; | 2 | import * as jobs from "./services/jobs"; |
3 | import * as cliArgs from "ts-command-line-args"; | 3 | import * as cliArgs from "ts-command-line-args"; |
4 | import PostDatabase from "./services/postDatabase"; | ||
5 | |||
6 | export const queueDb = new PostDatabase("queue.json", 50); | ||
4 | 7 | ||
5 | const args = cliArgs.parse<{ | 8 | const args = cliArgs.parse<{ |
6 | id?: number; | 9 | id?: number; |
10 | enqueue?: number; | ||
11 | dequeue?: number; | ||
7 | help?: boolean; | 12 | help?: boolean; |
8 | }>( | 13 | }>( |
9 | { | 14 | { |
10 | id: { type: Number, optional: true }, | 15 | id: { type: Number, optional: true }, |
16 | enqueue: { type: Number, optional: true }, | ||
17 | dequeue: { type: Number, optional: true }, | ||
11 | help: { type: Boolean, optional: true, alias: "h" }, | 18 | help: { type: Boolean, optional: true, alias: "h" }, |
12 | }, | 19 | }, |
13 | { | 20 | { |
@@ -23,7 +30,23 @@ const args = cliArgs.parse<{ | |||
23 | 30 | ||
24 | if (args.id) { | 31 | if (args.id) { |
25 | await jobs.postSpecificPicture(args.id); | 32 | await jobs.postSpecificPicture(args.id); |
33 | } else if (args.enqueue) { | ||
34 | console.log(`Enqueueing post ${args.enqueue}...`); | ||
35 | |||
36 | await queueDb.insertIfNotExists({ provider: "e926", id: args.enqueue }); | ||
37 | } else if (args.dequeue) { | ||
38 | console.log(`Dequeueing post ${args.dequeue}...`); | ||
39 | |||
40 | await queueDb.remove({ provider: "e926", id: args.dequeue }); | ||
26 | } else { | 41 | } else { |
27 | await jobs.postRandomPicture(); | 42 | console.log("Reading queue..."); |
43 | |||
44 | const queued = await queueDb.takeFirst(); | ||
45 | |||
46 | if (queued) { | ||
47 | await jobs.postSpecificPicture(queued.id); | ||
48 | } else { | ||
49 | await jobs.postRandomPicture(); | ||
50 | } | ||
28 | } | 51 | } |
29 | })(); | 52 | })(); |