Skip to content

Commit

Permalink
typescript rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
lavgup committed Oct 20, 2020
1 parent 8f9c660 commit 104f643
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
node_modules/
.idea/
# deps
node_modules

# ide settings
.idea

# compiled
dist

# dep tree
pnpm-lock.yaml
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "vacefron",
"version": "1.1.0",
"description": "A wrapper for the VACEfron API in JavaScript.",
"main": "src/index.js",
"version": "2.0.0",
"description": "A wrapper for the VACEfron API in TypeScript.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"api",
"wrapper",
"api-wrapper",
"vacefron"
"vacefron",
"typescript"
],
"homepage": "https://github.com/Sidemen19/VACEfron.js",
"repository": {
Expand All @@ -23,6 +25,8 @@
"author": "Sidemen19",
"license": "MIT",
"dependencies": {
"@types/node": "^14.11.10",
"@types/node-fetch": "^2.5.7",
"node-fetch": "^2.6.1"
}
}
143 changes: 143 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import fetch from 'node-fetch';

class VACEFronJS {
baseURL: string;
crewmateColors: string[];

public constructor() {
this.baseURL = `https://vacefron.nl/api`;

this.crewmateColors = [
'black',
'blue',
'brown',
'cyan',
'darkgreen',
'lime',
'orange',
'pink',
'purple',
'red',
'white',
'yellow'
];
}

protected async api(endpoint: string, parameters: object): Promise<Buffer> {
for (const [key, value] of Object.entries(parameters)) {
if (value === undefined) {
throw new Error(`Param "${key}" of VACEfron endpoint "${endpoint}" is undefined.`);
}
}

// @ts-ignore
const params = new URLSearchParams(parameters);
const response = await fetch(`${this.baseURL}/${endpoint}?${params}`);

if (response.status !== 200) {
const body = await response.json();
throw new Error(`"${endpoint}" endpoint: ${body.message} (status ${body.code})`);
}

return response.buffer();
}

public carReverse(text: string): Promise<Buffer> {
return this.api('carreverse', { text: text });
}

distractedBoyfriend(boyfriendAvatarURL: string, womanAvatarURL: string, girlfriendAvatarURL: string): Promise<Buffer> {
return this.api('distractedbf', {
boyfriend: boyfriendAvatarURL,
woman: womanAvatarURL,
girlfriend: girlfriendAvatarURL
});
}

ejected(name: string, wasImposter?: boolean, color?: string): Promise<Buffer> {
if (!wasImposter) {
wasImposter = Math.random() >= 0.5;
}

if (!color || !this.crewmateColors.includes(color.toLowerCase())) {
color = this.crewmateColors[Math.floor(Math.random() * this.crewmateColors.length)];
}

return this.api('ejected', {
name: name,
imposter: wasImposter,
crewmate: color.toLowerCase()
});
}

emergencyMeeting(text: string): Promise<Buffer> {
return this.api('emergencymeeting', { text: text });
}

firstTime(avatarURL: string): Promise<Buffer> {
return this.api('firsttime', { user: avatarURL });
}

grave(avatarURL: string): Promise<Buffer> {
return this.api('grave', { user: avatarURL });
}

iAmSpeed(avatarURL: string): Promise<Buffer> {
return this.api('icanmilkyou', { user: avatarURL });
}

iCanMilkYou(faceAvatarURL: string, cowAvatarURL: string): Promise<Buffer> {
return this.api('iamspeed', {
user1: faceAvatarURL,
user2: cowAvatarURL
});
}

heaven(avatarURL: string): Promise<Buffer> {
return this.api('heaven', { user: avatarURL });
}

rankCard(
username: string,
avatarURL: string,
customBackgroundURL: string,
level: number,
rank: number,
currentXP: number,
nextLevelXP: number,
previousLevelXP: number,
xpColor: string,
isBoosting: boolean
): Promise<Buffer> {
return this.api('rankcard', {
username: encodeURIComponent(username),
avatar: avatarURL,
custombg: customBackgroundURL,
level: level,
rank: rank,
currentxp: currentXP,
nextlevelxp: nextLevelXP,
previouslevelxp: previousLevelXP,
xpcolor: xpColor.replace('#', ''),
isboosting: isBoosting
});
}

stonks(avatarURL: string): Promise<Buffer> {
return this.api('stonks', { user: avatarURL });
}

tableFlip(avatarURL: string): Promise<Buffer> {
return this.api('tableflip', { user: avatarURL });
}

water(text: string): Promise<Buffer> {
return this.api('water', { text: text });
}

wide(imageURL: string): Promise<Buffer> {
return this.api('wide', { image: imageURL });
}
}

export = new VACEFronJS();
28 changes: 28 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"strict": true,
"moduleResolution": "node",
"target": "esnext",
"lib": [
"esnext",
"dom"
],
"declaration": true,
"removeComments": false,
"alwaysStrict": true,
"pretty": true,
"noEmitHelpers": true,
"importHelpers": true,
"skipLibCheck": true,
"esModuleInterop": true,
"module": "commonjs",
"outDir": "dist",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true
},
"include": ["src"],
"exclude": ["node_modules"]
}

0 comments on commit 104f643

Please sign in to comment.