-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoshop.js
executable file
·60 lines (47 loc) · 1.33 KB
/
Autoshop.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
//! require ( const const const const const )
require("dotenv/config");
const avaliableItems = 16;
const { createClient } = require("@supabase/supabase-js");
const RawItems = [];
const SellableItems = [];
const Supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY, {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true
});
async function updateShop() {
const { data } = await Supabase.from("config").select("*").eq("id", "all");
const ShopItems = await data[0].MarketItems;
const newItems = [];
for (var index in ShopItems) {
const Item = ShopItems[index];
Item.onsale = false;
if (Item.autoSale && Item.autoSale === true) RawItems.push(index);
}
function getItem() {
const RNG = RawItems[Math.floor(Math.random() * RawItems.length)];
SellableItems.splice(0, 0, RNG);
SellableItems.push(RNG);
return RNG;
}
for (var i = 0; i <= avaliableItems; i++) {
let Item = getItem();
if (newItems.includes(Item)) {
i--;
} else {
newItems.push(Item);
}
}
(async () => {
const { error } = await Supabase.from("config").update({
"market": {
"updates": Math.ceil((Date.now() + 86400000) / 1000),
"items": newItems
}
}).eq("id", "all");
if (error) console.log(error);
console.log("Market Refreshed");
})();
}
updateShop();
setInterval(updateShop, 86400000);