/
index.js
68 lines (58 loc) · 2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require("fs");
const { createCanvas, loadImage } = require("canvas");
const Instagram = require("instagram-web-api");
const FileCookieStore = require("tough-cookie-filestore2");
const cron = require("node-cron");
const { username, password } = require("./config.js");
const cookieStore = new FileCookieStore("./cookies.json");
const client = new Instagram({
username,
password,
cookieStore,
});
const postShop = async () => {
try {
const { user, authenticated, status } = await client.login();
// if (!user) {
// throw new Error(`User: ${username} not found`);
// }
if (!authenticated) {
throw new Error(
`Unable to authenticate user: ${username}, make sure you have 2FA disabled.`
);
}
let profile = await client.getProfile();
console.log(`Logged in as ${profile.username}`);
const canvas = createCanvas(1000, 1000);
const ctx = canvas.getContext("2d");
const image = await loadImage("https://fishstickbot.com/api/shop.png");
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
await fs.promises.writeFile("shop.jpeg", canvas.toBuffer("image/jpeg"));
const { media } = await client.uploadPhoto({
photo: "shop.jpeg",
caption: `Latest Fortnite Item Shop ${new Date().toDateString()}\n\n#Fortnite #ItemShop #FortniteItemShop #BattleRoyale #FortniteShop #FortniteSkins #FreeSkins #EpicPartner`,
post: "feed",
});
console.log(
`Posted item shop: https://www.instagram.com/p/${media.code}`
);
} catch (e) {
console.error(e);
}
};
(async () => {
console.log(`Setting up auto post job...`);
cron.schedule(
"1 0 * * *",
async () => {
console.log(`Posting item shop...`);
await postShop();
console.log(`Done!`);
},
{
scheduled: true,
timezone: "Etc/UTC",
}
);
console.log(`Will post item shop every day at 0:00 UTC`);
})();