Skip to content

Commit

Permalink
🎨 style: format files with new biome config
Browse files Browse the repository at this point in the history
  • Loading branch information
Fifixex committed Aug 10, 2024
1 parent 99b6c62 commit 6bc5a22
Show file tree
Hide file tree
Showing 11 changed files with 2,257 additions and 214 deletions.
5 changes: 5 additions & 0 deletions examples/basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Bot} from '@uniteds/curzy'

const app = new Bot({name: 'My Bot'})
const bot = await app.create()
console.log(bot.token)
2,071 changes: 2,055 additions & 16 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions src/Application.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { getTrackBase64, post } from './utils'

export default abstract class Application {
#token: string = process.env.SYSTEM_TOKEN as string
protected password: string = process.env.SYSTEM_PASSWORD as string
protected headers: Record<string, string> = {
'Content-Type': 'application/json',
Authorization: this.#token,
'X-Track': getTrackBase64()
}

public async getTicket(id: string) {
const reset = await post(`/applications/${id}/bot/reset`, {
headers: this.headers
})
return reset.mfa.ticket as string
}

public async getCookie(ticket: string) {
const cookie = await post('/mfa/finish', {
headers: this.headers,
body: JSON.stringify({
data: this.password,
mfa_type: 'password',
ticket: ticket
})
})
return cookie.token as string
}

public abstract request<T>(options: T): Promise<unknown>
}
import {getTrackBase64, post} from './utils'

export default abstract class Application {
#token: string = process.env.SYSTEM_TOKEN as string
protected password: string = process.env.SYSTEM_PASSWORD as string
protected headers: Record<string, string> = {
'Content-Type': 'application/json',
Authorization: this.#token,
'X-Track': getTrackBase64(),
}

public async getTicket(id: string) {
const reset = await post(`/applications/${id}/bot/reset`, {
headers: this.headers,
})
return reset.mfa.ticket as string
}

public async getCookie(ticket: string) {
const cookie = await post('/mfa/finish', {
headers: this.headers,
body: JSON.stringify({
data: this.password,
mfa_type: 'password',
ticket: ticket,
}),
})
return cookie.token as string
}

public abstract request<T>(options: T): Promise<unknown>
}
85 changes: 42 additions & 43 deletions src/Bot.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { Create, Delete } from './actions/index'

interface Options {
name: string
description?: string
tags?: string[]
owners?: string[]
avatar?: Buffer
}

export class Bot {
private name!: string
private description?: string
private tags?: string[]
private owners?: string[]
private avatar?: Buffer

constructor(options: Options) {
this.validate(options)

this.name = options.name
this.description = options.description
this.tags = options.tags
this.owners = options.owners
this.avatar = options.avatar
}

private validate(options: Options) {
if (typeof options !== 'object')
throw TypeError('Options should be a type of Object.')
if (!options.name)
throw Error('You must provide the name of the application.')
if (Reflect.has(options, 'tags') && !Array.isArray(options.tags))
throw TypeError('Tag(s) should be a type of Array<String>')
if (Reflect.has(options, 'owners') && !Array.isArray(options.owners))
throw TypeError('Owner(s) should be a type of Array<String>')
if (Reflect.has(options, 'avatar') && !Buffer.isBuffer(options.avatar))
throw TypeError('Avatar should be a type of Buffer.')
}

public create = async () => new Create().request<string>(this.name)
public delete = async (id: string) => new Delete().request<string>(id)
}
import {Create, Delete} from './actions/index'

interface Options {
name: string
description?: string
tags?: string[]
owners?: string[]
avatar?: Buffer
}

export class Bot {
private name!: string
private description?: string
private tags?: string[]
private owners?: string[]
private avatar?: Buffer

constructor(options: Options) {
this.validate(options)

this.name = options.name
this.description = options.description
this.tags = options.tags
this.owners = options.owners
this.avatar = options.avatar
}

private validate(options: Options) {
if (typeof options !== 'object')
throw TypeError('Options should be a type of Object.')
if (!options.name) throw Error('You must provide the name of the application.')
if (Reflect.has(options, 'tags') && !Array.isArray(options.tags))
throw TypeError('Tag(s) should be a type of Array<String>')
if (Reflect.has(options, 'owners') && !Array.isArray(options.owners))
throw TypeError('Owner(s) should be a type of Array<String>')
if (Reflect.has(options, 'avatar') && !Buffer.isBuffer(options.avatar))
throw TypeError('Avatar should be a type of Buffer.')
}

public create = async () => new Create().request<string>(this.name)
public delete = async (id: string) => new Delete().request<string>(id)
}
72 changes: 36 additions & 36 deletions src/actions/create.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import Application from '../Application'
import { post } from '../utils'

