-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
56 lines (45 loc) · 1.28 KB
/
bot.ts
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
console.log("Every Frame a Spider Starting!");
import { getFrame } from "./ffmpeg";
import { getArr, getBorderIndex, removeFrame } from "./fs";
import { FrameInfo } from "./types";
import { twitterUpload, tumblrUpload } from "./uploads";
// DONE: Frame Picker
/*
1. gets random num for num of frames remaining
2. return number to reference for the tweet
*/
const pickFrameIndex = (arr: number[]): number => {
const max = getBorderIndex(arr);
const min = 0;
let rand = Math.floor(Math.random() * (max - min + 1)) + min;
return rand;
};
// // DONE: generalize inside of postFrame function
// // TODO: frame alt text maybe?
const postFrame = async () => {
const arr = getArr();
const frameIndex = await pickFrameIndex(arr);
// TODO: ADD checking for failure here
const frameNum = removeFrame(frameIndex, arr);
// accounts for the +1 offset between my frames and stephen's
let rawFrameNum = frameNum - 1;
const framePath = await getFrame(rawFrameNum);
const frame: FrameInfo = {
num: frameNum,
index: frameIndex,
path: framePath,
};
try {
await twitterUpload(frame);
} catch (e) {
console.log(e);
}
try {
await tumblrUpload(frame);
} catch (e) {
console.log(e);
}
};
//DONE: Execute
// postFrame(pickFrame, freeFrame);
postFrame();