mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: added CDN methods
This commit is contained in:
parent
b53a3f412e
commit
4a3574b946
@ -1,3 +1,6 @@
|
||||
import { ImageOptions } from '../types'
|
||||
import { makeImageURL } from './Tools'
|
||||
|
||||
export const Status = {
|
||||
online: {
|
||||
text: '온라인',
|
||||
@ -88,4 +91,17 @@ export const reportCats = [
|
||||
'기타',
|
||||
]
|
||||
|
||||
export const BASE_URLs = {
|
||||
cdn: 'https://cdn.discordapp.com'
|
||||
}
|
||||
export const DiscordEnpoints = {
|
||||
CDN: class CDN {
|
||||
static root = BASE_URLs.cdn
|
||||
static emoji (id: string, options:ImageOptions={}) { return makeImageURL(`${this.root}/emojis/${id}`, options) }
|
||||
static guild (id: string, hash: string, options:ImageOptions={}) { return makeImageURL(`${this.root}/icons/${id}/${hash}`, options) }
|
||||
static default (tag: string, options:ImageOptions={}) { return makeImageURL(`${this.root}/embed/avatars/${isNaN(Number(tag)) ? Number(tag) % 5 : 0}`, options) }
|
||||
static user (id: string, hash: string, options:ImageOptions={}) { return makeImageURL(`${this.root}/avatars/${id}/${hash}`, options) }
|
||||
}
|
||||
}
|
||||
|
||||
export const git = { 'github.com': { icon: 'github', text: 'Github' }, 'gitlab.com': { icon: 'gitlab', text: 'Gitlab' }}
|
||||
@ -1,7 +1,7 @@
|
||||
import { UserPemissionFlags } from '../types'
|
||||
import { perms } from './Constants'
|
||||
import { ImageFormat, ImageOptions, ImageSize, UserPemissionFlags } from '../types'
|
||||
import { BASE_URLs, perms } from './Constants'
|
||||
|
||||
function formatNumber(value: number):string {
|
||||
export function formatNumber(value: number):string {
|
||||
const suffixes = ['', '만', '억', '조','해']
|
||||
const suffixNum = Math.floor((''+value).length/4)
|
||||
let shortValue:string|number = parseFloat((suffixNum != 0 ? (value / Math.pow(10000,suffixNum)) : value).toPrecision(2))
|
||||
@ -12,10 +12,12 @@ function formatNumber(value: number):string {
|
||||
return shortValue+suffixes[suffixNum]
|
||||
}
|
||||
|
||||
function checkPerm(base: number, required: number | UserPemissionFlags):boolean {
|
||||
export function checkPerm(base: number, required: number | UserPemissionFlags):boolean {
|
||||
required = typeof required === 'number' ? required : perms[required]
|
||||
if (typeof required !== 'number' && !required) throw new Error('올바르지 않은 권한입니다.')
|
||||
return (base & required) === required
|
||||
}
|
||||
|
||||
export { formatNumber, checkPerm }
|
||||
export function makeImageURL(root:string, { format='png', size=256 }:ImageOptions):string {
|
||||
return `${root}.${format}?size=${size}`
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user