export class Create extends Application {
public async request<T>(name: T) {
const application = await this.createApplication(name as string)
const ticket = await this.getTicket(application.id)
const cookie = await this.getCookie(ticket)
const token = await this.getToken(application.id, cookie)

return {
...application,
token
}
}

private async createApplication(name: string) {
const app = await post('/applications', {
headers: this.headers,
body: JSON.stringify({
name
})
})
return app
}

private async getToken(id: string, cookie: string) {
const response = await post(`/applications/${id}/bot/reset`, {
headers: {
...this.headers,
'x-discord-mfa-authorization': cookie
}
})
return response.token as string
}
}
import Application from '../Application'
import {post} from '../utils'

export class Create extends Application {
public async request<T>(name: T) {
const application = await this.createApplication(name as string)
const ticket = await this.getTicket(application.id)
const cookie = await this.getCookie(ticket)
const token = await this.getToken(application.id, cookie)

return {
...application,
token,
}
}

private async createApplication(name: string) {
const app = await post('/applications', {
headers: this.headers,
body: JSON.stringify({
name,
}),
})
return app
}

private async getToken(id: string, cookie: string) {
const response = await post(`/applications/${id}/bot/reset`, {
headers: {
...this.headers,
'x-discord-mfa-authorization': cookie,
},
})
return response.token as string
}
}
32 changes: 16 additions & 16 deletions src/actions/delete.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Application from '../Application'
import { post } from '../utils'

export class Delete extends Application {
public async request<T>(id: T): Promise<boolean> {
const ticket = await this.getTicket(id as string)
const cookie = await this.getCookie(ticket)
await post(`/applications/${id}/delete`, {
headers: {
...this.headers,
'x-discord-mfa-authorization': cookie
}
})
return true
}
}
import Application from '../Application'
import {post} from '../utils'

export class Delete extends Application {
public async request<T>(id: T): Promise<boolean> {
const ticket = await this.getTicket(id as string)
const cookie = await this.getCookie(ticket)
await post(`/applications/${id}/delete`, {
headers: {
...this.headers,
'x-discord-mfa-authorization': cookie,
},
})
return true
}
}
4 changes: 2 additions & 2 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './create'
export * from './delete'
export * from './create'
export * from './delete'
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Bot } from './Bot'
export {Bot} from './Bot'
60 changes: 30 additions & 30 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export const getTrackBase64 = () => {
const options = {
os: 'Windows',
browser: 'Chrome',
device: '',
system_locale: 'es',
browser_user_agent:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0',
browser_version: '127.0.0.0',
os_version: '10',
referrer: '',
referring_domain: '',
referrer_current: '',
referring_domain_current: '',
release_channel: 'stable',
client_build_number: 42503,
client_event_source: null
}
const data = JSON.stringify(options)
const track = Buffer.from(data).toString('base64')
return track
}

export const post = async (path: string, options: RequestInit) => {
options.method = 'POST'
const url = new URL('https://discord.com/api/v9'.concat(path))
const response = await fetch(url, options)
const data = await response.json()
return data
}
export const getTrackBase64 = () => {
const options = {
os: 'Windows',
browser: 'Chrome',
device: '',
system_locale: 'es',
browser_user_agent:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0',
browser_version: '127.0.0.0',
os_version: '10',
referrer: '',
referring_domain: '',
referrer_current: '',
referring_domain_current: '',
release_channel: 'stable',
client_build_number: 42503,
client_event_source: null,
}
const data = JSON.stringify(options)
const track = Buffer.from(data).toString('base64')
return track
}

export const post = async (path: string, options: RequestInit) => {
options.method = 'POST'
const url = new URL('https://discord.com/api/v9'.concat(path))
const response = await fetch(url, options)
const data = await response.json()
return data
}
54 changes: 27 additions & 27 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
Loading

0 comments on commit 6bc5a22

Please sign in to comment.