-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 style: format files with new biome config
- Loading branch information
Showing
11 changed files
with
2,257 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { Bot } from './Bot' | ||
export {Bot} from './Bot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.