added scanning functionality
This commit is contained in:
64
src/class.ts
Normal file
64
src/class.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import fetch from "cross-fetch";
|
||||
import { CheckResult } from "./types";
|
||||
|
||||
const TASEApi = `https://tase-staging.thegoober.xyz`
|
||||
|
||||
export class TASEClient {
|
||||
private token: string;
|
||||
|
||||
constructor(APIToken: string){
|
||||
this.token = APIToken
|
||||
}
|
||||
|
||||
async checkUser(UserID: string): Promise<CheckResult> {
|
||||
if(UserID.length < 16 || UserID.length > 20) throw new Error("A UserID must be between 16-20 characters.")
|
||||
|
||||
const Response = await fetch(TASEApi + `/api/v1/check/${UserID}`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${this.token}`
|
||||
},
|
||||
method: "GET"
|
||||
})
|
||||
|
||||
if(!Response.ok){
|
||||
switch(Response.status){
|
||||
case 401:
|
||||
throw new Error("Invalid API Key.")
|
||||
case 403:
|
||||
throw new Error("Your API key has been blacklisted.")
|
||||
default:
|
||||
throw new Error(`Unknown API error (code ${Response.status}: ${Response.statusText})`)
|
||||
}
|
||||
}
|
||||
|
||||
return Response.json()
|
||||
}
|
||||
|
||||
async checkUsers(UserIDs: string[]): Promise<Array<CheckResult>> {
|
||||
if(UserIDs.find((Value) => Value.length < 16 || Value.length > 20)) throw new Error("All UserIDs must be between 16-20 characters.")
|
||||
if(UserIDs.length > 10000) throw new Error("The amount of UserIDs must be less than 10,000.")
|
||||
if(UserIDs.length < 1) throw new Error("The amount of UserIDs must be atleast 1 character.")
|
||||
|
||||
const Response = await fetch(TASEApi + `/api/v1/mass-check`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${this.token}`,
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(UserIDs),
|
||||
method: "POST"
|
||||
})
|
||||
|
||||
if(!Response.ok){
|
||||
switch(Response.status){
|
||||
case 401:
|
||||
throw new Error("Invalid API Key.")
|
||||
case 403:
|
||||
throw new Error("Your API key has been blacklisted.")
|
||||
default:
|
||||
throw new Error(`Unknown API error (code ${Response.status}: ${Response.statusText})`)
|
||||
}
|
||||
}
|
||||
|
||||
return Response.json()
|
||||
}
|
||||
}
|
2
src/index.ts
Normal file
2
src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./class"
|
||||
export * from "./types"
|
61
src/types.ts
Normal file
61
src/types.ts
Normal file
@ -0,0 +1,61 @@
|
||||
export interface CheckGuild {
|
||||
/**
|
||||
* What is the Guild ID of the server?
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* What is this server's name?
|
||||
*/
|
||||
name: string,
|
||||
/**
|
||||
* What type of server is this?
|
||||
*/
|
||||
type: string,
|
||||
/**
|
||||
* What versions was this user detected with?
|
||||
*/
|
||||
detectedWith: Array<number>
|
||||
/**
|
||||
* When was the user last seen inside the condo server?
|
||||
*/
|
||||
lastSeen: Date | undefined,
|
||||
/**
|
||||
* When was the user first seen inside the condo server?
|
||||
*/
|
||||
firstSeen: Date | undefined,
|
||||
/**
|
||||
* Has the user boosted this server before?
|
||||
*/
|
||||
isBooster: boolean,
|
||||
/**
|
||||
* Does the user have certain roles?
|
||||
*/
|
||||
isStaff: boolean
|
||||
/**
|
||||
* A number calculated on how much a user has interacted with this guild.
|
||||
*/
|
||||
score: number
|
||||
}
|
||||
|
||||
export interface CheckResult {
|
||||
/**
|
||||
* What is the ID of the user?
|
||||
*/
|
||||
userId: string,
|
||||
/**
|
||||
* When did this user appeal? (if they have appealed.)
|
||||
*/
|
||||
appealDate?: Date
|
||||
/**
|
||||
* The summed up score of all the `guilds`.
|
||||
*/
|
||||
scoreSum: number,
|
||||
/**
|
||||
* When was the user last seen?
|
||||
*/
|
||||
lastSeen: Date | undefined,
|
||||
/**
|
||||
* An array of guilds the user has been detected in, with certain properties.
|
||||
*/
|
||||
guilds: Array<CheckGuild>
|
||||
}
|
Reference in New Issue
Block a user