Refactor bot. (#8)
This commit is contained in:
parent
e0374bea36
commit
259d540e6f
18 changed files with 491 additions and 300 deletions
11
src/version.ts
Normal file
11
src/version.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
let cachedVer: string;
|
||||
let cachedTimestamp: number;
|
||||
|
||||
export async function getLatest(): Promise<string> {
|
||||
if (cachedVer && Date.now() - cachedTimestamp < 600000) return cachedVer; // 10min
|
||||
const f = await fetch('https://api.github.com/repos/PolyMC/PolyMC/releases');
|
||||
const versions = await f.json();
|
||||
cachedVer = versions[0].tag_name;
|
||||
cachedTimestamp = Date.now();
|
||||
return versions[0].tag_name;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue