format files and ready for v0.9.0
This commit is contained in:
parent
a80a68bf91
commit
5e5b4076ce
|
@ -20,7 +20,7 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
deno: ["v1.x", "nightly"]
|
||||
deno: ['v1.x', 'nightly']
|
||||
|
||||
steps:
|
||||
- name: Setup repo
|
||||
|
|
|
@ -5,23 +5,22 @@ name: Lint Test
|
|||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
|
||||
- name: Setup ESLint
|
||||
run: npm install
|
||||
- name: Setup ESLint
|
||||
run: npm install
|
||||
|
||||
- name: Test ESLint
|
||||
run: npx eslint src/
|
||||
- name: Test ESLint
|
||||
run: npx eslint src/
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"arrowParens": "always"
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ Here is a small example of how to use harmony,
|
|||
import {
|
||||
Client,
|
||||
Message,
|
||||
Intents,
|
||||
Intents
|
||||
} from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts'
|
||||
|
||||
const client = new Client()
|
||||
|
@ -78,11 +78,11 @@ import {
|
|||
Command,
|
||||
CommandContext,
|
||||
Message,
|
||||
Intents,
|
||||
Intents
|
||||
} from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts'
|
||||
|
||||
const client = new CommandClient({
|
||||
prefix: '!',
|
||||
prefix: '!'
|
||||
})
|
||||
|
||||
// Listen for event when client is ready (Identified through gateway / Resumed)
|
||||
|
|
|
@ -11,7 +11,7 @@ export const channelPinsUpdate: GatewayEventHandler = async (
|
|||
| undefined = await gateway.client.channels.get<TextChannel>(d.channel_id)
|
||||
if (after !== undefined) {
|
||||
const before = after.refreshFromData({
|
||||
last_pin_timestamp: d.last_pin_timestamp,
|
||||
last_pin_timestamp: d.last_pin_timestamp
|
||||
})
|
||||
const raw = await gateway.client.channels._get(d.channel_id)
|
||||
await gateway.client.channels.set(
|
||||
|
|
|
@ -20,7 +20,7 @@ export const guildMemberUpdate: GatewayEventHandler = async (
|
|||
nick: d.nick,
|
||||
premium_since: d.premium_since,
|
||||
deaf: member?.deaf ?? false,
|
||||
mute: member?.mute ?? false,
|
||||
mute: member?.mute ?? false
|
||||
}
|
||||
await guild.members.set(d.user.id, newMemberPayload)
|
||||
const newMember = await guild.members.get(d.user.id)
|
||||
|
|
|
@ -27,7 +27,7 @@ export const guildMembersChunk: GatewayEventHandler = async (
|
|||
presences:
|
||||
d.presences === undefined ? undefined : d.presences.map((p) => p.user.id),
|
||||
chunkIndex: d.chunk_index,
|
||||
chunkCount: d.chunk_count,
|
||||
chunkCount: d.chunk_count
|
||||
})
|
||||
|
||||
// Guild is now completely chunked. Emit an event for that.
|
||||
|
|
|
@ -27,8 +27,7 @@ import { webhooksUpdate } from './webhooksUpdate.ts'
|
|||
import { messageDeleteBulk } from './messageDeleteBulk.ts'
|
||||
import { userUpdate } from './userUpdate.ts'
|
||||
import { typingStart } from './typingStart.ts'
|
||||
import { Channel } from '../../structures/channel.ts'
|
||||
import { GuildTextChannel, TextChannel } from '../../structures/textChannel.ts'
|
||||
import { GuildTextChannel } from '../../structures/textChannel.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { User } from '../../structures/user.ts'
|
||||
import { Emoji } from '../../structures/emoji.ts'
|
||||
|
@ -50,6 +49,10 @@ import { inviteDelete } from './inviteDelete.ts'
|
|||
import { MessageReaction } from '../../structures/messageReaction.ts'
|
||||
import { Invite } from '../../structures/invite.ts'
|
||||
import { Presence } from '../../structures/presence.ts'
|
||||
import {
|
||||
EveryChannelTypes,
|
||||
EveryTextChannelTypes
|
||||
} from '../../utils/getChannelByType.ts'
|
||||
|
||||
export const gatewayHandlers: {
|
||||
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
||||
|
@ -90,7 +93,7 @@ export const gatewayHandlers: {
|
|||
USER_UPDATE: userUpdate,
|
||||
VOICE_STATE_UPDATE: voiceStateUpdate,
|
||||
VOICE_SERVER_UPDATE: voiceServerUpdate,
|
||||
WEBHOOKS_UPDATE: webhooksUpdate,
|
||||
WEBHOOKS_UPDATE: webhooksUpdate
|
||||
}
|
||||
|
||||
export interface EventTypes {
|
||||
|
@ -107,10 +110,13 @@ export interface ClientEvents extends EventTypes {
|
|||
ready: () => void
|
||||
reconnect: () => void
|
||||
resumed: () => void
|
||||
channelCreate: (channel: Channel) => void
|
||||
channelDelete: (channel: Channel) => void
|
||||
channelPinsUpdate: (before: TextChannel, after: TextChannel) => void
|
||||
channelUpdate: (before: Channel, after: Channel) => void
|
||||
channelCreate: (channel: EveryChannelTypes) => void
|
||||
channelDelete: (channel: EveryChannelTypes) => void
|
||||
channelPinsUpdate: (
|
||||
before: EveryTextChannelTypes,
|
||||
after: EveryTextChannelTypes
|
||||
) => void
|
||||
channelUpdate: (before: EveryChannelTypes, after: EveryChannelTypes) => void
|
||||
guildBanAdd: (guild: Guild, user: User) => void
|
||||
guildBanRemove: (guild: Guild, user: User) => void
|
||||
guildCreate: (guild: Guild) => void
|
||||
|
@ -140,7 +146,7 @@ export interface ClientEvents extends EventTypes {
|
|||
messageReactionRemoveEmoji: (message: Message, emoji: Emoji) => void
|
||||
typingStart: (
|
||||
user: User,
|
||||
channel: TextChannel,
|
||||
channel: EveryChannelTypes,
|
||||
at: Date,
|
||||
guildData?: TypingStartGuildData
|
||||
) => void
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { InviteCreatePayload } from '../../types/gateway.ts'
|
||||
import { ChannelPayload, GuildPayload, InvitePayload } from '../../../mod.ts'
|
||||
import { ChannelPayload } from '../../types/channel.ts'
|
||||
import { GuildPayload } from '../../types/guild.ts'
|
||||
import { InvitePayload } from '../../types/invite.ts'
|
||||
import { Invite } from '../../structures/invite.ts'
|
||||
|
||||
export const inviteCreate: GatewayEventHandler = async (
|
||||
|
@ -32,7 +34,7 @@ export const inviteCreate: GatewayEventHandler = async (
|
|||
channel: (cachedChannel as unknown) as ChannelPayload,
|
||||
inviter: d.inviter,
|
||||
target_user: d.target_user,
|
||||
target_user_type: d.target_user_type,
|
||||
target_user_type: d.target_user_type
|
||||
}
|
||||
|
||||
await guild.invites.set(d.code, dataConverted)
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Gateway, GatewayEventHandler } from '../index.ts'
|
|||
import { Guild } from '../../structures/guild.ts'
|
||||
import { InviteDeletePayload } from '../../types/gateway.ts'
|
||||
import { PartialInvitePayload } from '../../types/invite.ts'
|
||||
import { Channel } from '../../../mod.ts'
|
||||
import { Channel } from '../../structures/channel.ts'
|
||||
|
||||
export const inviteDelete: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
|
@ -24,7 +24,7 @@ export const inviteDelete: GatewayEventHandler = async (
|
|||
const uncachedInvite: PartialInvitePayload = {
|
||||
guild: (cachedGuild as unknown) as Guild,
|
||||
channel: (cachedChannel as unknown) as Channel,
|
||||
code: d.code,
|
||||
code: d.code
|
||||
}
|
||||
return gateway.client.emit('inviteDeleteUncached', uncachedInvite)
|
||||
} else {
|
||||
|
|
|
@ -34,7 +34,7 @@ export const messageReactionAdd: GatewayEventHandler = async (
|
|||
await message.reactions.set(d.emoji.id, {
|
||||
count: 1,
|
||||
emoji: d.emoji,
|
||||
me: d.user_id === gateway.client.user?.id,
|
||||
me: d.user_id === gateway.client.user?.id
|
||||
})
|
||||
reaction = ((await message.reactions.get(
|
||||
d.emoji.id
|
||||
|
|
|
@ -9,6 +9,6 @@ export const voiceServerUpdate: GatewayEventHandler = async (
|
|||
gateway.client.emit('voiceServerUpdate', {
|
||||
token: d.token,
|
||||
endpoint: d.endpoint,
|
||||
guild: ((await gateway.client.guilds.get(d.guild_id)) as unknown) as Guild,
|
||||
guild: ((await gateway.client.guilds.get(d.guild_id)) as unknown) as Guild
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { unzlib } from 'https://deno.land/x/denoflate@1.1/mod.ts'
|
|||
import { Client } from '../models/client.ts'
|
||||
import {
|
||||
DISCORD_GATEWAY_URL,
|
||||
DISCORD_API_VERSION,
|
||||
DISCORD_API_VERSION
|
||||
} from '../consts/urlsAndVersions.ts'
|
||||
import { GatewayResponse } from '../types/gatewayResponse.ts'
|
||||
import {
|
||||
|
@ -10,7 +10,7 @@ import {
|
|||
GatewayIntents,
|
||||
GatewayCloseCodes,
|
||||
IdentityPayload,
|
||||
StatusUpdatePayload,
|
||||
StatusUpdatePayload
|
||||
} from '../types/gateway.ts'
|
||||
import { gatewayHandlers } from './handlers/index.ts'
|
||||
import { GATEWAY_BOT } from '../types/endpoint.ts'
|
||||
|
@ -230,7 +230,7 @@ class Gateway {
|
|||
properties: {
|
||||
$os: Deno.build.os,
|
||||
$browser: 'harmony',
|
||||
$device: 'harmony',
|
||||
$device: 'harmony'
|
||||
},
|
||||
compress: true,
|
||||
shard: [0, 1], // TODO: Make sharding possible
|
||||
|
@ -238,7 +238,7 @@ class Gateway {
|
|||
(previous, current) => previous | current,
|
||||
0
|
||||
),
|
||||
presence: this.client.presence.create(),
|
||||
presence: this.client.presence.create()
|
||||
}
|
||||
|
||||
if (this.client.bot === false) {
|
||||
|
@ -250,13 +250,13 @@ class Gateway {
|
|||
$browser: 'Firefox',
|
||||
$device: '',
|
||||
$referrer: '',
|
||||
$referring_domain: '',
|
||||
$referring_domain: ''
|
||||
}
|
||||
}
|
||||
|
||||
this.send({
|
||||
op: GatewayOpcodes.IDENTIFY,
|
||||
d: payload,
|
||||
d: payload
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -272,8 +272,8 @@ class Gateway {
|
|||
d: {
|
||||
token: this.token,
|
||||
session_id: this.sessionID,
|
||||
seq: this.sequenceID ?? null,
|
||||
},
|
||||
seq: this.sequenceID ?? null
|
||||
}
|
||||
}
|
||||
this.send(resumePayload)
|
||||
}
|
||||
|
@ -292,8 +292,8 @@ class Gateway {
|
|||
limit: options.limit,
|
||||
presences: options.presences,
|
||||
user_ids: options.users,
|
||||
nonce,
|
||||
},
|
||||
nonce
|
||||
}
|
||||
})
|
||||
return nonce
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ class Gateway {
|
|||
op: data.op,
|
||||
d: data.d,
|
||||
s: typeof data.s === 'number' ? data.s : null,
|
||||
t: data.t === undefined ? null : data.t,
|
||||
t: data.t === undefined ? null : data.t
|
||||
})
|
||||
)
|
||||
return true
|
||||
|
@ -343,14 +343,14 @@ class Gateway {
|
|||
sendPresence(data: StatusUpdatePayload): void {
|
||||
this.send({
|
||||
op: GatewayOpcodes.PRESENCE_UPDATE,
|
||||
d: data,
|
||||
d: data
|
||||
})
|
||||
}
|
||||
|
||||
sendHeartbeat(): void {
|
||||
const payload = {
|
||||
op: GatewayOpcodes.HEARTBEAT,
|
||||
d: this.sequenceID ?? null,
|
||||
d: this.sequenceID ?? null
|
||||
}
|
||||
|
||||
this.send(payload)
|
||||
|
|
|
@ -8,37 +8,37 @@ export class BaseManager<T, T2> {
|
|||
/** Which data type does this cache have */
|
||||
DataType: any
|
||||
|
||||
constructor (client: Client, cacheName: string, DataType: any) {
|
||||
constructor(client: Client, cacheName: string, DataType: any) {
|
||||
this.client = client
|
||||
this.cacheName = cacheName
|
||||
this.DataType = DataType
|
||||
}
|
||||
|
||||
async _get (key: string): Promise<T | undefined> {
|
||||
async _get(key: string): Promise<T | undefined> {
|
||||
return this.client.cache.get(this.cacheName, key)
|
||||
}
|
||||
|
||||
async get (key: string): Promise<T2 | undefined> {
|
||||
async get(key: string): Promise<T2 | undefined> {
|
||||
const raw = await this._get(key)
|
||||
if (raw === undefined) return
|
||||
return new this.DataType(this.client, raw)
|
||||
}
|
||||
|
||||
async set (key: string, value: T): Promise<any> {
|
||||
async set(key: string, value: T): Promise<any> {
|
||||
return this.client.cache.set(this.cacheName, key, value)
|
||||
}
|
||||
|
||||
async delete (key: string): Promise<boolean> {
|
||||
async delete(key: string): Promise<boolean> {
|
||||
return this.client.cache.delete(this.cacheName, key)
|
||||
}
|
||||
|
||||
async array (): Promise<undefined | T2[]> {
|
||||
async array(): Promise<undefined | T2[]> {
|
||||
let arr = await (this.client.cache.array(this.cacheName) as T[])
|
||||
if (arr === undefined) arr = []
|
||||
return arr.map(e => new this.DataType(this.client, e)) as any
|
||||
return arr.map((e) => new this.DataType(this.client, e)) as any
|
||||
}
|
||||
|
||||
async collection (): Promise<Collection<string, T2>> {
|
||||
async collection(): Promise<Collection<string, T2>> {
|
||||
const arr = await this.array()
|
||||
if (arr === undefined) return new Collection()
|
||||
const collection = new Collection()
|
||||
|
@ -49,7 +49,7 @@ export class BaseManager<T, T2> {
|
|||
return collection
|
||||
}
|
||||
|
||||
flush (): any {
|
||||
flush(): any {
|
||||
return this.client.cache.deleteCache(this.cacheName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ export class BaseChildManager<T, T2> {
|
|||
}
|
||||
|
||||
async collection(): Promise<Collection<string, T2>> {
|
||||
const arr = await this.array() as undefined | T2[]
|
||||
const arr = (await this.array()) as undefined | T2[]
|
||||
if (arr === undefined) return new Collection()
|
||||
const collection = new Collection()
|
||||
for (const elem of arr) {
|
||||
|
|
|
@ -6,12 +6,12 @@ import getChannelByType from '../utils/getChannelByType.ts'
|
|||
import { BaseManager } from './base.ts'
|
||||
|
||||
export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||
constructor (client: Client) {
|
||||
constructor(client: Client) {
|
||||
super(client, 'channels', Channel)
|
||||
}
|
||||
|
||||
// Override get method as Generic
|
||||
async get<T = Channel> (key: string): Promise<T | undefined> {
|
||||
async get<T = Channel>(key: string): Promise<T | undefined> {
|
||||
const data = await this._get(key)
|
||||
if (data === undefined) return
|
||||
let guild
|
||||
|
@ -25,7 +25,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
|||
return res as any
|
||||
}
|
||||
|
||||
async array (): Promise<undefined | Channel[]> {
|
||||
async array(): Promise<undefined | Channel[]> {
|
||||
const arr = await (this.client.cache.array(
|
||||
this.cacheName
|
||||
) as ChannelPayload[])
|
||||
|
@ -43,19 +43,25 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
|||
return result
|
||||
}
|
||||
|
||||
async fetch<T = Channel> (id: string): Promise<T> {
|
||||
async fetch<T = Channel>(id: string): Promise<T> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(CHANNEL(id))
|
||||
.then(async data => {
|
||||
.then(async (data) => {
|
||||
this.set(id, data as ChannelPayload)
|
||||
let guild
|
||||
if (data.guild_id !== undefined) {
|
||||
guild = await this.client.guilds.get(data.guild_id)
|
||||
}
|
||||
resolve((getChannelByType(this.client, data as ChannelPayload, guild) as unknown) as T)
|
||||
resolve(
|
||||
(getChannelByType(
|
||||
this.client,
|
||||
data as ChannelPayload,
|
||||
guild
|
||||
) as unknown) as T
|
||||
)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,11 @@ import { GUILD_EMOJI } from '../types/endpoint.ts'
|
|||
import { BaseManager } from './base.ts'
|
||||
|
||||
export class EmojisManager extends BaseManager<EmojiPayload, Emoji> {
|
||||
|
||||
constructor (client: Client) {
|
||||
constructor(client: Client) {
|
||||
super(client, `emojis`, Emoji)
|
||||
}
|
||||
|
||||
async get (key: string): Promise<Emoji | undefined> {
|
||||
async get(key: string): Promise<Emoji | undefined> {
|
||||
const raw = await this._get(key)
|
||||
if (raw === undefined) return
|
||||
const emoji = new this.DataType(this.client, raw)
|
||||
|
@ -21,15 +20,15 @@ export class EmojisManager extends BaseManager<EmojiPayload, Emoji> {
|
|||
return emoji
|
||||
}
|
||||
|
||||
async fetch (guildID: string, id: string): Promise<Emoji> {
|
||||
async fetch(guildID: string, id: string): Promise<Emoji> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(GUILD_EMOJI(guildID, id))
|
||||
.then(async data => {
|
||||
.then(async (data) => {
|
||||
await this.set(id, data as EmojiPayload)
|
||||
resolve(new Emoji(this.client, data as EmojiPayload))
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,22 +4,22 @@ export class GatewayCache {
|
|||
client: Client
|
||||
cacheName: string = 'discord_gateway_cache'
|
||||
|
||||
constructor (client: Client, cacheName?: string) {
|
||||
constructor(client: Client, cacheName?: string) {
|
||||
this.client = client
|
||||
if (cacheName !== undefined) this.cacheName = cacheName
|
||||
}
|
||||
|
||||
async get (key: string): Promise<undefined | any> {
|
||||
async get(key: string): Promise<undefined | any> {
|
||||
const result = await this.client.cache.get(this.cacheName, key)
|
||||
return result
|
||||
}
|
||||
|
||||
async set (key: string, value: any): Promise<any> {
|
||||
async set(key: string, value: any): Promise<any> {
|
||||
const result = await this.client.cache.set(this.cacheName, key, value)
|
||||
return result
|
||||
}
|
||||
|
||||
async delete (key: string): Promise<boolean> {
|
||||
async delete(key: string): Promise<boolean> {
|
||||
const result = await this.client.cache.delete(this.cacheName, key)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ export class GuildChannelsManager extends BaseChildManager<
|
|||
> {
|
||||
guild: Guild
|
||||
|
||||
constructor (client: Client, parent: ChannelsManager, guild: Guild) {
|
||||
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
|
||||
super(client, parent as any)
|
||||
this.guild = guild
|
||||
}
|
||||
|
||||
async get (id: string): Promise<GuildChannel | undefined> {
|
||||
async get(id: string): Promise<GuildChannel | undefined> {
|
||||
const res = await this.parent.get(id)
|
||||
if (res !== undefined && res.guild.id === this.guild.id) return res
|
||||
else return undefined
|
||||
|
@ -40,14 +40,14 @@ export class GuildChannelsManager extends BaseChildManager<
|
|||
return this.client.rest.delete(CHANNEL(id))
|
||||
}
|
||||
|
||||
async array (): Promise<GuildChannel[]> {
|
||||
async array(): Promise<GuildChannel[]> {
|
||||
const arr = (await this.parent.array()) as Channel[]
|
||||
return arr.filter(
|
||||
(c: any) => c.guild !== undefined && c.guild.id === this.guild.id
|
||||
) as any
|
||||
}
|
||||
|
||||
async flush (): Promise<boolean> {
|
||||
async flush(): Promise<boolean> {
|
||||
const arr = await this.array()
|
||||
for (const elem of arr) {
|
||||
this.parent.delete(elem.id)
|
||||
|
|
|
@ -8,10 +8,7 @@ import { BaseChildManager } from './baseChild.ts'
|
|||
import { EmojisManager } from './emojis.ts'
|
||||
import { fetchAuto } from 'https://raw.githubusercontent.com/DjDeveloperr/fetch-base64/main/mod.ts'
|
||||
|
||||
export class GuildEmojisManager extends BaseChildManager<
|
||||
EmojiPayload,
|
||||
Emoji
|
||||
> {
|
||||
export class GuildEmojisManager extends BaseChildManager<EmojiPayload, Emoji> {
|
||||
guild: Guild
|
||||
|
||||
constructor(client: Client, parent: EmojisManager, guild: Guild) {
|
||||
|
@ -33,28 +30,34 @@ export class GuildEmojisManager extends BaseChildManager<
|
|||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(GUILD_EMOJI(this.guild.id, id))
|
||||
.then(async data => {
|
||||
.then(async (data) => {
|
||||
const emoji = new Emoji(this.client, data as EmojiPayload)
|
||||
data.guild_id = this.guild.id
|
||||
await this.set(id, data as EmojiPayload)
|
||||
emoji.guild = this.guild
|
||||
resolve(emoji)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
|
||||
async create(name: string, url: string, roles?: Role[] | string[] | string): Promise<Emoji | undefined> {
|
||||
async create(
|
||||
name: string,
|
||||
url: string,
|
||||
roles?: Role[] | string[] | string
|
||||
): Promise<Emoji | undefined> {
|
||||
let data = url
|
||||
if (!data.startsWith("data:")) {
|
||||
if (!data.startsWith('data:')) {
|
||||
data = await fetchAuto(url)
|
||||
}
|
||||
return await new Promise((resolve, reject) => {
|
||||
let roleIDs: string[] = []
|
||||
if (roles !== undefined && typeof roles === "string") roleIDs = [roles]
|
||||
if (roles !== undefined && typeof roles === 'string') roleIDs = [roles]
|
||||
else if (roles !== undefined) {
|
||||
if (roles?.length === 0) reject(new Error("Empty Roles array was provided"))
|
||||
if (roles[0] instanceof Role) roleIDs = (roles as any).map((r: Role) => r.id)
|
||||
if (roles?.length === 0)
|
||||
reject(new Error('Empty Roles array was provided'))
|
||||
if (roles[0] instanceof Role)
|
||||
roleIDs = (roles as any).map((r: Role) => r.id)
|
||||
else roleIDs = roles as string[]
|
||||
} else roles = [this.guild.id]
|
||||
this.client.rest
|
||||
|
@ -63,14 +66,14 @@ export class GuildEmojisManager extends BaseChildManager<
|
|||
image: data,
|
||||
roles: roleIDs
|
||||
})
|
||||
.then(async data => {
|
||||
.then(async (data) => {
|
||||
const emoji = new Emoji(this.client, data as EmojiPayload)
|
||||
data.guild_id = this.guild.id
|
||||
await this.set(data.id, data as EmojiPayload)
|
||||
emoji.guild = this.guild
|
||||
resolve(emoji)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ export class GuildVoiceStatesManager extends BaseManager<
|
|||
)) as unknown) as VoiceChannel),
|
||||
guild,
|
||||
member:
|
||||
guild === undefined ? undefined : await guild.members.get(raw.user_id),
|
||||
guild === undefined ? undefined : await guild.members.get(raw.user_id)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ import { BaseManager } from './base.ts'
|
|||
import { MembersManager } from './members.ts'
|
||||
|
||||
export class GuildManager extends BaseManager<GuildPayload, Guild> {
|
||||
constructor (client: Client) {
|
||||
constructor(client: Client) {
|
||||
super(client, 'guilds', Guild)
|
||||
}
|
||||
|
||||
async fetch (id: string): Promise<Guild> {
|
||||
async fetch(id: string): Promise<Guild> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(GUILD(id))
|
||||
|
@ -29,7 +29,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
|
|||
|
||||
resolve(guild)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Member } from '../structures/member.ts'
|
|||
import { GUILD_MEMBER } from '../types/endpoint.ts'
|
||||
import { MemberPayload } from '../types/guild.ts'
|
||||
import { BaseManager } from './base.ts'
|
||||
import { Permissions } from "../utils/permissions.ts"
|
||||
import { Permissions } from '../utils/permissions.ts'
|
||||
|
||||
export class MembersManager extends BaseManager<MemberPayload, Member> {
|
||||
guild: Guild
|
||||
|
@ -22,27 +22,47 @@ export class MembersManager extends BaseManager<MemberPayload, Member> {
|
|||
const roles = await this.guild.roles.array()
|
||||
let permissions = new Permissions(Permissions.DEFAULT)
|
||||
if (roles !== undefined) {
|
||||
const mRoles = roles.filter(r => raw.roles.includes(r.id) as boolean || r.id === this.guild.id)
|
||||
permissions = new Permissions(mRoles.map(r => r.permissions))
|
||||
const mRoles = roles.filter(
|
||||
(r) => (raw.roles.includes(r.id) as boolean) || r.id === this.guild.id
|
||||
)
|
||||
permissions = new Permissions(mRoles.map((r) => r.permissions))
|
||||
}
|
||||
const res = new this.DataType(this.client, raw, user, this.guild, permissions)
|
||||
const res = new this.DataType(
|
||||
this.client,
|
||||
raw,
|
||||
user,
|
||||
this.guild,
|
||||
permissions
|
||||
)
|
||||
return res
|
||||
}
|
||||
|
||||
async fetch(id: string): Promise<Member> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(async data => {
|
||||
await this.set(id, data as MemberPayload)
|
||||
const user: User = new User(this.client, data.user)
|
||||
const roles = await this.guild.roles.array()
|
||||
let permissions = new Permissions(Permissions.DEFAULT)
|
||||
if (roles !== undefined) {
|
||||
const mRoles = roles.filter(r => data.roles.includes(r.id) as boolean || r.id === this.guild.id)
|
||||
permissions = new Permissions(mRoles.map(r => r.permissions))
|
||||
}
|
||||
const res = new Member(this.client, data as MemberPayload, user, this.guild, permissions)
|
||||
resolve(res)
|
||||
}).catch(e => reject(e))
|
||||
this.client.rest
|
||||
.get(GUILD_MEMBER(this.guild.id, id))
|
||||
.then(async (data) => {
|
||||
await this.set(id, data as MemberPayload)
|
||||
const user: User = new User(this.client, data.user)
|
||||
const roles = await this.guild.roles.array()
|
||||
let permissions = new Permissions(Permissions.DEFAULT)
|
||||
if (roles !== undefined) {
|
||||
const mRoles = roles.filter(
|
||||
(r) =>
|
||||
(data.roles.includes(r.id) as boolean) || r.id === this.guild.id
|
||||
)
|
||||
permissions = new Permissions(mRoles.map((r) => r.permissions))
|
||||
}
|
||||
const res = new Member(
|
||||
this.client,
|
||||
data as MemberPayload,
|
||||
user,
|
||||
this.guild,
|
||||
permissions
|
||||
)
|
||||
resolve(res)
|
||||
})
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -8,20 +8,20 @@ import { BaseManager } from './base.ts'
|
|||
export class RolesManager extends BaseManager<RolePayload, Role> {
|
||||
guild: Guild
|
||||
|
||||
constructor (client: Client, guild: Guild) {
|
||||
constructor(client: Client, guild: Guild) {
|
||||
super(client, `roles:${guild.id}`, Role)
|
||||
this.guild = guild
|
||||
}
|
||||
|
||||
async fetch (id: string): Promise<Role> {
|
||||
async fetch(id: string): Promise<Role> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(GUILD_ROLE(this.guild.id, id))
|
||||
.then(data => {
|
||||
.then((data) => {
|
||||
this.set(id, data as RolePayload)
|
||||
resolve(new Role(this.client, data as RolePayload))
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@ import { UserPayload } from '../types/user.ts'
|
|||
import { BaseManager } from './base.ts'
|
||||
|
||||
export class UserManager extends BaseManager<UserPayload, User> {
|
||||
constructor (client: Client) {
|
||||
constructor(client: Client) {
|
||||
super(client, 'users', User)
|
||||
}
|
||||
|
||||
async fetch (id: string): Promise<User> {
|
||||
async fetch(id: string): Promise<User> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(USER(id))
|
||||
.then(data => {
|
||||
.then((data) => {
|
||||
this.set(id, data as UserPayload)
|
||||
resolve(new User(this.client, data as UserPayload))
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
.catch((e) => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,12 @@ import {
|
|||
|
||||
export interface ICacheAdapter {
|
||||
get: (cacheName: string, key: string) => Promise<any> | any
|
||||
set: (cacheName: string, key: string, value: any, expire?: number) => Promise<any> | any
|
||||
set: (
|
||||
cacheName: string,
|
||||
key: string,
|
||||
value: any,
|
||||
expire?: number
|
||||
) => Promise<any> | any
|
||||
delete: (cacheName: string, key: string) => Promise<boolean> | boolean
|
||||
array: (cacheName: string) => undefined | any[] | Promise<any[] | undefined>
|
||||
deleteCache: (cacheName: string) => any
|
||||
|
@ -24,16 +29,22 @@ export class DefaultCacheAdapter implements ICacheAdapter {
|
|||
return cache.get(key)
|
||||
}
|
||||
|
||||
async set(cacheName: string, key: string, value: any, expire?: number): Promise<any> {
|
||||
async set(
|
||||
cacheName: string,
|
||||
key: string,
|
||||
value: any,
|
||||
expire?: number
|
||||
): Promise<any> {
|
||||
let cache = this.data[cacheName]
|
||||
if (cache === undefined) {
|
||||
this.data[cacheName] = new Collection()
|
||||
cache = this.data[cacheName]
|
||||
}
|
||||
cache.set(key, value)
|
||||
if (expire !== undefined) setTimeout(() => {
|
||||
cache.delete(key)
|
||||
}, expire)
|
||||
if (expire !== undefined)
|
||||
setTimeout(() => {
|
||||
cache.delete(key)
|
||||
}, expire)
|
||||
}
|
||||
|
||||
async delete(cacheName: string, key: string): Promise<boolean> {
|
||||
|
@ -64,7 +75,7 @@ export class RedisCacheAdapter implements ICacheAdapter {
|
|||
constructor(options: RedisConnectOptions) {
|
||||
this._redis = connect(options)
|
||||
this._redis.then(
|
||||
redis => {
|
||||
(redis) => {
|
||||
this.redis = redis
|
||||
this.ready = true
|
||||
this._startExpireInterval()
|
||||
|
@ -79,11 +90,11 @@ export class RedisCacheAdapter implements ICacheAdapter {
|
|||
this._expireInterval = setInterval(() => {
|
||||
this.redis?.scan(0, { pattern: '*:expires' }).then(([_, names]) => {
|
||||
for (const name of names) {
|
||||
this.redis?.hvals(name).then(vals => {
|
||||
this.redis?.hvals(name).then((vals) => {
|
||||
for (const val of vals) {
|
||||
const expireVal: {
|
||||
name: string,
|
||||
key: string,
|
||||
name: string
|
||||
key: string
|
||||
at: number
|
||||
} = JSON.parse(val)
|
||||
const expired = new Date().getTime() > expireVal.at
|
||||
|
@ -126,7 +137,11 @@ export class RedisCacheAdapter implements ICacheAdapter {
|
|||
await this.redis?.hset(
|
||||
`${cacheName}:expires`,
|
||||
key,
|
||||
JSON.stringify({ name: cacheName, key, at: new Date().getTime() + expire })
|
||||
JSON.stringify({
|
||||
name: cacheName,
|
||||
key,
|
||||
at: new Date().getTime() + expire
|
||||
})
|
||||
)
|
||||
}
|
||||
return result
|
||||
|
@ -148,6 +163,6 @@ export class RedisCacheAdapter implements ICacheAdapter {
|
|||
|
||||
async deleteCache(cacheName: string): Promise<boolean> {
|
||||
await this._checkReady()
|
||||
return await this.redis?.del(cacheName) !== 0
|
||||
return (await this.redis?.del(cacheName)) !== 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import { ClientPresence } from '../structures/presence.ts'
|
|||
import { EmojisManager } from '../managers/emojis.ts'
|
||||
import { ActivityGame, ClientActivity } from '../types/presence.ts'
|
||||
import { ClientEvents } from '../gateway/handlers/index.ts'
|
||||
// import { Application } from "../../mod.ts"
|
||||
|
||||
/** Some Client Options to modify behaviour */
|
||||
export interface ClientOptions {
|
||||
|
|
|
@ -142,7 +142,7 @@ export class CommandBuilder extends Command {
|
|||
...new Set(
|
||||
...this.aliases,
|
||||
...(typeof alias === 'string' ? [alias] : alias)
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
return this
|
||||
|
@ -166,7 +166,7 @@ export class CommandBuilder extends Command {
|
|||
...new Set(
|
||||
...this.usage,
|
||||
...(typeof usage === 'string' ? [usage] : usage)
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
return this
|
||||
|
@ -185,7 +185,7 @@ export class CommandBuilder extends Command {
|
|||
...new Set(
|
||||
...this.examples,
|
||||
...(typeof examples === 'string' ? [examples] : examples)
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
return this
|
||||
|
@ -423,6 +423,6 @@ export const parseCommand = (
|
|||
return {
|
||||
name,
|
||||
args,
|
||||
argString,
|
||||
argString
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Message } from '../../mod.ts'
|
||||
import { Message } from '../structures/message.ts'
|
||||
import { awaitSync } from '../utils/mixedPromise.ts'
|
||||
import { Client, ClientOptions } from './client.ts'
|
||||
import {
|
||||
CategoriesManager,
|
||||
CommandContext,
|
||||
CommandsManager,
|
||||
parseCommand,
|
||||
parseCommand
|
||||
} from './command.ts'
|
||||
import { ExtensionsManager } from './extensions.ts'
|
||||
|
||||
|
@ -108,12 +108,12 @@ export class CommandClient extends Client implements CommandClientOptions {
|
|||
if (isGuildBlacklisted === true) return
|
||||
}
|
||||
|
||||
let prefix: string | string[] = this.prefix
|
||||
let prefix: string | string[] = await awaitSync(
|
||||
this.getUserPrefix(msg.author.id)
|
||||
)
|
||||
|
||||
if (msg.guild !== undefined) {
|
||||
prefix = await awaitSync(this.getGuildPrefix(msg.guild.id))
|
||||
} else {
|
||||
prefix = await awaitSync(this.getUserPrefix(msg.author.id))
|
||||
}
|
||||
|
||||
let mentionPrefix = false
|
||||
|
@ -204,7 +204,7 @@ export class CommandClient extends Client implements CommandClientOptions {
|
|||
author: msg.author,
|
||||
command,
|
||||
channel: msg.channel,
|
||||
guild: msg.guild,
|
||||
guild: msg.guild
|
||||
}
|
||||
|
||||
// In these checks too, Command overrides Category if present
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Collection } from "../utils/collection.ts";
|
||||
import { Command } from "./command.ts";
|
||||
import { CommandClient } from "./commandClient.ts";
|
||||
import { Collection } from '../utils/collection.ts'
|
||||
import { Command } from './command.ts'
|
||||
import { CommandClient } from './commandClient.ts'
|
||||
|
||||
export type ExtensionEventCallback = (ext: Extension, ...args: any[]) => any
|
||||
|
||||
|
@ -12,7 +12,9 @@ export class ExtensionCommands {
|
|||
}
|
||||
|
||||
get list(): Collection<string, Command> {
|
||||
return this.extension.client.commands.list.filter(c => c.extension?.name === this.extension.name)
|
||||
return this.extension.client.commands.list.filter(
|
||||
(c) => c.extension?.name === this.extension.name
|
||||
)
|
||||
}
|
||||
|
||||
get(cmd: string): Command | undefined {
|
||||
|
@ -31,9 +33,15 @@ export class ExtensionCommands {
|
|||
}
|
||||
|
||||
delete(cmd: Command | string): boolean {
|
||||
const find = this.extension.client.commands.find(typeof cmd === 'string' ? cmd : cmd.name)
|
||||
const find = this.extension.client.commands.find(
|
||||
typeof cmd === 'string' ? cmd : cmd.name
|
||||
)
|
||||
if (find === undefined) return false
|
||||
if (find.extension !== undefined && find.extension.name !== this.extension.name) return false
|
||||
if (
|
||||
find.extension !== undefined &&
|
||||
find.extension.name !== this.extension.name
|
||||
)
|
||||
return false
|
||||
else return this.extension.client.commands.delete(find)
|
||||
}
|
||||
|
||||
|
@ -61,7 +69,7 @@ export class Extension {
|
|||
const fn = (...args: any[]): any => {
|
||||
// eslint-disable-next-line standard/no-callback-literal
|
||||
cb(this, ...args)
|
||||
};
|
||||
}
|
||||
this.client.on(event, fn)
|
||||
this.events[event] = fn
|
||||
return true
|
||||
|
@ -91,7 +99,8 @@ export class ExtensionsManager {
|
|||
load(ext: Extension | typeof Extension): void {
|
||||
// eslint-disable-next-line new-cap
|
||||
if (!(ext instanceof Extension)) ext = new ext(this.client)
|
||||
if (this.exists(ext.name)) throw new Error(`Extension with name '${ext.name}' already exists`)
|
||||
if (this.exists(ext.name))
|
||||
throw new Error(`Extension with name '${ext.name}' already exists`)
|
||||
this.list.set(ext.name, ext)
|
||||
ext.load()
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export enum HttpResponseCode {
|
|||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
TooManyRequests = 429,
|
||||
GatewayUnavailable = 502,
|
||||
GatewayUnavailable = 502
|
||||
}
|
||||
|
||||
export interface RequestHeaders {
|
||||
|
@ -109,7 +109,7 @@ export class RESTManager {
|
|||
if (result?.rateLimited !== undefined) {
|
||||
this.queue({
|
||||
...request,
|
||||
bucket: result.bucket ?? request.bucket,
|
||||
bucket: result.bucket ?? request.bucket
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ export class RESTManager {
|
|||
if (result?.rateLimited !== undefined) {
|
||||
this.queue({
|
||||
...request,
|
||||
bucket: result.bucket ?? request.bucket,
|
||||
bucket: result.bucket ?? request.bucket
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ export class RESTManager {
|
|||
|
||||
prepare(body: any, method: RequestMethods): { [key: string]: any } {
|
||||
const headers: RequestHeaders = {
|
||||
'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)`,
|
||||
'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)`
|
||||
}
|
||||
|
||||
if (this.client !== undefined)
|
||||
|
@ -168,7 +168,7 @@ export class RESTManager {
|
|||
const data: { [name: string]: any } = {
|
||||
headers,
|
||||
body: body?.file ?? JSON.stringify(body),
|
||||
method: method.toUpperCase(),
|
||||
method: method.toUpperCase()
|
||||
}
|
||||
|
||||
if (this.client?.bot === false) {
|
||||
|
@ -222,14 +222,14 @@ export class RESTManager {
|
|||
this.rateLimits.set(url, {
|
||||
url,
|
||||
resetAt: Number(resetAt) * 1000,
|
||||
bucket,
|
||||
bucket
|
||||
})
|
||||
|
||||
if (bucket !== null) {
|
||||
this.rateLimits.set(bucket, {
|
||||
url,
|
||||
resetAt: Number(resetAt) * 1000,
|
||||
bucket,
|
||||
bucket
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -242,14 +242,14 @@ export class RESTManager {
|
|||
this.rateLimits.set('global', {
|
||||
url: 'global',
|
||||
resetAt: reset,
|
||||
bucket,
|
||||
bucket
|
||||
})
|
||||
|
||||
if (bucket !== null) {
|
||||
this.rateLimits.set(bucket, {
|
||||
url: 'global',
|
||||
resetAt: reset,
|
||||
bucket,
|
||||
bucket
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ export class RESTManager {
|
|||
url: response.url,
|
||||
status,
|
||||
method: data.method,
|
||||
body: data.body,
|
||||
body: data.body
|
||||
}
|
||||
if (body !== undefined) error = Object.assign(error, body)
|
||||
|
||||
|
@ -295,7 +295,7 @@ export class RESTManager {
|
|||
HttpResponseCode.BadRequest,
|
||||
HttpResponseCode.NotFound,
|
||||
HttpResponseCode.Forbidden,
|
||||
HttpResponseCode.MethodNotAllowed,
|
||||
HttpResponseCode.MethodNotAllowed
|
||||
].includes(status)
|
||||
) {
|
||||
throw new DiscordAPIError(Deno.inspect(error))
|
||||
|
@ -320,7 +320,7 @@ export class RESTManager {
|
|||
return {
|
||||
rateLimited: rateLimitResetIn,
|
||||
before: true,
|
||||
bucket,
|
||||
bucket
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,7 @@ export class RESTManager {
|
|||
return {
|
||||
rateLimited: json.retry_after,
|
||||
before: false,
|
||||
bucket: bucketFromHeaders,
|
||||
bucket: bucketFromHeaders
|
||||
}
|
||||
}
|
||||
return resolve(rawResponse === true ? { response, body: json } : json)
|
||||
|
@ -379,7 +379,7 @@ export class RESTManager {
|
|||
this.queue({
|
||||
onComplete,
|
||||
bucket,
|
||||
url,
|
||||
url
|
||||
})
|
||||
if (!this.processing) {
|
||||
this.processing = true
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Guild } from "../structures/guild.ts"
|
||||
import { VoiceChannel } from "../structures/guildVoiceChannel.ts"
|
||||
import { Guild } from '../structures/guild.ts'
|
||||
import { VoiceChannel } from '../structures/guildVoiceChannel.ts'
|
||||
import { Client } from './client.ts'
|
||||
|
||||
export interface VoiceOptions {
|
||||
guild: Guild,
|
||||
guild: Guild
|
||||
channel: VoiceChannel
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Client } from "../models/client.ts";
|
||||
import { ApplicationPayload } from "../types/application.ts";
|
||||
import { Base } from "./base.ts";
|
||||
import { User } from "./user.ts";
|
||||
import { Client } from '../models/client.ts'
|
||||
import { ApplicationPayload } from '../types/application.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { User } from './user.ts'
|
||||
|
||||
export class Application extends Base {
|
||||
id: string
|
||||
|
|
|
@ -13,18 +13,21 @@ export class Base {
|
|||
static useCache?: boolean = true
|
||||
static restFunc?: (...restURLfuncArgs: string[]) => string
|
||||
|
||||
constructor (client: Client, _data?: any) {
|
||||
constructor(client: Client, _data?: any) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
static async autoInit (
|
||||
static async autoInit(
|
||||
client: Client,
|
||||
{ useCache, endpoint, restURLfuncArgs }: IInit
|
||||
): Promise<any> {
|
||||
this.useCache = useCache
|
||||
const cacheID = restURLfuncArgs.join(':')
|
||||
if (this.useCache !== undefined) {
|
||||
const cached = await client.cache.get(this.cacheName ?? this.name, cacheID)
|
||||
const cached = await client.cache.get(
|
||||
this.cacheName ?? this.name,
|
||||
cacheID
|
||||
)
|
||||
if (cached !== undefined) {
|
||||
return cached
|
||||
}
|
||||
|
@ -35,7 +38,7 @@ export class Base {
|
|||
return new this(client, jsonParsed)
|
||||
}
|
||||
|
||||
async refreshFromAPI (
|
||||
async refreshFromAPI(
|
||||
client: Client,
|
||||
{ endpoint, restURLfuncArgs }: IInit
|
||||
): Promise<this> {
|
||||
|
@ -48,13 +51,13 @@ export class Base {
|
|||
return oldOne
|
||||
}
|
||||
|
||||
refreshFromData (data: { [k: string]: any }): this {
|
||||
refreshFromData(data: { [k: string]: any }): this {
|
||||
const oldOne = Object.assign(Object.create(this), this)
|
||||
this.readFromData(data)
|
||||
return oldOne
|
||||
}
|
||||
|
||||
protected readFromData (data: { [k: string]: any }): void {}
|
||||
protected readFromData(data: { [k: string]: any }): void {}
|
||||
|
||||
// toJSON() {}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ export class Channel extends Base {
|
|||
type: ChannelTypes
|
||||
id: string
|
||||
static cacheName = 'channel'
|
||||
get mention (): string {
|
||||
get mention(): string {
|
||||
return `<#${this.id}>`
|
||||
}
|
||||
|
||||
constructor (client: Client, data: ChannelPayload) {
|
||||
constructor(client: Client, data: ChannelPayload) {
|
||||
super(client, data)
|
||||
this.type = data.type
|
||||
this.id = data.id
|
||||
|
@ -18,7 +18,7 @@ export class Channel extends Base {
|
|||
// this.client.channels.set(this.id, data)
|
||||
}
|
||||
|
||||
protected readFromData (data: ChannelPayload): void {
|
||||
protected readFromData(data: ChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.type = data.type ?? this.type
|
||||
this.id = data.id ?? this.id
|
||||
|
|
|
@ -6,12 +6,12 @@ import { TextChannel } from './textChannel.ts'
|
|||
export class DMChannel extends TextChannel {
|
||||
recipients: UserPayload[]
|
||||
|
||||
constructor (client: Client, data: DMChannelPayload) {
|
||||
constructor(client: Client, data: DMChannelPayload) {
|
||||
super(client, data)
|
||||
this.recipients = data.recipients
|
||||
}
|
||||
|
||||
protected readFromData (data: DMChannelPayload): void {
|
||||
protected readFromData(data: DMChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.recipients = data.recipients ?? this.recipients
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ export class Embed {
|
|||
author?: EmbedAuthor
|
||||
fields?: EmbedField[]
|
||||
|
||||
constructor (data?: EmbedPayload) {
|
||||
constructor(data?: EmbedPayload) {
|
||||
this.title = data?.title
|
||||
this.type = data?.type
|
||||
this.description = data?.description
|
||||
|
@ -42,7 +42,7 @@ export class Embed {
|
|||
}
|
||||
|
||||
// khk4912
|
||||
toJSON (): EmbedPayload {
|
||||
toJSON(): EmbedPayload {
|
||||
return {
|
||||
title: this.title,
|
||||
type: this.type,
|
||||
|
@ -60,72 +60,72 @@ export class Embed {
|
|||
}
|
||||
}
|
||||
|
||||
setTitle (title: string): Embed {
|
||||
setTitle(title: string): Embed {
|
||||
this.title = title
|
||||
return this
|
||||
}
|
||||
|
||||
setDescription (description: string): Embed {
|
||||
setDescription(description: string): Embed {
|
||||
this.description = description
|
||||
return this
|
||||
}
|
||||
|
||||
setType (type: EmbedTypes): Embed {
|
||||
setType(type: EmbedTypes): Embed {
|
||||
this.type = type
|
||||
return this
|
||||
}
|
||||
|
||||
setURL (url: string): Embed {
|
||||
setURL(url: string): Embed {
|
||||
this.url = url
|
||||
return this
|
||||
}
|
||||
|
||||
setTimestamp (timestamp: string): Embed {
|
||||
setTimestamp(timestamp: string): Embed {
|
||||
this.timestamp = timestamp
|
||||
return this
|
||||
}
|
||||
|
||||
setColor (hex: number): Embed {
|
||||
setColor(hex: number): Embed {
|
||||
this.color = hex
|
||||
return this
|
||||
}
|
||||
|
||||
setFooter (footer: EmbedFooter): Embed {
|
||||
setFooter(footer: EmbedFooter): Embed {
|
||||
this.footer = footer
|
||||
return this
|
||||
}
|
||||
|
||||
setImage (image: EmbedImage): Embed {
|
||||
setImage(image: EmbedImage): Embed {
|
||||
this.image = image
|
||||
return this
|
||||
}
|
||||
|
||||
setThumbnail (thumbnail: EmbedThumbnail): Embed {
|
||||
setThumbnail(thumbnail: EmbedThumbnail): Embed {
|
||||
this.thumbnail = thumbnail
|
||||
return this
|
||||
}
|
||||
|
||||
setVideo (video: EmbedVideo): Embed {
|
||||
setVideo(video: EmbedVideo): Embed {
|
||||
this.video = video
|
||||
return this
|
||||
}
|
||||
|
||||
setProvider (provider: EmbedProvider): Embed {
|
||||
setProvider(provider: EmbedProvider): Embed {
|
||||
this.provider = provider
|
||||
return this
|
||||
}
|
||||
|
||||
setAuthor (author: EmbedAuthor): Embed {
|
||||
setAuthor(author: EmbedAuthor): Embed {
|
||||
this.author = author
|
||||
return this
|
||||
}
|
||||
|
||||
setFields (fields: EmbedField[]): Embed {
|
||||
setFields(fields: EmbedField[]): Embed {
|
||||
this.fields = fields
|
||||
return this
|
||||
}
|
||||
|
||||
addField (name: string, value: string, inline?: boolean): Embed {
|
||||
addField(name: string, value: string, inline?: boolean): Embed {
|
||||
if (this.fields === undefined) {
|
||||
this.fields = [
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ export class Emoji extends Base {
|
|||
animated?: boolean
|
||||
available?: boolean
|
||||
|
||||
get getEmojiString (): string {
|
||||
get getEmojiString(): string {
|
||||
if (this.animated === false) {
|
||||
return `<:${this.name}:${this.id}>`
|
||||
} else return `<a:${this.name}:${this.id}>`
|
||||
|
@ -26,7 +26,7 @@ export class Emoji extends Base {
|
|||
return this.getEmojiString
|
||||
}
|
||||
|
||||
constructor (client: Client, data: EmojiPayload) {
|
||||
constructor(client: Client, data: EmojiPayload) {
|
||||
super(client, data)
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
|
@ -38,7 +38,7 @@ export class Emoji extends Base {
|
|||
this.available = data.available
|
||||
}
|
||||
|
||||
protected readFromData (data: EmojiPayload): void {
|
||||
protected readFromData(data: EmojiPayload): void {
|
||||
super.readFromData(data)
|
||||
this.id = data.id ?? this.id
|
||||
this.name = data.name ?? this.name
|
||||
|
@ -51,7 +51,7 @@ export class Emoji extends Base {
|
|||
User.autoInit(this.client, {
|
||||
endpoint: USER,
|
||||
restURLfuncArgs: [data.user.id]
|
||||
}).then(user => (this.user = user))
|
||||
}).then((user) => (this.user = user))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ export class GroupDMChannel extends Channel {
|
|||
icon?: string
|
||||
ownerID: string
|
||||
|
||||
constructor (client: Client, data: GroupDMChannelPayload) {
|
||||
constructor(client: Client, data: GroupDMChannelPayload) {
|
||||
super(client, data)
|
||||
|
||||
this.name = data.name
|
||||
|
@ -17,7 +17,7 @@ export class GroupDMChannel extends Channel {
|
|||
// cache.set('groupchannel', this.id, this)
|
||||
}
|
||||
|
||||
protected readFromData (data: GroupDMChannelPayload): void {
|
||||
protected readFromData(data: GroupDMChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.name = data.name ?? this.name
|
||||
this.icon = data.icon ?? this.icon
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
GuildIntegrationPayload,
|
||||
GuildPayload,
|
||||
IntegrationAccountPayload,
|
||||
IntegrationExpireBehavior,
|
||||
IntegrationExpireBehavior
|
||||
} from '../types/guild.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { RolesManager } from '../managers/roles.ts'
|
||||
|
@ -85,7 +85,7 @@ export class GuildBans {
|
|||
GUILD_BAN(this.guild.id, typeof user === 'string' ? user : user.id),
|
||||
{
|
||||
reason,
|
||||
delete_message_days: deleteMessagesDays,
|
||||
delete_message_days: deleteMessagesDays
|
||||
},
|
||||
undefined,
|
||||
null,
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { Channel } from './channel.ts'
|
||||
import {
|
||||
GuildChannelCategoryPayload,
|
||||
Overwrite
|
||||
} from '../types/channel.ts'
|
||||
import { GuildChannelCategoryPayload, Overwrite } from '../types/channel.ts'
|
||||
import { Guild } from './guild.ts'
|
||||
|
||||
export class CategoryChannel extends Channel {
|
||||
|
@ -15,7 +12,7 @@ export class CategoryChannel extends Channel {
|
|||
guild: Guild
|
||||
parentID?: string
|
||||
|
||||
constructor (client: Client, data: GuildChannelCategoryPayload, guild: Guild) {
|
||||
constructor(client: Client, data: GuildChannelCategoryPayload, guild: Guild) {
|
||||
super(client, data)
|
||||
this.guildID = data.guild_id
|
||||
this.name = data.name
|
||||
|
@ -28,7 +25,7 @@ export class CategoryChannel extends Channel {
|
|||
// cache.set('guildcategorychannel', this.id, this)
|
||||
}
|
||||
|
||||
protected readFromData (data: GuildChannelCategoryPayload): void {
|
||||
protected readFromData(data: GuildChannelCategoryPayload): void {
|
||||
super.readFromData(data)
|
||||
this.guildID = data.guild_id ?? this.guildID
|
||||
this.name = data.name ?? this.name
|
||||
|
|
|
@ -13,7 +13,7 @@ export class NewsChannel extends TextChannel {
|
|||
parentID?: string
|
||||
topic?: string
|
||||
|
||||
constructor (client: Client, data: GuildNewsChannelPayload, guild: Guild) {
|
||||
constructor(client: Client, data: GuildNewsChannelPayload, guild: Guild) {
|
||||
super(client, data)
|
||||
this.guildID = data.guild_id
|
||||
this.name = data.name
|
||||
|
@ -25,7 +25,7 @@ export class NewsChannel extends TextChannel {
|
|||
this.topic = data.topic
|
||||
}
|
||||
|
||||
protected readFromData (data: GuildNewsChannelPayload): void {
|
||||
protected readFromData(data: GuildNewsChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.guildID = data.guild_id ?? this.guildID
|
||||
this.name = data.name ?? this.name
|
||||
|
|
|
@ -14,7 +14,7 @@ export class VoiceChannel extends Channel {
|
|||
nsfw: boolean
|
||||
parentID?: string
|
||||
|
||||
constructor (client: Client, data: GuildVoiceChannelPayload, guild: Guild) {
|
||||
constructor(client: Client, data: GuildVoiceChannelPayload, guild: Guild) {
|
||||
super(client, data)
|
||||
this.bitrate = data.bitrate
|
||||
this.userLimit = data.user_limit
|
||||
|
@ -29,7 +29,7 @@ export class VoiceChannel extends Channel {
|
|||
// cache.set('guildvoicechannel', this.id, this)
|
||||
}
|
||||
|
||||
protected readFromData (data: GuildVoiceChannelPayload): void {
|
||||
protected readFromData(data: GuildVoiceChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.bitrate = data.bitrate ?? this.bitrate
|
||||
this.userLimit = data.user_limit ?? this.userLimit
|
||||
|
|
|
@ -85,7 +85,7 @@ export class Member extends Base {
|
|||
nick: data.nick,
|
||||
roles: data.roles?.map((e) => (typeof e === 'string' ? e : e.id)),
|
||||
deaf: data.deaf,
|
||||
mute: data.mute,
|
||||
mute: data.mute
|
||||
}
|
||||
const res = await this.client.rest.patch(
|
||||
GUILD_MEMBER(this.guild.id, this.id),
|
||||
|
@ -109,7 +109,7 @@ export class Member extends Base {
|
|||
*/
|
||||
async setNickname(nick?: string): Promise<Member> {
|
||||
return await this.edit({
|
||||
nick: nick === undefined ? null : nick,
|
||||
nick: nick === undefined ? null : nick
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ export class Member extends Base {
|
|||
*/
|
||||
async setMute(mute?: boolean): Promise<Member> {
|
||||
return await this.edit({
|
||||
mute: mute === undefined ? false : mute,
|
||||
mute: mute === undefined ? false : mute
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ export class Member extends Base {
|
|||
*/
|
||||
async setDeaf(deaf?: boolean): Promise<Member> {
|
||||
return await this.edit({
|
||||
deaf: deaf === undefined ? false : deaf,
|
||||
deaf: deaf === undefined ? false : deaf
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
MessageApplication,
|
||||
MessageOption,
|
||||
MessagePayload,
|
||||
MessageReference,
|
||||
MessageReference
|
||||
} from '../types/channel.ts'
|
||||
import { Client } from '../models/client.ts'
|
||||
import { User } from './user.ts'
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
ActivityPayload,
|
||||
ClientActivity,
|
||||
ClientStatus,
|
||||
StatusType,
|
||||
StatusType
|
||||
} from '../types/presence.ts'
|
||||
import { PresenceUpdatePayload, StatusUpdatePayload } from '../types/gateway.ts'
|
||||
import { Base } from './base.ts'
|
||||
|
@ -17,7 +17,7 @@ enum ActivityTypes {
|
|||
LISTENING = 2,
|
||||
WATCHING = 3,
|
||||
CUSTOM_STATUS = 4,
|
||||
COMPETING = 5,
|
||||
COMPETING = 5
|
||||
}
|
||||
|
||||
export class Presence extends Base {
|
||||
|
@ -88,7 +88,7 @@ export class ClientPresence {
|
|||
afk: this.afk === undefined ? false : this.afk,
|
||||
activities: this.createActivity(),
|
||||
since: this.since === undefined ? null : this.since,
|
||||
status: this.status === undefined ? 'online' : this.status,
|
||||
status: this.status === undefined ? 'online' : this.status
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { RolePayload } from '../types/role.ts'
|
||||
import { Permissions } from "../utils/permissions.ts"
|
||||
import { Permissions } from '../utils/permissions.ts'
|
||||
|
||||
export class Role extends Base {
|
||||
id: string
|
||||
|
@ -13,13 +13,15 @@ export class Role extends Base {
|
|||
managed: boolean
|
||||
mentionable: boolean
|
||||
|
||||
get mention (): string {
|
||||
get mention(): string {
|
||||
return `<@&${this.id}>`
|
||||
}
|
||||
|
||||
toString(): string { return this.mention }
|
||||
toString(): string {
|
||||
return this.mention
|
||||
}
|
||||
|
||||
constructor (client: Client, data: RolePayload) {
|
||||
constructor(client: Client, data: RolePayload) {
|
||||
super(client, data)
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
|
@ -31,13 +33,16 @@ export class Role extends Base {
|
|||
this.mentionable = data.mentionable
|
||||
}
|
||||
|
||||
protected readFromData (data: RolePayload): void {
|
||||
protected readFromData(data: RolePayload): void {
|
||||
super.readFromData(data)
|
||||
this.name = data.name ?? this.name
|
||||
this.color = data.color ?? this.color
|
||||
this.hoist = data.hoist ?? this.hoist
|
||||
this.position = data.position ?? this.position
|
||||
this.permissions = new Permissions(data.permissions) ?? this.permissions
|
||||
this.permissions =
|
||||
data.permissions !== undefined
|
||||
? new Permissions(data.permissions)
|
||||
: this.permissions
|
||||
this.managed = data.managed ?? this.managed
|
||||
this.mentionable = data.mentionable ?? this.mentionable
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
export class Snowflake {
|
||||
snowflake: bigint
|
||||
constructor (id: string) {
|
||||
constructor(id: string) {
|
||||
this.snowflake = BigInt.asUintN(64, BigInt(id))
|
||||
}
|
||||
|
||||
get timestamp (): string {
|
||||
get timestamp(): string {
|
||||
return ((this.snowflake >> 22n) + 1420070400000n).toString()
|
||||
}
|
||||
|
||||
get workerID (): string {
|
||||
get workerID(): string {
|
||||
return ((this.snowflake & 0x3e0000n) >> 17n).toString()
|
||||
}
|
||||
|
||||
get processID (): string {
|
||||
get processID(): string {
|
||||
return ((this.snowflake & 0x1f00n) >> 12n).toString()
|
||||
}
|
||||
|
||||
get increment (): string {
|
||||
get increment(): string {
|
||||
return (this.snowflake & 0xfffn).toString()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
import { MessagesManager } from "../../mod.ts"
|
||||
import { MessagesManager } from '../managers/messages.ts'
|
||||
import { Client } from '../models/client.ts'
|
||||
import { GuildTextChannelPayload, MessageOption, MessageReference, Overwrite, TextChannelPayload } from '../types/channel.ts'
|
||||
import {
|
||||
GuildTextChannelPayload,
|
||||
MessageOption,
|
||||
MessageReference,
|
||||
Overwrite,
|
||||
TextChannelPayload
|
||||
} from '../types/channel.ts'
|
||||
import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts'
|
||||
import { Channel } from './channel.ts'
|
||||
import { Embed } from './embed.ts'
|
||||
import { Guild } from "./guild.ts"
|
||||
import { Guild } from './guild.ts'
|
||||
import { Message } from './message.ts'
|
||||
|
||||
export type AllMessageOptions = MessageOption | Embed
|
||||
|
@ -33,17 +39,22 @@ export class TextChannel extends Channel {
|
|||
* @param option Various other Message options.
|
||||
* @param reply Reference to a Message object to reply-to.
|
||||
*/
|
||||
async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> {
|
||||
if (typeof text === "object") {
|
||||
async send(
|
||||
text?: string | AllMessageOptions,
|
||||
option?: AllMessageOptions,
|
||||
reply?: Message
|
||||
): Promise<Message> {
|
||||
if (typeof text === 'object') {
|
||||
option = text
|
||||
text = undefined
|
||||
}
|
||||
if (text === undefined && option === undefined) {
|
||||
throw new Error('Either text or option is necessary.')
|
||||
}
|
||||
if (option instanceof Embed) option = {
|
||||
embed: option
|
||||
}
|
||||
if (option instanceof Embed)
|
||||
option = {
|
||||
embed: option
|
||||
}
|
||||
|
||||
const payload: any = {
|
||||
content: text,
|
||||
|
@ -57,7 +68,7 @@ export class TextChannel extends Channel {
|
|||
const reference: MessageReference = {
|
||||
message_id: reply.id,
|
||||
channel_id: reply.channel.id,
|
||||
guild_id: reply.guild?.id,
|
||||
guild_id: reply.guild?.id
|
||||
}
|
||||
payload.message_reference = reference
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { UserPayload } from '../types/user.ts'
|
||||
import { UserFlagsManager } from "../utils/userFlags.ts"
|
||||
import { UserFlagsManager } from '../utils/userFlags.ts'
|
||||
import { Base } from './base.ts'
|
||||
|
||||
export class User extends Base {
|
||||
|
@ -14,7 +14,7 @@ export class User extends Base {
|
|||
locale?: string
|
||||
verified?: boolean
|
||||
email?: string
|
||||
flags?: UserFlagsManager
|
||||
flags: UserFlagsManager
|
||||
/**
|
||||
* Nitro type of the User.
|
||||
*
|
||||
|
@ -23,21 +23,21 @@ export class User extends Base {
|
|||
* 2 = Regular Nitro
|
||||
*/
|
||||
premiumType?: 0 | 1 | 2
|
||||
publicFlags?: UserFlagsManager
|
||||
publicFlags: UserFlagsManager
|
||||
|
||||
get tag (): string {
|
||||
get tag(): string {
|
||||
return `${this.username}#${this.discriminator}`
|
||||
}
|
||||
|
||||
get nickMention (): string {
|
||||
get nickMention(): string {
|
||||
return `<@!${this.id}>`
|
||||
}
|
||||
|
||||
get mention (): string {
|
||||
get mention(): string {
|
||||
return `<@${this.id}>`
|
||||
}
|
||||
|
||||
constructor (client: Client, data: UserPayload) {
|
||||
constructor(client: Client, data: UserPayload) {
|
||||
super(client, data)
|
||||
this.id = data.id
|
||||
this.username = data.username
|
||||
|
@ -54,7 +54,7 @@ export class User extends Base {
|
|||
this.publicFlags = new UserFlagsManager(data.public_flags)
|
||||
}
|
||||
|
||||
protected readFromData (data: UserPayload): void {
|
||||
protected readFromData(data: UserPayload): void {
|
||||
super.readFromData(data)
|
||||
this.username = data.username ?? this.username
|
||||
this.discriminator = data.discriminator ?? this.discriminator
|
||||
|
@ -65,12 +65,16 @@ export class User extends Base {
|
|||
this.locale = data.locale ?? this.locale
|
||||
this.verified = data.verified ?? this.verified
|
||||
this.email = data.email ?? this.email
|
||||
this.flags = new UserFlagsManager(data.flags) ?? this.flags
|
||||
this.flags =
|
||||
data.flags !== undefined ? new UserFlagsManager(data.flags) : this.flags
|
||||
this.premiumType = data.premium_type ?? this.premiumType
|
||||
this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags
|
||||
this.publicFlags =
|
||||
data.public_flags !== undefined
|
||||
? new UserFlagsManager(data.public_flags)
|
||||
: this.publicFlags
|
||||
}
|
||||
|
||||
toString (): string {
|
||||
toString(): string {
|
||||
return this.mention
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { VoiceStatePayload } from '../types/voice.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { Guild } from "./guild.ts"
|
||||
import { VoiceChannel } from "./guildVoiceChannel.ts"
|
||||
import { Member } from "./member.ts"
|
||||
import { User } from "./user.ts"
|
||||
import { Guild } from './guild.ts'
|
||||
import { VoiceChannel } from './guildVoiceChannel.ts'
|
||||
import { Member } from './member.ts'
|
||||
import { User } from './user.ts'
|
||||
|
||||
export class VoiceState extends Base {
|
||||
guild?: Guild
|
||||
|
@ -18,12 +18,16 @@ export class VoiceState extends Base {
|
|||
video: boolean
|
||||
suppress: boolean
|
||||
|
||||
constructor (client: Client, data: VoiceStatePayload, _data: {
|
||||
user: User,
|
||||
channel: VoiceChannel | null,
|
||||
member?: Member,
|
||||
guild?: Guild
|
||||
}) {
|
||||
constructor(
|
||||
client: Client,
|
||||
data: VoiceStatePayload,
|
||||
_data: {
|
||||
user: User
|
||||
channel: VoiceChannel | null
|
||||
member?: Member
|
||||
guild?: Guild
|
||||
}
|
||||
) {
|
||||
super(client, data)
|
||||
this.channel = _data.channel
|
||||
this.sessionID = data.session_id
|
||||
|
@ -39,7 +43,7 @@ export class VoiceState extends Base {
|
|||
this.suppress = data.suppress
|
||||
}
|
||||
|
||||
protected readFromData (data: VoiceStatePayload): void {
|
||||
protected readFromData(data: VoiceStatePayload): void {
|
||||
super.readFromData(data)
|
||||
this.sessionID = data.session_id ?? this.sessionID
|
||||
this.deaf = data.deaf ?? this.deaf
|
||||
|
|
|
@ -45,11 +45,11 @@ export class Webhook {
|
|||
applicationID?: string
|
||||
rest: RESTManager
|
||||
|
||||
get url (): string {
|
||||
get url(): string {
|
||||
return `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${this.id}/${this.token}`
|
||||
}
|
||||
|
||||
constructor (data: WebhookPayload, client?: Client, rest?: RESTManager) {
|
||||
constructor(data: WebhookPayload, client?: Client, rest?: RESTManager) {
|
||||
this.id = data.id
|
||||
this.type = data.type
|
||||
this.channelID = data.channel_id
|
||||
|
@ -70,7 +70,7 @@ export class Webhook {
|
|||
else this.rest = new RESTManager()
|
||||
}
|
||||
|
||||
private fromPayload (data: WebhookPayload): Webhook {
|
||||
private fromPayload(data: WebhookPayload): Webhook {
|
||||
this.id = data.id
|
||||
this.type = data.type
|
||||
this.channelID = data.channel_id
|
||||
|
@ -90,7 +90,7 @@ export class Webhook {
|
|||
}
|
||||
|
||||
/** Send a Message through Webhook. */
|
||||
async send (
|
||||
async send(
|
||||
text?: string | AllWebhookMessageOptions,
|
||||
option?: AllWebhookMessageOptions
|
||||
): Promise<Message> {
|
||||
|
@ -153,7 +153,7 @@ export class Webhook {
|
|||
* @param url URL of the Webhook
|
||||
* @param client Client (bot) object, if any.
|
||||
*/
|
||||
static async fromURL (url: string | URL, client?: Client): Promise<Webhook> {
|
||||
static async fromURL(url: string | URL, client?: Client): Promise<Webhook> {
|
||||
const rest = client !== undefined ? client.rest : new RESTManager()
|
||||
|
||||
const raw = await rest.get(typeof url === 'string' ? url : url.toString())
|
||||
|
@ -168,7 +168,7 @@ export class Webhook {
|
|||
* Edit the Webhook name, avatar, or channel (requires authentication).
|
||||
* @param options Options to edit the Webhook.
|
||||
*/
|
||||
async edit (options: WebhookEditOptions): Promise<Webhook> {
|
||||
async edit(options: WebhookEditOptions): Promise<Webhook> {
|
||||
if (options.channelID !== undefined && this.rest.client === undefined)
|
||||
throw new Error('Authentication is required for editing Webhook Channel')
|
||||
if (
|
||||
|
@ -186,7 +186,7 @@ export class Webhook {
|
|||
}
|
||||
|
||||
/** Delete the Webhook. */
|
||||
async delete (): Promise<boolean> {
|
||||
async delete(): Promise<boolean> {
|
||||
const resp = await this.rest.delete(this.url, undefined, 0, undefined, true)
|
||||
if (resp.response.status !== 204) return false
|
||||
else return true
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
Intents,
|
||||
GuildChannel,
|
||||
CommandContext,
|
||||
Extension,
|
||||
Extension
|
||||
} from '../../mod.ts'
|
||||
import { Invite } from '../structures/invite.ts'
|
||||
import { TOKEN } from './config.ts'
|
||||
|
@ -12,7 +12,7 @@ import { TOKEN } from './config.ts'
|
|||
const client = new CommandClient({
|
||||
prefix: ['pls', '!'],
|
||||
spacesAfterPrefix: true,
|
||||
mentionPrefix: true,
|
||||
mentionPrefix: true
|
||||
})
|
||||
|
||||
client.on('debug', console.log)
|
||||
|
|
|
@ -3,7 +3,7 @@ import { CommandContext } from '../../models/command.ts'
|
|||
|
||||
export default class AddEmojiCommand extends Command {
|
||||
name = 'addemoji'
|
||||
aliases = [ 'ae', 'emojiadd' ]
|
||||
aliases = ['ae', 'emojiadd']
|
||||
args = 2
|
||||
guildOnly = true
|
||||
|
||||
|
@ -12,11 +12,16 @@ export default class AddEmojiCommand extends Command {
|
|||
if (name === undefined) return ctx.message.reply('No name was given!')
|
||||
const url = ctx.argString.slice(name.length).trim()
|
||||
if (url === '') return ctx.message.reply('No URL was given!')
|
||||
ctx.message.guild?.emojis.create(name, url).then(emoji => {
|
||||
ctx.message.guild?.emojis
|
||||
.create(name, url)
|
||||
.then((emoji) => {
|
||||
if (emoji === undefined) throw new Error('Unknown')
|
||||
ctx.message.reply(`Successfuly added emoji ${emoji.toString()} ${emoji.name}!`)
|
||||
}).catch(e => {
|
||||
ctx.message.reply(
|
||||
`Successfuly added emoji ${emoji.toString()} ${emoji.name}!`
|
||||
)
|
||||
})
|
||||
.catch((e) => {
|
||||
ctx.message.reply(`Failed to add emoji. Reason: ${e.message}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
|
@ -2,16 +2,34 @@ import { Command, Embed } from '../../../mod.ts'
|
|||
import { CommandContext } from '../../models/command.ts'
|
||||
|
||||
export default class PingCommand extends Command {
|
||||
name = "mentions"
|
||||
aliases = ["m"]
|
||||
name = 'mentions'
|
||||
aliases = ['m']
|
||||
|
||||
execute(ctx: CommandContext): void {
|
||||
const embed = new Embed()
|
||||
.setTitle('Mentions')
|
||||
.addField('Users', `${ctx.message.mentions.users.size === 0 ? `None` : ''}${ctx.message.mentions.users.map(u => u.toString()).join(", ")}`)
|
||||
.addField('Channels', `${ctx.message.mentions.channels.size === 0 ? `None` : ''}${ctx.message.mentions.channels.map(u => u.toString()).join(", ")}`)
|
||||
.addField('Roles', `${ctx.message.mentions.roles.size === 0 ? `None` : ''}${ctx.message.mentions.roles.map(u => u.toString()).join(", ")}`)
|
||||
.addField('Everyone?', ctx.message.mentions.everyone === true ? 'Yes' : 'No')
|
||||
.addField(
|
||||
'Users',
|
||||
`${
|
||||
ctx.message.mentions.users.size === 0 ? `None` : ''
|
||||
}${ctx.message.mentions.users.map((u) => u.toString()).join(', ')}`
|
||||
)
|
||||
.addField(
|
||||
'Channels',
|
||||
`${
|
||||
ctx.message.mentions.channels.size === 0 ? `None` : ''
|
||||
}${ctx.message.mentions.channels.map((u) => u.toString()).join(', ')}`
|
||||
)
|
||||
.addField(
|
||||
'Roles',
|
||||
`${
|
||||
ctx.message.mentions.roles.size === 0 ? `None` : ''
|
||||
}${ctx.message.mentions.roles.map((u) => u.toString()).join(', ')}`
|
||||
)
|
||||
.addField(
|
||||
'Everyone?',
|
||||
ctx.message.mentions.everyone === true ? 'Yes' : 'No'
|
||||
)
|
||||
.setColor(0xff0000)
|
||||
ctx.message.channel.send(embed)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Command } from '../../../mod.ts'
|
|||
import { CommandContext } from '../../models/command.ts'
|
||||
|
||||
export default class PingCommand extends Command {
|
||||
name = "ping"
|
||||
name = 'ping'
|
||||
|
||||
execute(ctx: CommandContext): void {
|
||||
ctx.message.reply(`Pong! Latency: ${ctx.client.ping}ms`)
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
import { Command, Member, CommandContext, Embed } from '../../../mod.ts'
|
||||
|
||||
export default class UserinfoCommand extends Command {
|
||||
name = "userinfo"
|
||||
guildOnly = true
|
||||
aliases = [ 'u', 'user' ]
|
||||
name = 'userinfo'
|
||||
guildOnly = true
|
||||
aliases = ['u', 'user']
|
||||
|
||||
async execute(ctx: CommandContext): Promise<void> {
|
||||
const member: Member = ctx.message.member as any
|
||||
const roles = await member.roles.array()
|
||||
const embed = new Embed()
|
||||
.setTitle(`User Info`)
|
||||
.setAuthor({ name: member.user.tag })
|
||||
.addField("ID", member.id)
|
||||
.addField("Roles", roles.map(r => r.name).join(", "))
|
||||
.addField('Permissions', JSON.stringify(member.permissions.has('ADMINISTRATOR')))
|
||||
.setColor(0xff00ff)
|
||||
ctx.channel.send(embed)
|
||||
}
|
||||
async execute(ctx: CommandContext): Promise<void> {
|
||||
const member: Member = ctx.message.member as any
|
||||
const roles = await member.roles.array()
|
||||
const embed = new Embed()
|
||||
.setTitle(`User Info`)
|
||||
.setAuthor({ name: member.user.tag })
|
||||
.addField('ID', member.id)
|
||||
.addField('Roles', roles.map((r) => r.name).join(', '))
|
||||
.addField(
|
||||
'Permissions',
|
||||
JSON.stringify(member.permissions.has('ADMINISTRATOR'))
|
||||
)
|
||||
.setColor(0xff00ff)
|
||||
ctx.channel.send(embed)
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import { Webhook } from '../../mod.ts'
|
||||
import { WEBHOOK } from "./config.ts"
|
||||
import { WEBHOOK } from './config.ts'
|
||||
|
||||
const webhook = await Webhook.fromURL(WEBHOOK)
|
||||
console.log('Fetched webhook!')
|
||||
|
||||
webhook.send('Hello World', {
|
||||
name: 'OwO'
|
||||
}).then(() => 'Sent message!')
|
||||
webhook
|
||||
.send('Hello World', {
|
||||
name: 'OwO'
|
||||
})
|
||||
.then(() => 'Sent message!')
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
import { Client, Intents, GuildTextChannel, Message, ClientPresence, Member, Role, GuildChannel, Embed, Guild } from '../../mod.ts'
|
||||
import {
|
||||
Client,
|
||||
Intents,
|
||||
Message,
|
||||
ClientPresence,
|
||||
Member,
|
||||
Role,
|
||||
GuildChannel,
|
||||
Embed,
|
||||
Guild,
|
||||
EveryChannelTypes,
|
||||
ChannelTypes,
|
||||
GuildTextChannel
|
||||
} from '../../mod.ts'
|
||||
import { TOKEN } from './config.ts'
|
||||
|
||||
const client = new Client({
|
||||
presence: new ClientPresence({
|
||||
name: 'Pokémon Sword',
|
||||
type: 'COMPETING'
|
||||
}),
|
||||
name: 'Pokémon Sword',
|
||||
type: 'COMPETING'
|
||||
})
|
||||
// bot: false,
|
||||
// cache: new RedisCacheAdapter({
|
||||
// hostname: '127.0.0.1',
|
||||
|
@ -19,13 +32,19 @@ client.on('ready', () => {
|
|||
|
||||
client.on('debug', console.log)
|
||||
|
||||
client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) => {
|
||||
console.log(before.send('', {
|
||||
embed: new Embed({
|
||||
title: 'Channel Update',
|
||||
description: `Name Before: ${before.name}\nName After: ${after.name}`
|
||||
})
|
||||
}))
|
||||
client.on('channelUpdate', (b: EveryChannelTypes, a: EveryChannelTypes) => {
|
||||
if (b.type === ChannelTypes.GUILD_TEXT) {
|
||||
const before = (b as unknown) as GuildTextChannel
|
||||
const after = (a as unknown) as GuildTextChannel
|
||||
console.log(
|
||||
before.send('', {
|
||||
embed: new Embed({
|
||||
title: 'Channel Update',
|
||||
description: `Name Before: ${before.name}\nName After: ${after.name}`
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
client.on('messageCreate', async (msg: Message) => {
|
||||
|
@ -35,26 +54,40 @@ client.on('messageCreate', async (msg: Message) => {
|
|||
msg.reply(`Pong! Ping: ${client.ping}ms`)
|
||||
} else if (msg.content === '!members') {
|
||||
const col = await msg.guild?.members.collection()
|
||||
const data = col?.array().map((c: Member, i: number) => {
|
||||
return `${i + 1}. ${c.user.tag}`
|
||||
}).join("\n") as string
|
||||
msg.channel.send("Member List:\n" + data)
|
||||
const data = col
|
||||
?.array()
|
||||
.map((c: Member, i: number) => {
|
||||
return `${i + 1}. ${c.user.tag}`
|
||||
})
|
||||
.join('\n') as string
|
||||
msg.channel.send('Member List:\n' + data)
|
||||
} else if (msg.content === '!guilds') {
|
||||
const guilds = await msg.client.guilds.collection()
|
||||
msg.channel.send('Guild List:\n' + (guilds.array().map((c: Guild, i: number) => {
|
||||
return `${i + 1}. ${c.name} - ${c.memberCount} members`
|
||||
}).join("\n") as string))
|
||||
msg.channel.send(
|
||||
'Guild List:\n' +
|
||||
(guilds
|
||||
.array()
|
||||
.map((c: Guild, i: number) => {
|
||||
return `${i + 1}. ${c.name} - ${c.memberCount} members`
|
||||
})
|
||||
.join('\n') as string)
|
||||
)
|
||||
} else if (msg.content === '!roles') {
|
||||
const col = await msg.guild?.roles.collection()
|
||||
const data = col?.array().map((c: Role, i: number) => {
|
||||
return `${i + 1}. ${c.name}`
|
||||
}).join("\n") as string
|
||||
msg.channel.send("Roles List:\n" + data)
|
||||
const data = col
|
||||
?.array()
|
||||
.map((c: Role, i: number) => {
|
||||
return `${i + 1}. ${c.name}`
|
||||
})
|
||||
.join('\n') as string
|
||||
msg.channel.send('Roles List:\n' + data)
|
||||
} else if (msg.content === '!channels') {
|
||||
const col = await msg.guild?.channels.array()
|
||||
const data = col?.map((c: GuildChannel, i: number) => {
|
||||
return `${i + 1}. ${c.name}`
|
||||
}).join("\n") as string
|
||||
const data = col
|
||||
?.map((c: GuildChannel, i: number) => {
|
||||
return `${i + 1}. ${c.name}`
|
||||
})
|
||||
.join('\n') as string
|
||||
msg.channel.send('Channels List:\n' + data)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { UserPayload } from "./user.ts";
|
||||
import { UserPayload } from './user.ts'
|
||||
|
||||
export interface ApplicationPayload {
|
||||
id: string
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048
|
||||
export type ImageFormats = "jpg" | "jpeg" | "png" | "webp" | "gif"
|
||||
export type ImageFormats = 'jpg' | 'jpeg' | 'png' | 'webp' | 'gif'
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
ActivityGame,
|
||||
ActivityPayload,
|
||||
StatusType,
|
||||
ClientStatus,
|
||||
ClientStatus
|
||||
} from './presence.ts'
|
||||
import { RolePayload } from './role.ts'
|
||||
import { UserPayload } from './user.ts'
|
||||
|
@ -27,7 +27,7 @@ export enum GatewayOpcodes { // 문서를 확인해본 결과 Opcode 5번은 비
|
|||
REQUEST_GUILD_MEMBERS = 8,
|
||||
INVALID_SESSION = 9,
|
||||
HELLO = 10,
|
||||
HEARTBEAT_ACK = 11,
|
||||
HEARTBEAT_ACK = 11
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ export enum GatewayCloseCodes {
|
|||
SHARDING_REQUIRED = 4011,
|
||||
INVALID_API_VERSION = 4012,
|
||||
INVALID_INTENTS = 4013,
|
||||
DISALLOWED_INTENTS = 4014,
|
||||
DISALLOWED_INTENTS = 4014
|
||||
}
|
||||
|
||||
export enum GatewayIntents {
|
||||
|
@ -65,7 +65,7 @@ export enum GatewayIntents {
|
|||
GUILD_MESSAGE_TYPING = 1 << 11,
|
||||
DIRECT_MESSAGES = 1 << 12,
|
||||
DIRECT_MESSAGE_REACTIONS = 1 << 13,
|
||||
DIRECT_MESSAGE_TYPING = 1 << 13,
|
||||
DIRECT_MESSAGE_TYPING = 1 << 13
|
||||
}
|
||||
|
||||
export enum GatewayEvents {
|
||||
|
@ -105,7 +105,7 @@ export enum GatewayEvents {
|
|||
User_Update = 'USER_UPDATE',
|
||||
Voice_Server_Update = 'VOICE_SERVER_UPDATE',
|
||||
Voice_State_Update = 'VOICE_STATE_UPDATE',
|
||||
Webhooks_Update = 'WEBHOOKS_UPDATE',
|
||||
Webhooks_Update = 'WEBHOOKS_UPDATE'
|
||||
}
|
||||
|
||||
export interface IdentityPayload {
|
||||
|
|
|
@ -66,18 +66,18 @@ export interface MemberPayload {
|
|||
|
||||
export enum MessageNotification {
|
||||
ALL_MESSAGES = 0,
|
||||
ONLY_MENTIONS = 1,
|
||||
ONLY_MENTIONS = 1
|
||||
}
|
||||
|
||||
export enum ContentFilter {
|
||||
DISABLED = 0,
|
||||
MEMBERS_WITHOUT_ROLES = 1,
|
||||
ALL_MEMBERS = 3,
|
||||
ALL_MEMBERS = 3
|
||||
}
|
||||
|
||||
export enum MFA {
|
||||
NONE = 0,
|
||||
ELEVATED = 1,
|
||||
ELEVATED = 1
|
||||
}
|
||||
|
||||
export enum Verification {
|
||||
|
@ -85,19 +85,19 @@ export enum Verification {
|
|||
LOW = 1,
|
||||
MEDIUM = 2,
|
||||
HIGH = 3,
|
||||
VERY_HIGH = 4,
|
||||
VERY_HIGH = 4
|
||||
}
|
||||
|
||||
export enum PremiumTier {
|
||||
NONE = 0,
|
||||
TIER_1 = 1,
|
||||
TIER_2 = 2,
|
||||
TIER_3 = 3,
|
||||
TIER_3 = 3
|
||||
}
|
||||
|
||||
export enum SystemChannelFlags {
|
||||
SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0,
|
||||
SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1,
|
||||
SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
|
||||
}
|
||||
|
||||
export type GuildFeatures =
|
||||
|
@ -116,7 +116,7 @@ export type GuildFeatures =
|
|||
|
||||
export enum IntegrationExpireBehavior {
|
||||
REMOVE_ROLE = 0,
|
||||
KICK = 1,
|
||||
KICK = 1
|
||||
}
|
||||
|
||||
export interface IntegrationAccountPayload {
|
||||
|
|
|
@ -31,5 +31,5 @@ export const PermissionFlags: { [key: string]: number } = {
|
|||
MANAGE_NICKNAMES: 1 << 27,
|
||||
MANAGE_ROLES: 1 << 28,
|
||||
MANAGE_WEBHOOKS: 1 << 29,
|
||||
MANAGE_EMOJIS: 1 << 30,
|
||||
MANAGE_EMOJIS: 1 << 30
|
||||
}
|
|
@ -56,7 +56,7 @@ export enum ActivityFlags {
|
|||
SPECTATE = 1 << 2,
|
||||
JOIN_REQUEST = 1 << 3,
|
||||
SYNC = 1 << 4,
|
||||
PLAY = 1 << 5,
|
||||
PLAY = 1 << 5
|
||||
}
|
||||
|
||||
export type ActivityType =
|
||||
|
|
|
@ -19,12 +19,13 @@ export class BitField {
|
|||
}
|
||||
|
||||
has(bit: BitFieldResolvable, ...args: any[]): boolean {
|
||||
if (Array.isArray(bit)) return bit.every(p => this.has(p))
|
||||
if (Array.isArray(bit)) return bit.every((p) => this.has(p))
|
||||
return (this.bitfield & BitField.resolve(this.flags, bit)) === bit
|
||||
}
|
||||
|
||||
missing(bits: any, ...hasParams: any[]): string[] {
|
||||
if (!Array.isArray(bits)) bits = new BitField(this.flags, bits).toArray(false)
|
||||
if (!Array.isArray(bits))
|
||||
bits = new BitField(this.flags, bits).toArray(false)
|
||||
return bits.filter((p: any) => !this.has(p, ...hasParams))
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,8 @@ export class BitField {
|
|||
for (const bit of bits) {
|
||||
total |= BitField.resolve(this.flags, bit)
|
||||
}
|
||||
if (Object.isFrozen(this)) return new BitField(this.flags, this.bitfield | total)
|
||||
if (Object.isFrozen(this))
|
||||
return new BitField(this.flags, this.bitfield | total)
|
||||
this.bitfield |= total
|
||||
return this
|
||||
}
|
||||
|
@ -47,19 +49,26 @@ export class BitField {
|
|||
for (const bit of bits) {
|
||||
total |= BitField.resolve(this.flags, bit)
|
||||
}
|
||||
if (Object.isFrozen(this)) return new BitField(this.flags, this.bitfield & ~total)
|
||||
if (Object.isFrozen(this))
|
||||
return new BitField(this.flags, this.bitfield & ~total)
|
||||
this.bitfield &= ~total
|
||||
return this
|
||||
}
|
||||
|
||||
serialize(...hasParams: any[]): { [key: string]: any } {
|
||||
const serialized: { [key: string]: any } = {}
|
||||
for (const [flag, bit] of Object.entries(this.flags)) serialized[flag] = this.has(BitField.resolve(this.flags, bit), ...hasParams)
|
||||
for (const [flag, bit] of Object.entries(this.flags))
|
||||
serialized[flag] = this.has(
|
||||
BitField.resolve(this.flags, bit),
|
||||
...hasParams
|
||||
)
|
||||
return serialized
|
||||
}
|
||||
|
||||
toArray(...hasParams: any[]): string[] {
|
||||
return Object.keys(this.flags).filter(bit => this.has(BitField.resolve(this.flags, bit), ...hasParams))
|
||||
return Object.keys(this.flags).filter((bit) =>
|
||||
this.has(BitField.resolve(this.flags, bit), ...hasParams)
|
||||
)
|
||||
}
|
||||
|
||||
toJSON(): number {
|
||||
|
@ -78,8 +87,12 @@ export class BitField {
|
|||
if (typeof bit === 'string' && !isNaN(parseInt(bit))) return parseInt(bit)
|
||||
if (typeof bit === 'number' && bit >= 0) return bit
|
||||
if (bit instanceof BitField) return this.resolve(flags, bit.bitfield)
|
||||
if (Array.isArray(bit)) return bit.map(p => this.resolve(flags, p)).reduce((prev, p) => prev | p, 0)
|
||||
if (typeof bit === 'string' && typeof flags[bit] !== 'undefined') return flags[bit]
|
||||
if (Array.isArray(bit))
|
||||
return bit
|
||||
.map((p) => this.resolve(flags, p))
|
||||
.reduce((prev, p) => prev | p, 0)
|
||||
if (typeof bit === 'string' && typeof flags[bit] !== 'undefined')
|
||||
return flags[bit]
|
||||
const error = new RangeError('BITFIELD_INVALID')
|
||||
throw error
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ export class Collection<K = string, V = any> extends Map<K, V> {
|
|||
|
||||
reduce<T>(
|
||||
callback: (accumulator: T, value: V, key: K) => T,
|
||||
initialValue?: T,
|
||||
initialValue?: T
|
||||
): T {
|
||||
let accumulator: T = initialValue as T
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export const delay = async (ms: number): Promise<true> => await new Promise((resolve, reject) => {
|
||||
setTimeout(() => resolve(true), ms);
|
||||
});
|
||||
export const delay = async (ms: number): Promise<true> =>
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => resolve(true), ms)
|
||||
})
|
||||
|
|
|
@ -7,7 +7,8 @@ import {
|
|||
GuildChannelCategoryPayload,
|
||||
GuildNewsChannelPayload,
|
||||
GuildTextChannelPayload,
|
||||
GuildVoiceChannelPayload
|
||||
GuildVoiceChannelPayload,
|
||||
TextChannelPayload
|
||||
} from '../types/channel.ts'
|
||||
import { DMChannel } from '../structures/dmChannel.ts'
|
||||
import { GroupDMChannel } from '../structures/groupChannel.ts'
|
||||
|
@ -15,39 +16,64 @@ import { CategoryChannel } from '../structures/guildCategoryChannel.ts'
|
|||
import { NewsChannel } from '../structures/guildNewsChannel.ts'
|
||||
import { VoiceChannel } from '../structures/guildVoiceChannel.ts'
|
||||
import { Guild } from '../structures/guild.ts'
|
||||
import { TextChannel, GuildTextChannel } from '../structures/textChannel.ts'
|
||||
import { GuildTextChannel, TextChannel } from '../structures/textChannel.ts'
|
||||
import { Channel } from '../structures/channel.ts'
|
||||
|
||||
export type EveryTextChannelTypes =
|
||||
| TextChannel
|
||||
| NewsChannel
|
||||
| GuildTextChannel
|
||||
| DMChannel
|
||||
| GroupDMChannel
|
||||
|
||||
export type EveryTextChannelPayloadTypes =
|
||||
| TextChannelPayload
|
||||
| GuildNewsChannelPayload
|
||||
| GuildTextChannelPayload
|
||||
| DMChannelPayload
|
||||
| GroupDMChannelPayload
|
||||
|
||||
export type EveryChannelTypes =
|
||||
| Channel
|
||||
| CategoryChannel
|
||||
| VoiceChannel
|
||||
| EveryTextChannelTypes
|
||||
|
||||
export type EveryChannelPayloadTypes =
|
||||
| ChannelPayload
|
||||
| GuildChannelCategoryPayload
|
||||
| GuildVoiceChannelPayload
|
||||
| EveryTextChannelPayloadTypes
|
||||
|
||||
const getChannelByType = (
|
||||
client: Client,
|
||||
data:
|
||||
| GuildChannelCategoryPayload
|
||||
| GuildNewsChannelPayload
|
||||
| GuildTextChannelPayload
|
||||
| GuildVoiceChannelPayload
|
||||
| DMChannelPayload
|
||||
| GroupDMChannelPayload
|
||||
| ChannelPayload,
|
||||
data: EveryChannelPayloadTypes,
|
||||
guild?: Guild
|
||||
):
|
||||
| CategoryChannel
|
||||
| NewsChannel
|
||||
| TextChannel
|
||||
| VoiceChannel
|
||||
| DMChannel
|
||||
| GroupDMChannel
|
||||
| undefined => {
|
||||
): EveryChannelTypes | undefined => {
|
||||
switch (data.type) {
|
||||
case ChannelTypes.GUILD_CATEGORY:
|
||||
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||
return new CategoryChannel(client, data as GuildChannelCategoryPayload, guild)
|
||||
if (guild === undefined)
|
||||
throw new Error('No Guild was provided to construct Channel')
|
||||
return new CategoryChannel(
|
||||
client,
|
||||
data as GuildChannelCategoryPayload,
|
||||
guild
|
||||
)
|
||||
case ChannelTypes.GUILD_NEWS:
|
||||
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||
if (guild === undefined)
|
||||
throw new Error('No Guild was provided to construct Channel')
|
||||
return new NewsChannel(client, data as GuildNewsChannelPayload, guild)
|
||||
case ChannelTypes.GUILD_TEXT:
|
||||
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||
return new GuildTextChannel(client, data as GuildTextChannelPayload, guild)
|
||||
if (guild === undefined)
|
||||
throw new Error('No Guild was provided to construct Channel')
|
||||
return new GuildTextChannel(
|
||||
client,
|
||||
data as GuildTextChannelPayload,
|
||||
guild
|
||||
)
|
||||
case ChannelTypes.GUILD_VOICE:
|
||||
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||
if (guild === undefined)
|
||||
throw new Error('No Guild was provided to construct Channel')
|
||||
return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild)
|
||||
case ChannelTypes.DM:
|
||||
return new DMChannel(client, data as DMChannelPayload)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export { default as getChannelByType } from './getChannelByType.ts'
|
||||
export type AnyFunction<ReturnType = any> = (...args:any[]) => ReturnType;
|
||||
export type AnyFunction<ReturnType = any> = (...args: any[]) => ReturnType
|
||||
export { delay } from './delay.ts'
|
|
@ -36,22 +36,23 @@ export class Intents {
|
|||
...Intents.NonPriviliged
|
||||
]
|
||||
|
||||
static None: number[] = [
|
||||
...Intents.NonPriviliged
|
||||
]
|
||||
static None: number[] = [...Intents.NonPriviliged]
|
||||
|
||||
static create(priviliged?: PriviligedIntents[], disable?: number[]): number[] {
|
||||
let intents: number[] = [
|
||||
...Intents.NonPriviliged
|
||||
]
|
||||
static create(
|
||||
priviliged?: PriviligedIntents[],
|
||||
disable?: number[]
|
||||
): number[] {
|
||||
let intents: number[] = [...Intents.NonPriviliged]
|
||||
|
||||
if (priviliged !== undefined && priviliged.length !== 0) {
|
||||
if (priviliged.includes('GUILD_MEMBERS')) intents.push(GatewayIntents.GUILD_MEMBERS)
|
||||
if (priviliged.includes('GUILD_PRESENCES')) intents.push(GatewayIntents.GUILD_PRESENCES)
|
||||
if (priviliged.includes('GUILD_MEMBERS'))
|
||||
intents.push(GatewayIntents.GUILD_MEMBERS)
|
||||
if (priviliged.includes('GUILD_PRESENCES'))
|
||||
intents.push(GatewayIntents.GUILD_PRESENCES)
|
||||
}
|
||||
|
||||
if (disable !== undefined) {
|
||||
intents = intents.filter(intent => !disable.includes(intent))
|
||||
intents = intents.filter((intent) => !disable.includes(intent))
|
||||
}
|
||||
|
||||
return intents
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export const awaitSync = async(val: any | Promise<any>): Promise<any> => {
|
||||
return val instanceof Promise ? await val : val
|
||||
export const awaitSync = async (val: any | Promise<any>): Promise<any> => {
|
||||
return val instanceof Promise ? await val : val
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
// Ported from https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
|
||||
import { PermissionFlags } from "../types/permissionFlags.ts"
|
||||
import { BitField } from "./bitfield.ts"
|
||||
import { PermissionFlags } from '../types/permissionFlags.ts'
|
||||
import { BitField } from './bitfield.ts'
|
||||
|
||||
export type PermissionResolvable = string | number | Permissions | PermissionResolvable[]
|
||||
export type PermissionResolvable =
|
||||
| string
|
||||
| number
|
||||
| Permissions
|
||||
| PermissionResolvable[]
|
||||
|
||||
export class Permissions extends BitField {
|
||||
static DEFAULT = 104324673
|
||||
|
@ -13,10 +17,16 @@ export class Permissions extends BitField {
|
|||
}
|
||||
|
||||
any(permission: PermissionResolvable, checkAdmin = true): boolean {
|
||||
return (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || super.any(permission as any)
|
||||
return (
|
||||
(checkAdmin && super.has(this.flags.ADMINISTRATOR)) ||
|
||||
super.any(permission as any)
|
||||
)
|
||||
}
|
||||
|
||||
has(permission: PermissionResolvable, checkAdmin = true): boolean {
|
||||
return (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || super.has(permission as any)
|
||||
return (
|
||||
(checkAdmin && super.has(this.flags.ADMINISTRATOR)) ||
|
||||
super.has(permission as any)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { UserFlags } from "../types/userFlags.ts";
|
||||
import { BitField } from "./bitfield.ts";
|
||||
import { UserFlags } from '../types/userFlags.ts'
|
||||
import { BitField } from './bitfield.ts'
|
||||
|
||||
export class UserFlagsManager extends BitField {
|
||||
constructor(bits: any) {
|
||||
super(UserFlags, bits)
|
||||
}
|
||||
constructor(bits: any) {
|
||||
super(UserFlags, bits)
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@
|
|||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
/* Experimental Options */
|
||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
||||
"emitDecoratorMetadata": false /* Enables experimental support for emitting type metadata for decorators. */,
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true,
|
||||
|
|
Loading…
Reference in New Issue