Fixed 173 Lint Errors
This commit is contained in:
parent
9b37e185b0
commit
0fed83cb2d
27 changed files with 228 additions and 205 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
|
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
|
||||||
|
|
||||||
Discord Deno API that is easy to use
|
An easy to use Discord API Library for Deno
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ Not made yet
|
||||||
|
|
||||||
See [the contributing file](CONTRIBUTING.md)!
|
See [the contributing file](CONTRIBUTING.md)!
|
||||||
|
|
||||||
PRs accepted.
|
PRs are accepted.
|
||||||
|
|
||||||
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
|
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT © 2020 Helloyunho
|
[MIT © 2020 Helloyunho](LICENSE)
|
||||||
|
|
56
mod.ts
Normal file
56
mod.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
export * from './src/gateway/index.ts'
|
||||||
|
export * from './src/models/client.ts'
|
||||||
|
export * from './src/models/rest.ts'
|
||||||
|
export * from './src/models/CacheAdapter.ts'
|
||||||
|
export * from './src/models/shard.ts'
|
||||||
|
export * from './src/managers/BaseManager.ts'
|
||||||
|
export * from './src/managers/BaseChildManager.ts'
|
||||||
|
export * from './src/managers/ChannelsManager.ts'
|
||||||
|
export * from './src/managers/EmojisManager.ts'
|
||||||
|
export * from './src/managers/GatewayCache.ts'
|
||||||
|
export * from './src/managers/GuildChannelsManager.ts'
|
||||||
|
export * from './src/managers/GuildsManager.ts'
|
||||||
|
export * from './src/managers/MembersManager.ts'
|
||||||
|
export * from './src/managers/MessagesManager.ts'
|
||||||
|
export * from './src/managers/RolesManager.ts'
|
||||||
|
export * from './src/managers/UsersManager.ts'
|
||||||
|
export * from './src/structures/base.ts'
|
||||||
|
export * from './src/structures/cdn.ts'
|
||||||
|
export * from './src/structures/channel.ts'
|
||||||
|
export * from './src/structures/dmChannel.ts'
|
||||||
|
export * from './src/structures/embed.ts'
|
||||||
|
export * from './src/structures/emoji.ts'
|
||||||
|
export * from './src/structures/groupChannel.ts'
|
||||||
|
export * from './src/structures/guild.ts'
|
||||||
|
export * from './src/structures/guildCategoryChannel.ts'
|
||||||
|
export * from './src/structures/guildNewsChannel.ts'
|
||||||
|
export * from './src/structures/guildTextChannel.ts'
|
||||||
|
export * from './src/structures/guildVoiceChannel.ts'
|
||||||
|
export * from './src/structures/invite.ts'
|
||||||
|
export * from './src/structures/member.ts'
|
||||||
|
export * from './src/structures/message.ts'
|
||||||
|
export * from './src/structures/MessageMentions.ts'
|
||||||
|
export * from './src/structures/presence.ts'
|
||||||
|
export * from './src/structures/role.ts'
|
||||||
|
export * from './src/structures/snowflake.ts'
|
||||||
|
export * from './src/structures/textChannel.ts'
|
||||||
|
export * from './src/structures/user.ts'
|
||||||
|
export * from './src/structures/voicestate.ts'
|
||||||
|
export * from './src/structures/webhook.ts'
|
||||||
|
export * from './src/types/cdn.ts'
|
||||||
|
export * from './src/types/channel.ts'
|
||||||
|
export * from './src/types/emoji.ts'
|
||||||
|
export * from './src/types/endpoint.ts'
|
||||||
|
export * from './src/types/gateway.ts'
|
||||||
|
export * from './src/types/gatewayBot.ts'
|
||||||
|
export * from './src/types/gatewayResponse.ts'
|
||||||
|
export * from './src/types/guild.ts'
|
||||||
|
export * from './src/types/invite.ts'
|
||||||
|
export * from './src/types/permissionFlags.ts'
|
||||||
|
export * from './src/types/presence.ts'
|
||||||
|
export * from './src/types/role.ts'
|
||||||
|
export * from './src/types/template.ts'
|
||||||
|
export * from './src/types/user.ts'
|
||||||
|
export * from './src/types/voice.ts'
|
||||||
|
export * from './src/types/webhook.ts'
|
||||||
|
export * from './src/utils/collection.ts'
|
|
@ -1,4 +1,3 @@
|
||||||
import { GuildChannelPayload } from "../../managers/GuildChannelsManager.ts"
|
|
||||||
import { Channel } from '../../structures/channel.ts'
|
import { Channel } from '../../structures/channel.ts'
|
||||||
import { Guild } from "../../structures/guild.ts"
|
import { Guild } from "../../structures/guild.ts"
|
||||||
import { ChannelPayload } from '../../types/channel.ts'
|
import { ChannelPayload } from '../../types/channel.ts'
|
||||||
|
@ -9,13 +8,13 @@ export const channelUpdate: GatewayEventHandler = async (
|
||||||
gateway: Gateway,
|
gateway: Gateway,
|
||||||
d: ChannelPayload
|
d: ChannelPayload
|
||||||
) => {
|
) => {
|
||||||
const oldChannel: Channel | void = await gateway.client.channels.get(d.id)
|
const oldChannel: Channel | undefined = await gateway.client.channels.get(d.id)
|
||||||
|
|
||||||
if (oldChannel !== undefined) {
|
if (oldChannel !== undefined) {
|
||||||
await gateway.client.channels.set(d.id, d)
|
await gateway.client.channels.set(d.id, d)
|
||||||
let guild: undefined | Guild;
|
let guild: undefined | Guild;
|
||||||
if((d as GuildChannelPayload).guild_id) {
|
if((d as any).guild_id !== undefined) {
|
||||||
guild = await gateway.client.guilds.get((d as GuildChannelPayload).guild_id) || undefined
|
guild = await gateway.client.guilds.get((d as any).guild_id) as Guild | undefined
|
||||||
}
|
}
|
||||||
if (oldChannel.type !== d.type) {
|
if (oldChannel.type !== d.type) {
|
||||||
const channel: Channel = getChannelByType(gateway.client, d, guild) ?? oldChannel
|
const channel: Channel = getChannelByType(gateway.client, d, guild) ?? oldChannel
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
import { Guild } from '../../structures/guild.ts'
|
import { Guild } from '../../structures/guild.ts'
|
||||||
import { User } from '../../structures/user.ts'
|
import { User } from '../../structures/user.ts'
|
||||||
import { GuildBanAddPayload } from '../../types/gateway.ts'
|
import { GuildBanAddPayload } from '../../types/gateway.ts'
|
||||||
import { Member } from "../../structures/member.ts"
|
|
||||||
|
|
||||||
export const guildBanAdd: GatewayEventHandler = async (
|
export const guildBanAdd: GatewayEventHandler = async (
|
||||||
gateway: Gateway,
|
gateway: Gateway,
|
||||||
|
|
|
@ -11,39 +11,40 @@ export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: Guild
|
||||||
if (guild !== undefined) {
|
if (guild !== undefined) {
|
||||||
// It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in
|
// It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in
|
||||||
await gateway.client.guilds.set(d.id, d)
|
await gateway.client.guilds.set(d.id, d)
|
||||||
if((d as GuildPayload).members) {
|
if((d as any).members !== undefined) {
|
||||||
let members = new MembersManager(gateway.client, guild)
|
const members = new MembersManager(gateway.client, guild)
|
||||||
await members.fromPayload((d as GuildPayload).members as MemberPayload[])
|
await members.fromPayload((d as any).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
}
|
}
|
||||||
if((d as GuildPayload).channels) {
|
if((d as any).channels !== undefined) {
|
||||||
for (let ch of (d as GuildPayload).channels as ChannelPayload[]) {
|
for (const ch of (d as any).channels as ChannelPayload[]) {
|
||||||
(ch as any).guild_id = d.id
|
(ch as any).guild_id = d.id
|
||||||
await gateway.client.channels.set(ch.id, ch)
|
await gateway.client.channels.set(ch.id, ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((d as GuildPayload).roles) {
|
if((d as any).roles !== undefined) {
|
||||||
let roles = new RolesManager(gateway.client, guild)
|
const roles = new RolesManager(gateway.client, guild)
|
||||||
await roles.fromPayload((d as GuildPayload).roles as RolePayload[])
|
await roles.fromPayload((d as any).roles as RolePayload[])
|
||||||
guild.roles = roles
|
guild.roles = roles
|
||||||
}
|
}
|
||||||
guild.refreshFromData(d)
|
guild.refreshFromData(d)
|
||||||
} else {
|
} else {
|
||||||
await gateway.client.guilds.set(d.id, d)
|
await gateway.client.guilds.set(d.id, d)
|
||||||
guild = new Guild(gateway.client, d as GuildPayload)
|
guild = new Guild(gateway.client, d)
|
||||||
if((d as GuildPayload).members) {
|
if((d as any).members !== undefined) {
|
||||||
let members = new MembersManager(gateway.client, guild)
|
const members = new MembersManager(gateway.client, guild)
|
||||||
await members.fromPayload((d as GuildPayload).members as MemberPayload[])
|
await members.fromPayload((d as any).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
}
|
}
|
||||||
if((d as GuildPayload).channels) {
|
if((d as any).channels !== undefined) {
|
||||||
for (let ch of (d as GuildPayload).channels as ChannelPayload[]) {
|
for (const ch of (d as any).channels as ChannelPayload[]) {
|
||||||
|
(ch as any).guild_id = d.id
|
||||||
await gateway.client.channels.set(ch.id, ch)
|
await gateway.client.channels.set(ch.id, ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((d as GuildPayload).roles) {
|
if((d as any).roles !== undefined) {
|
||||||
let roles = new RolesManager(gateway.client, guild)
|
const roles = new RolesManager(gateway.client, guild)
|
||||||
await roles.fromPayload((d as GuildPayload).roles as RolePayload[])
|
await roles.fromPayload((d as any).roles as RolePayload[])
|
||||||
guild.roles = roles
|
guild.roles = roles
|
||||||
}
|
}
|
||||||
await guild.roles.fromPayload(d.roles)
|
await guild.roles.fromPayload(d.roles)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import cache from '../../models/cache.ts'
|
import cache from '../../models/cache.ts'
|
||||||
import { Guild } from '../../structures/guild.ts'
|
import { Guild } from '../../structures/guild.ts'
|
||||||
import { GuildEmojiUpdatePayload } from '../../types/gatewayTypes.ts'
|
import { GuildEmojiUpdatePayload } from '../../types/gateway.ts'
|
||||||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
|
|
||||||
const guildEmojiUpdate: GatewayEventHandler = (
|
export const guildEmojiUpdate: GatewayEventHandler = (
|
||||||
gateway: Gateway,
|
gateway: Gateway,
|
||||||
d: GuildEmojiUpdatePayload
|
d: GuildEmojiUpdatePayload
|
||||||
) => {
|
) => {
|
||||||
const guild: Guild = cache.get('guild', d.guild_id)
|
const guild: Guild = cache.get('guild', d.guild_id)
|
||||||
if (guild !== undefined) {
|
if (guild !== undefined) {
|
||||||
const emojis = guild.emojis
|
// const emojis = guild.emojis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { Channel } from '../../structures/channel.ts'
|
|
||||||
import { Message } from '../../structures/message.ts'
|
import { Message } from '../../structures/message.ts'
|
||||||
import { MessageMentions } from '../../structures/MessageMentions.ts'
|
import { MessageMentions } from '../../structures/MessageMentions.ts'
|
||||||
import { TextChannel } from '../../structures/textChannel.ts'
|
import { TextChannel } from '../../structures/textChannel.ts'
|
||||||
|
@ -13,15 +12,15 @@ export const messageCreate: GatewayEventHandler = async (
|
||||||
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
|
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
|
||||||
// Fetch the channel if not cached
|
// Fetch the channel if not cached
|
||||||
if (channel === undefined)
|
if (channel === undefined)
|
||||||
channel = (await gateway.client.channels.fetch(d.channel_id)) as TextChannel
|
channel = (await gateway.client.channels.fetch(d.channel_id)) as any
|
||||||
const user = new User(gateway.client, d.author)
|
const user = new User(gateway.client, d.author)
|
||||||
await gateway.client.users.set(d.author.id, d.author)
|
await gateway.client.users.set(d.author.id, d.author)
|
||||||
let guild
|
let guild
|
||||||
if(d.guild_id) {
|
if(d.guild_id !== undefined) {
|
||||||
guild = await gateway.client.guilds.get(d.guild_id)
|
guild = await gateway.client.guilds.get(d.guild_id)
|
||||||
}
|
}
|
||||||
let mentions = new MessageMentions()
|
const mentions = new MessageMentions()
|
||||||
let message = new Message(gateway.client, d, channel, user, mentions)
|
const message = new Message(gateway.client, d, channel as any, user, mentions)
|
||||||
if(guild) message.guild = guild
|
if(guild !== undefined) message.guild = guild
|
||||||
gateway.client.emit('messageCreate', message)
|
gateway.client.emit('messageCreate', message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
} from '../types/gateway.ts'
|
} from '../types/gateway.ts'
|
||||||
import { gatewayHandlers } from './handlers/index.ts'
|
import { gatewayHandlers } from './handlers/index.ts'
|
||||||
import { GATEWAY_BOT } from '../types/endpoint.ts'
|
import { GATEWAY_BOT } from '../types/endpoint.ts'
|
||||||
import { GatewayBotPayload } from "../types/gatewayBot.ts"
|
|
||||||
import { GatewayCache } from "../managers/GatewayCache.ts"
|
import { GatewayCache } from "../managers/GatewayCache.ts"
|
||||||
import { ClientActivityPayload } from "../structures/presence.ts"
|
import { ClientActivityPayload } from "../structures/presence.ts"
|
||||||
|
|
||||||
|
@ -95,10 +94,9 @@ class Gateway {
|
||||||
}, this.heartbeatInterval)
|
}, this.heartbeatInterval)
|
||||||
|
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
this.sendIdentify(this.client.forceNewSession)
|
|
||||||
this.initialized = true
|
this.initialized = true
|
||||||
|
await this.sendIdentify(this.client.forceNewSession)
|
||||||
} else {
|
} else {
|
||||||
console.log('Calling Resume')
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
this.sendResume()
|
this.sendResume()
|
||||||
}
|
}
|
||||||
|
@ -290,18 +288,18 @@ class Gateway {
|
||||||
this.websocket.close(1000)
|
this.websocket.close(1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
send(data: GatewayResponse) {
|
send(data: GatewayResponse): boolean {
|
||||||
if (this.websocket.readyState != this.websocket.OPEN) return false
|
if (this.websocket.readyState !== this.websocket.OPEN) return false
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
op: data.op,
|
op: data.op,
|
||||||
d: data.d,
|
d: data.d,
|
||||||
s: typeof data.s == "number" ? data.s : null,
|
s: typeof data.s === "number" ? data.s : null,
|
||||||
t: data.t || null,
|
t: data.t === undefined ? null : data.t,
|
||||||
}))
|
}))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPresence(data: ClientActivityPayload) {
|
sendPresence(data: ClientActivityPayload): void {
|
||||||
this.send({
|
this.send({
|
||||||
op: GatewayOpcodes.PRESENCE_UPDATE,
|
op: GatewayOpcodes.PRESENCE_UPDATE,
|
||||||
d: data
|
d: data
|
||||||
|
|
|
@ -11,12 +11,12 @@ export class BaseChildManager<T, T2> {
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(key: string): Promise<T2 | void> {
|
async get(key: string): Promise<T2 | undefined> {
|
||||||
return await this.parent.get(key)
|
return this.parent.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(key: string, value: T) {
|
async set(key: string, value: T): Promise<void> {
|
||||||
return await this.parent.set(key, value)
|
return this.parent.set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(key: string): Promise<any> {
|
async delete(key: string): Promise<any> {
|
||||||
|
@ -24,15 +24,15 @@ export class BaseChildManager<T, T2> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async array(): Promise<any> {
|
async array(): Promise<any> {
|
||||||
return await this.parent.array()
|
return this.parent.array()
|
||||||
}
|
}
|
||||||
|
|
||||||
async collection(): Promise<Collection<string, T2>> {
|
async collection(): Promise<Collection<string, T2>> {
|
||||||
const arr = await this.array() as void | T2[]
|
const arr = await this.array() as undefined | T2[]
|
||||||
if(arr === undefined) return new Collection()
|
if(arr === undefined) return new Collection()
|
||||||
let collection = new Collection()
|
const collection = new Collection()
|
||||||
for (const elem of arr) {
|
for (const elem of arr) {
|
||||||
// @ts-ignore
|
// @ts-expect-error
|
||||||
collection.set(elem.id, elem)
|
collection.set(elem.id, elem)
|
||||||
}
|
}
|
||||||
return collection
|
return collection
|
||||||
|
|
|
@ -30,23 +30,23 @@ export class BaseManager<T, T2> {
|
||||||
return this.client.cache.delete(this.cacheName, key)
|
return this.client.cache.delete(this.cacheName, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
async array(): Promise<void | T2[]> {
|
async array(): Promise<undefined | T2[]> {
|
||||||
let arr = await (this.client.cache.array(this.cacheName) as T[])
|
const arr = await (this.client.cache.array(this.cacheName) as T[])
|
||||||
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() as void | T2[]
|
const arr = await this.array()
|
||||||
if(arr === undefined) return new Collection()
|
if(arr === undefined) return new Collection()
|
||||||
let collection = new Collection()
|
const collection = new Collection()
|
||||||
for (const elem of arr) {
|
for (const elem of arr) {
|
||||||
// @ts-ignore
|
// @ts-expect-error
|
||||||
collection.set(elem.id, elem)
|
collection.set(elem.id, elem)
|
||||||
}
|
}
|
||||||
return collection
|
return collection
|
||||||
}
|
}
|
||||||
|
|
||||||
flush() {
|
flush(): any {
|
||||||
return this.client.cache.deleteCache(this.cacheName)
|
return this.client.cache.deleteCache(this.cacheName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { Client } from "../models/client.ts";
|
import { Client } from "../models/client.ts";
|
||||||
import { Channel } from "../structures/channel.ts";
|
import { Channel } from "../structures/channel.ts";
|
||||||
import { User } from "../structures/user.ts";
|
|
||||||
import { ChannelPayload } from "../types/channel.ts";
|
import { ChannelPayload } from "../types/channel.ts";
|
||||||
import { CHANNEL } from "../types/endpoint.ts";
|
import { CHANNEL } from "../types/endpoint.ts";
|
||||||
import getChannelByType from "../utils/getChannelByType.ts";
|
import getChannelByType from "../utils/getChannelByType.ts";
|
||||||
|
@ -13,39 +12,39 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||||
|
|
||||||
// Override get method as Generic
|
// Override get method as Generic
|
||||||
async get<T = Channel>(key: string): Promise<T | undefined> {
|
async get<T = Channel>(key: string): Promise<T | undefined> {
|
||||||
let data = await this._get(key) as any
|
const data = await this._get(key)
|
||||||
if(!data) return
|
if(data === undefined) return
|
||||||
let guild
|
let guild
|
||||||
if(data.guild_id) {
|
if((data as any).guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get(data.guild_id)
|
guild = await this.client.guilds.get((data as any).guild_id)
|
||||||
}
|
}
|
||||||
let res = getChannelByType(this.client, data as ChannelPayload, guild || undefined)
|
const res = getChannelByType(this.client, data, guild)
|
||||||
return res as any
|
return res as any
|
||||||
}
|
}
|
||||||
|
|
||||||
async array(): Promise<void | Channel[]> {
|
async array(): Promise<undefined | Channel[]> {
|
||||||
let arr = await (this.client.cache.array(this.cacheName) as ChannelPayload[])
|
const arr = await (this.client.cache.array(this.cacheName) as ChannelPayload[])
|
||||||
let result: any[] = []
|
const result: any[] = []
|
||||||
for(let elem of arr) {
|
for(const elem of arr) {
|
||||||
let guild
|
let guild
|
||||||
if((elem as any).guild_id) {
|
if((elem as any).guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get((elem as any).guild_id)
|
guild = await this.client.guilds.get((elem as any).guild_id)
|
||||||
}
|
}
|
||||||
result.push(getChannelByType(this.client, elem as ChannelPayload, guild || undefined))
|
result.push(getChannelByType(this.client, elem, guild))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(id: string): Promise<Channel> {
|
async fetch(id: string): Promise<Channel> {
|
||||||
return new Promise((res, rej) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.client.rest.get(CHANNEL(id)).then(async data => {
|
this.client.rest.get(CHANNEL(id)).then(async data => {
|
||||||
this.set(id, data as ChannelPayload)
|
this.set(id, data as ChannelPayload)
|
||||||
let guild
|
let guild
|
||||||
if((data as any).guild_id) {
|
if(data.guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get((data as any).guild_id)
|
guild = await this.client.guilds.get(data.guild_id)
|
||||||
}
|
}
|
||||||
res(getChannelByType(this.client, data as ChannelPayload, guild || undefined))
|
resolve(getChannelByType(this.client, data as ChannelPayload, guild))
|
||||||
}).catch(e => rej(e))
|
}).catch(e => reject(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,12 @@ import { VoiceChannel } from "../structures/guildVoiceChannel.ts";
|
||||||
import { GuildChannelCategoryPayload, GuildTextChannelPayload, GuildVoiceChannelPayload } from "../types/channel.ts";
|
import { GuildChannelCategoryPayload, GuildTextChannelPayload, GuildVoiceChannelPayload } from "../types/channel.ts";
|
||||||
import { CHANNEL } from "../types/endpoint.ts";
|
import { CHANNEL } from "../types/endpoint.ts";
|
||||||
import { BaseChildManager } from "./BaseChildManager.ts";
|
import { BaseChildManager } from "./BaseChildManager.ts";
|
||||||
import { BaseManager } from "./BaseManager.ts";
|
|
||||||
import { ChannelsManager } from "./ChannelsManager.ts";
|
import { ChannelsManager } from "./ChannelsManager.ts";
|
||||||
|
|
||||||
export type GuildChannelPayload = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload
|
export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload
|
||||||
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
|
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
|
||||||
|
|
||||||
export class GuildChannelsManager extends BaseChildManager<GuildChannelPayload, GuildChannel> {
|
export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads, GuildChannel> {
|
||||||
guild: Guild
|
guild: Guild
|
||||||
|
|
||||||
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
|
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
|
||||||
|
@ -21,24 +20,24 @@ export class GuildChannelsManager extends BaseChildManager<GuildChannelPayload,
|
||||||
this.guild = guild
|
this.guild = guild
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: string): Promise<GuildChannel | void> {
|
async get(id: string): Promise<GuildChannel | undefined> {
|
||||||
const res = await this.parent.get(id)
|
const res = await this.parent.get(id)
|
||||||
if(res && res.guild.id == this.guild.id) return res
|
if(res !== undefined && res.guild.id === this.guild.id) return res
|
||||||
else return
|
else return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(id: string) {
|
async delete(id: string): Promise<boolean> {
|
||||||
return this.client.rest.delete(CHANNEL(id))
|
return this.client.rest.delete(CHANNEL(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
async array(): Promise<GuildChannel[]> {
|
async array(): Promise<GuildChannel[]> {
|
||||||
let arr = await this.parent.array() as Channel[]
|
const arr = await this.parent.array() as Channel[]
|
||||||
return arr as any//.filter((c: any) => c.guild && c.guild.id == this.guild.id) as any
|
return arr.filter((c: any) => c.guild !== undefined && c.guild.id === this.guild.id) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
async flush() {
|
async flush(): Promise<boolean> {
|
||||||
let arr = await this.array()
|
const arr = await this.array()
|
||||||
for (let elem of arr) {
|
for (const elem of arr) {
|
||||||
this.parent.delete(elem.id)
|
this.parent.delete(elem.id)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { guildBanAdd } from "../gateway/handlers/guildBanAdd.ts";
|
|
||||||
import { Client } from "../models/client.ts";
|
import { Client } from "../models/client.ts";
|
||||||
import { Guild } from "../structures/guild.ts";
|
import { Guild } from "../structures/guild.ts";
|
||||||
import { GUILD } from "../types/endpoint.ts";
|
import { GUILD } from "../types/endpoint.ts";
|
||||||
|
@ -11,18 +10,18 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
|
||||||
super(client, 'guilds', Guild)
|
super(client, 'guilds', Guild)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(id: string) {
|
async fetch(id: string): Promise<Guild> {
|
||||||
return new Promise((res, rej) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.client.rest.get(GUILD(id)).then(async (data: any) => {
|
this.client.rest.get(GUILD(id)).then(async (data: any) => {
|
||||||
this.set(id, data)
|
this.set(id, data)
|
||||||
let guild = new Guild(this.client, data)
|
const guild = new Guild(this.client, data)
|
||||||
if((data as GuildPayload).members) {
|
if((data as GuildPayload).members !== undefined) {
|
||||||
let members = new MembersManager(this.client, guild)
|
const members = new MembersManager(this.client, guild)
|
||||||
await members.fromPayload((data as GuildPayload).members as MemberPayload[])
|
await members.fromPayload((data as GuildPayload).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
}
|
}
|
||||||
res(guild)
|
resolve(guild)
|
||||||
}).catch(e => rej(e))
|
}).catch(e => reject(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,28 @@
|
||||||
import { Client } from "../models/client.ts";
|
import { Client } from "../models/client.ts";
|
||||||
import { Guild } from "../structures/guild.ts";
|
import { Guild } from "../structures/guild.ts";
|
||||||
import { Member } from "../structures/member.ts";
|
import { Member } from "../structures/member.ts";
|
||||||
import { Role } from "../structures/role.ts";
|
import { GUILD_MEMBER } from "../types/endpoint.ts";
|
||||||
import { GUILD_MEMBER, GUILD_ROLE } from "../types/endpoint.ts";
|
|
||||||
import { MemberPayload } from "../types/guild.ts";
|
import { MemberPayload } from "../types/guild.ts";
|
||||||
import { RolePayload } from "../types/role.ts";
|
|
||||||
import { BaseManager } from "./BaseManager.ts";
|
import { BaseManager } from "./BaseManager.ts";
|
||||||
|
|
||||||
export class MembersManager extends BaseManager<MemberPayload, Member> {
|
export class MembersManager extends BaseManager<MemberPayload, Member> {
|
||||||
guild: Guild
|
guild: Guild
|
||||||
|
|
||||||
constructor(client: Client, guild: Guild) {
|
constructor(client: Client, guild: Guild) {
|
||||||
super(client, `g${guild.id}m`, Member)
|
super(client, `members:${guild.id}`, Member)
|
||||||
this.guild = guild
|
this.guild = guild
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(id: string) {
|
async fetch(id: string): Promise<Member> {
|
||||||
return new Promise((res, rej) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(data => {
|
this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(data => {
|
||||||
this.set(id, data as MemberPayload)
|
this.set(id, data as MemberPayload)
|
||||||
res(new Member(this.client, data as MemberPayload))
|
resolve(new Member(this.client, data as MemberPayload))
|
||||||
}).catch(e => rej(e))
|
}).catch(e => reject(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fromPayload(members: MemberPayload[]) {
|
async fromPayload(members: MemberPayload[]): Promise<void> {
|
||||||
for(const member of members) {
|
for(const member of members) {
|
||||||
await this.set(member.user.id, member)
|
await this.set(member.user.id, member)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { TextChannel } from "../structures/textChannel.ts";
|
||||||
import { User } from "../structures/user.ts";
|
import { User } from "../structures/user.ts";
|
||||||
import { MessagePayload } from "../types/channel.ts";
|
import { MessagePayload } from "../types/channel.ts";
|
||||||
import { CHANNEL_MESSAGE } from "../types/endpoint.ts";
|
import { CHANNEL_MESSAGE } from "../types/endpoint.ts";
|
||||||
import { UserPayload } from "../types/user.ts";
|
|
||||||
import { BaseManager } from "./BaseManager.ts";
|
import { BaseManager } from "./BaseManager.ts";
|
||||||
|
|
||||||
export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
||||||
|
@ -15,27 +14,27 @@ export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
||||||
|
|
||||||
async get(key: string): Promise<Message | undefined> {
|
async get(key: string): Promise<Message | undefined> {
|
||||||
const raw = await this._get(key)
|
const raw = await this._get(key)
|
||||||
if(!raw) return
|
if(raw === undefined) return
|
||||||
let channel = await this.client.channels.get(raw.channel_id)
|
let channel = await this.client.channels.get(raw.channel_id)
|
||||||
if(!channel) channel = await this.client.channels.fetch(raw.channel_id)
|
if(channel === undefined) channel = await this.client.channels.fetch(raw.channel_id)
|
||||||
if(!channel) return
|
if(channel === undefined) return
|
||||||
let author = new User(this.client, raw.author)
|
const author = new User(this.client, raw.author)
|
||||||
let mentions = new MessageMentions()
|
const mentions = new MessageMentions()
|
||||||
return new this.DataType(this.client, raw, channel, author, mentions) as any
|
return new this.DataType(this.client, raw, channel, author, mentions) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(channelID: string, id: string) {
|
async fetch(channelID: string, id: string): Promise<Message> {
|
||||||
return new Promise((res, rej) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => {
|
this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => {
|
||||||
this.set(id, data as MessagePayload)
|
this.set(id, data as MessagePayload)
|
||||||
let channel = await this.client.channels.get<TextChannel>(channelID)
|
let channel: any = await this.client.channels.get<TextChannel>(channelID)
|
||||||
if(!channel) channel = await this.client.channels.fetch(channelID) as TextChannel
|
if(channel === undefined) channel = await this.client.channels.fetch(channelID)
|
||||||
let author = new User(this.client, (data as MessagePayload).author as UserPayload)
|
const author = new User(this.client, (data as MessagePayload).author)
|
||||||
await this.client.users.set(author.id, (data as MessagePayload).author)
|
await this.client.users.set(author.id, (data as MessagePayload).author)
|
||||||
// TODO: Make this thing work (MessageMentions)
|
// TODO: Make this thing work (MessageMentions)
|
||||||
let mentions = new MessageMentions()
|
const mentions = new MessageMentions()
|
||||||
res(new Message(this.client, data as MessagePayload, channel, author, mentions))
|
resolve(new Message(this.client, data as MessagePayload, channel as TextChannel, author, mentions))
|
||||||
}).catch(e => rej(e))
|
}).catch(e => reject(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class RolesManager extends BaseManager<RolePayload, Role> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fromPayload(roles: RolePayload[]) {
|
async fromPayload(roles: RolePayload[]): Promise<boolean> {
|
||||||
for(const role of roles) {
|
for(const role of roles) {
|
||||||
await this.set(role.id, role)
|
await this.set(role.id, role)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,8 @@ export class DefaultCacheAdapter implements ICacheAdapter {
|
||||||
return cache.array()
|
return cache.array()
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteCache(cacheName: string) {
|
async deleteCache(cacheName: string): Promise<boolean> {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
return delete this.data[cacheName]
|
return delete this.data[cacheName]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,8 +121,8 @@ export class RedisCacheAdapter implements ICacheAdapter {
|
||||||
return data?.map((e: string) => JSON.parse(e))
|
return data?.map((e: string) => JSON.parse(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteCache(cacheName: string) {
|
async deleteCache(cacheName: string): Promise<boolean> {
|
||||||
await this._checkReady()
|
await this._checkReady()
|
||||||
return await this.redis?.del(cacheName)
|
return await this.redis?.del(cacheName) !== 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { GuildManager } from "../managers/GuildsManager.ts"
|
||||||
import { EmojisManager } from "../managers/EmojisManager.ts"
|
import { EmojisManager } from "../managers/EmojisManager.ts"
|
||||||
import { ChannelsManager } from "../managers/ChannelsManager.ts"
|
import { ChannelsManager } from "../managers/ChannelsManager.ts"
|
||||||
import { MessagesManager } from "../managers/MessagesManager.ts"
|
import { MessagesManager } from "../managers/MessagesManager.ts"
|
||||||
import { ActivityGame, ClientActivity, ClientActivityPayload, ClientPresence } from "../structures/presence.ts"
|
import { ActivityGame, ClientActivity, ClientPresence } from "../structures/presence.ts"
|
||||||
|
|
||||||
/** Some Client Options to modify behaviour */
|
/** Some Client Options to modify behaviour */
|
||||||
export interface ClientOptions {
|
export interface ClientOptions {
|
||||||
|
@ -54,14 +54,14 @@ export class Client extends EventEmitter {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setPresence(presence: ClientPresence | ClientActivity | ActivityGame) {
|
setPresence(presence: ClientPresence | ClientActivity | ActivityGame): void {
|
||||||
if(presence instanceof ClientPresence) {
|
if(presence instanceof ClientPresence) {
|
||||||
this.presence = presence
|
this.presence = presence
|
||||||
} else this.presence = new ClientPresence(presence)
|
} else this.presence = new ClientPresence(presence)
|
||||||
this.gateway?.sendPresence(this.presence.create())
|
this.gateway?.sendPresence(this.presence.create())
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(tag: string, msg: string) {
|
debug(tag: string, msg: string): void {
|
||||||
this.emit("debug", `[${tag}] ${msg}`)
|
this.emit("debug", `[${tag}] ${msg}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
import { Client } from '../models/client.ts'
|
import { Client } from '../models/client.ts'
|
||||||
import { GuildFeatures, GuildPayload } from '../types/guild.ts'
|
import { GuildFeatures, GuildPayload } from '../types/guild.ts'
|
||||||
import { PresenceUpdatePayload } from '../types/presence.ts'
|
import { PresenceUpdatePayload } from '../types/gateway.ts'
|
||||||
import { Base } from './base.ts'
|
import { Base } from './base.ts'
|
||||||
import { Channel } from './channel.ts'
|
|
||||||
import { Emoji } from './emoji.ts'
|
import { Emoji } from './emoji.ts'
|
||||||
import { Member } from './member.ts'
|
|
||||||
import { VoiceState } from './voiceState.ts'
|
import { VoiceState } from './voiceState.ts'
|
||||||
import cache from '../models/cache.ts'
|
import cache from '../models/cache.ts'
|
||||||
import getChannelByType from '../utils/getChannelByType.ts'
|
|
||||||
import { RolesManager } from "../managers/RolesManager.ts"
|
import { RolesManager } from "../managers/RolesManager.ts"
|
||||||
import { Role } from "./role.ts"
|
|
||||||
import { GuildChannelsManager } from "../managers/GuildChannelsManager.ts"
|
import { GuildChannelsManager } from "../managers/GuildChannelsManager.ts"
|
||||||
import { MembersManager } from "../managers/MembersManager.ts"
|
import { MembersManager } from "../managers/MembersManager.ts"
|
||||||
import { ChannelsManager } from "../managers/ChannelsManager.ts"
|
|
||||||
|
|
||||||
export class Guild extends Base {
|
export class Guild extends Base {
|
||||||
id: string
|
id: string
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { User } from './user.ts'
|
||||||
import { Member } from './member.ts'
|
import { Member } from './member.ts'
|
||||||
import { Embed } from './embed.ts'
|
import { Embed } from './embed.ts'
|
||||||
import { CHANNEL_MESSAGE } from '../types/endpoint.ts'
|
import { CHANNEL_MESSAGE } from '../types/endpoint.ts'
|
||||||
import { Channel } from "./channel.ts"
|
|
||||||
import { MessageMentions } from "./MessageMentions.ts"
|
import { MessageMentions } from "./MessageMentions.ts"
|
||||||
import { TextChannel } from "./textChannel.ts"
|
import { TextChannel } from "./textChannel.ts"
|
||||||
import { DMChannel } from "./dmChannel.ts"
|
import { DMChannel } from "./dmChannel.ts"
|
||||||
|
@ -124,11 +123,11 @@ export class Message extends Base {
|
||||||
this.flags = data.flags ?? this.flags
|
this.flags = data.flags ?? this.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
edit (text?: string, option?: MessageOption): Promise<Message> {
|
async edit (text?: string, option?: MessageOption): Promise<Message> {
|
||||||
return this.channel.edit(this.id, text, option)
|
return this.channel.edit(this.id, text, option)
|
||||||
}
|
}
|
||||||
|
|
||||||
reply(text: string, options?: MessageOption) {
|
async reply(text: string, options?: MessageOption): Promise<Message> {
|
||||||
// TODO: Use inline replies once they're out
|
// TODO: Use inline replies once they're out
|
||||||
if(this.channel instanceof DMChannel) return this.channel.send(text, options)
|
if(this.channel instanceof DMChannel) return this.channel.send(text, options)
|
||||||
return this.channel.send(`${this.author.mention}, ${text}`, options)
|
return this.channel.send(`${this.author.mention}, ${text}`, options)
|
||||||
|
|
|
@ -37,13 +37,13 @@ export class ClientPresence {
|
||||||
afk?: boolean
|
afk?: boolean
|
||||||
|
|
||||||
constructor(data?: ClientActivity | ClientActivityPayload | ActivityGame) {
|
constructor(data?: ClientActivity | ClientActivityPayload | ActivityGame) {
|
||||||
if (data) {
|
if (data !== undefined) {
|
||||||
if((data as ClientActivity).activity !== undefined) {
|
if((data as ClientActivity).activity !== undefined) {
|
||||||
Object.assign(this, data)
|
Object.assign(this, data)
|
||||||
} else if((data as ClientActivityPayload).activities !== undefined) {
|
} else if((data as ClientActivityPayload).activities !== undefined) {
|
||||||
|
|
||||||
} else if((data as ActivityGame).name !== undefined) {
|
} else if((data as ActivityGame).name !== undefined) {
|
||||||
if(!this.activity) {
|
if(this.activity === undefined) {
|
||||||
this.activity = data as ActivityGame
|
this.activity = data as ActivityGame
|
||||||
} else if(this.activity instanceof Array) {
|
} else if(this.activity instanceof Array) {
|
||||||
this.activity.push(data as ActivityGame)
|
this.activity.push(data as ActivityGame)
|
||||||
|
@ -52,68 +52,71 @@ export class ClientPresence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(payload: ClientActivityPayload) {
|
parse(payload: ClientActivityPayload): ClientPresence {
|
||||||
this.afk = payload.afk
|
this.afk = payload.afk
|
||||||
this.activity = payload.activities ?? undefined
|
this.activity = payload.activities ?? undefined
|
||||||
this.since = payload.since
|
this.since = payload.since
|
||||||
this.status = payload.status
|
this.status = payload.status
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse(payload: ClientActivityPayload) {
|
static parse(payload: ClientActivityPayload): ClientPresence {
|
||||||
return new ClientPresence().parse(payload)
|
return new ClientPresence().parse(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
create(): ClientActivityPayload {
|
create(): ClientActivityPayload {
|
||||||
return {
|
return {
|
||||||
afk: this.afk || false,
|
afk: this.afk === undefined ? false : this.afk,
|
||||||
activities: this.createActivity(),
|
activities: this.createActivity(),
|
||||||
since: this.since || null,
|
since: this.since === undefined ? null : this.since,
|
||||||
status: this.status || 'online'
|
status: this.status === undefined ? 'online' : this.status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createActivity() {
|
createActivity(): ActivityGame[] | null {
|
||||||
let activity = this.activity == undefined ? null : (this.activity instanceof Array ? this.activity : [this.activity]) || null
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||||
if(activity == null) return activity
|
const activity = this.activity === undefined ? null : (this.activity instanceof Array ? this.activity : [this.activity]) || null
|
||||||
|
if(activity === null) return activity
|
||||||
else {
|
else {
|
||||||
activity.map(e => {
|
activity.map(e => {
|
||||||
if(typeof e.type == "string") e.type = ActivityTypes[e.type]
|
if(typeof e.type === "string") e.type = ActivityTypes[e.type]
|
||||||
return e
|
return e
|
||||||
})
|
})
|
||||||
return activity
|
return activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatus(status: StatusType) {
|
setStatus(status: StatusType): ClientPresence {
|
||||||
this.status = status
|
this.status = status
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setActivity(activity: ActivityGame) {
|
setActivity(activity: ActivityGame): ClientPresence {
|
||||||
this.activity = activity
|
this.activity = activity
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setActivities(activities: ActivityGame[]) {
|
setActivities(activities: ActivityGame[]): ClientPresence {
|
||||||
this.activity = activities
|
this.activity = activities
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setAFK(afk: boolean) {
|
setAFK(afk: boolean): ClientPresence {
|
||||||
this.afk = afk
|
this.afk = afk
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAFK() {
|
removeAFK(): ClientPresence {
|
||||||
this.afk = false
|
this.afk = false
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleAFK() {
|
toggleAFK(): ClientPresence {
|
||||||
this.afk = !(this.afk || true)
|
this.afk = this.afk === undefined ? true : !this.afk
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setSince(since?: number) {
|
setSince(since?: number): ClientPresence {
|
||||||
this.since = since
|
this.since = since
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts'
|
||||||
import { Channel } from './channel.ts'
|
import { Channel } from './channel.ts'
|
||||||
import { Message } from './message.ts'
|
import { Message } from './message.ts'
|
||||||
import { MessageMentions } from './MessageMentions.ts'
|
import { MessageMentions } from './MessageMentions.ts'
|
||||||
import { User } from "./user.ts"
|
|
||||||
|
|
||||||
export class TextChannel extends Channel {
|
export class TextChannel extends Channel {
|
||||||
lastMessageID?: string
|
lastMessageID?: string
|
||||||
|
@ -36,7 +35,7 @@ export class TextChannel extends Channel {
|
||||||
allowed_mentions: option?.allowedMention
|
allowed_mentions: option?.allowedMention
|
||||||
})
|
})
|
||||||
|
|
||||||
return new Message(this.client, resp as any, this, this.client.user as User, new MessageMentions())
|
return new Message(this.client, resp as any, this, this.client.user as any, new MessageMentions())
|
||||||
}
|
}
|
||||||
|
|
||||||
async edit (
|
async edit (
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
|
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
|
||||||
// https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
|
// https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
|
||||||
|
import { StatusType } from "../../mod.ts"
|
||||||
import { EmojiPayload } from './emoji.ts'
|
import { EmojiPayload } from './emoji.ts'
|
||||||
import { MemberPayload } from './guild.ts'
|
import { MemberPayload } from './guild.ts'
|
||||||
import { ActivityPayload } from './presence.ts'
|
import { ActivityPayload } from './presence.ts'
|
||||||
|
@ -291,7 +292,7 @@ export interface MessageReactionRemoveAllPayload {
|
||||||
export interface PresenceUpdatePayload {
|
export interface PresenceUpdatePayload {
|
||||||
user: UserPayload
|
user: UserPayload
|
||||||
guild_id: string
|
guild_id: string
|
||||||
status: string
|
status: StatusType
|
||||||
activities: ActivityPayload[]
|
activities: ActivityPayload[]
|
||||||
client_status: UpdateStatus[]
|
client_status: UpdateStatus[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ChannelPayload } from './channel.ts'
|
import { ChannelPayload } from './channel.ts'
|
||||||
import { EmojiPayload } from './emoji.ts'
|
import { EmojiPayload } from './emoji.ts'
|
||||||
import { PresenceUpdatePayload } from './presence.ts'
|
import { PresenceUpdatePayload } from './gateway.ts'
|
||||||
import { RolePayload } from './role.ts'
|
import { RolePayload } from './role.ts'
|
||||||
import { UserPayload } from './user.ts'
|
import { UserPayload } from './user.ts'
|
||||||
import { VoiceStatePayload } from './voice.ts'
|
import { VoiceStatePayload } from './voice.ts'
|
||||||
|
@ -63,23 +63,23 @@ export interface MemberPayload {
|
||||||
mute: boolean
|
mute: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MessageNotification {
|
export enum MessageNotification {
|
||||||
ALL_MESSAGES = 0,
|
ALL_MESSAGES = 0,
|
||||||
ONLY_MENTIONS = 1
|
ONLY_MENTIONS = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ContentFilter {
|
export enum ContentFilter {
|
||||||
DISABLED = 0,
|
DISABLED = 0,
|
||||||
MEMBERS_WITHOUT_ROLES = 1,
|
MEMBERS_WITHOUT_ROLES = 1,
|
||||||
ALL_MEMBERS = 3
|
ALL_MEMBERS = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MFA {
|
export enum MFA {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
ELEVATED = 1
|
ELEVATED = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Verification {
|
export enum Verification {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
LOW = 1,
|
LOW = 1,
|
||||||
MEDIUM = 2,
|
MEDIUM = 2,
|
||||||
|
@ -87,14 +87,14 @@ enum Verification {
|
||||||
VERY_HIGH = 4
|
VERY_HIGH = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PremiumTier {
|
export enum PremiumTier {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
TIER_1 = 1,
|
TIER_1 = 1,
|
||||||
TIER_2 = 2,
|
TIER_2 = 2,
|
||||||
TIER_3 = 3
|
TIER_3 = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SystemChannelFlags {
|
export enum SystemChannelFlags {
|
||||||
SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0,
|
SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0,
|
||||||
SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
|
SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
import { StatusType } from "../structures/presence.ts";
|
|
||||||
import { User } from "../structures/user.ts";
|
|
||||||
|
|
||||||
export interface ClientStatus {
|
export interface ClientStatus {
|
||||||
desktop?: string
|
desktop?: string
|
||||||
mobile?: string
|
mobile?: string
|
||||||
|
@ -60,12 +57,4 @@ export enum ActivityFlags {
|
||||||
JOIN_REQUEST = 1 << 3,
|
JOIN_REQUEST = 1 << 3,
|
||||||
SYNC = 1 << 4,
|
SYNC = 1 << 4,
|
||||||
PLAY = 1 << 5
|
PLAY = 1 << 5
|
||||||
}
|
|
||||||
|
|
||||||
export interface PresenceUpdatePayload {
|
|
||||||
user: User
|
|
||||||
guild_id: string
|
|
||||||
status: StatusType
|
|
||||||
activities: ActivityPayload
|
|
||||||
client_status: ClientStatus
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice
|
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice
|
||||||
import { MemberPayload } from './guild.ts'
|
import { MemberPayload } from './guild.ts'
|
||||||
|
|
||||||
enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC -
|
export enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC -
|
||||||
IDENTIFY = 0,
|
IDENTIFY = 0,
|
||||||
SELECT_PROTOCOL = 1,
|
SELECT_PROTOCOL = 1,
|
||||||
READY = 2,
|
READY = 2,
|
||||||
|
@ -15,7 +15,7 @@ enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC -
|
||||||
CLIENT_DISCONNECT = 13
|
CLIENT_DISCONNECT = 13
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VoiceCloseCodes {
|
export enum VoiceCloseCodes {
|
||||||
UNKNOWN_OPCODE = 4001,
|
UNKNOWN_OPCODE = 4001,
|
||||||
NOT_AUTHENTICATED = 4003,
|
NOT_AUTHENTICATED = 4003,
|
||||||
AUTHENTICATION_FAILED = 4004,
|
AUTHENTICATION_FAILED = 4004,
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
export class Collection<K = string, V = any> extends Map<K, V> {
|
export class Collection<K = string, V = any> extends Map<K, V> {
|
||||||
maxSize?: number;
|
set(key: K, value: V): this {
|
||||||
|
|
||||||
set(key: K, value: V) {
|
|
||||||
if (this.maxSize || this.maxSize === 0) {
|
|
||||||
if (this.size >= this.maxSize) return this
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.set(key, value)
|
return super.set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
array() {
|
array(): V[] {
|
||||||
return [...this.values()]
|
return [...this.values()]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,53 +15,49 @@ export class Collection<K = string, V = any> extends Map<K, V> {
|
||||||
return [...this.values()][this.size - 1]
|
return [...this.values()][this.size - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
random() {
|
random(): V {
|
||||||
const arr = [...this.values()]
|
const arr = [...this.values()]
|
||||||
return arr[Math.floor(Math.random() * arr.length)]
|
return arr[Math.floor(Math.random() * arr.length)]
|
||||||
}
|
}
|
||||||
|
|
||||||
find(callback: (value: V, key: K) => boolean) {
|
find(callback: (value: V, key: K) => boolean): V | undefined {
|
||||||
for (const key of this.keys()) {
|
for (const key of this.keys()) {
|
||||||
const value = this.get(key)!
|
const value = this.get(key) as V
|
||||||
|
// eslint-disable-next-line standard/no-callback-literal
|
||||||
if (callback(value, key)) return value
|
if (callback(value, key)) return value
|
||||||
}
|
}
|
||||||
// If nothing matched
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(callback: (value: V, key: K) => boolean) {
|
filter(callback: (value: V, key: K) => boolean): Collection<K, V> {
|
||||||
const relevant = new Collection<K, V>()
|
const relevant = new Collection<K, V>()
|
||||||
this.forEach((value, key) => {
|
this.forEach((value, key) => {
|
||||||
if (callback(value, key)) relevant.set(key, value)
|
if (callback(value, key)) relevant.set(key, value)
|
||||||
});
|
})
|
||||||
|
return relevant
|
||||||
return relevant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map<T>(callback: (value: V, key: K) => T) {
|
map<T>(callback: (value: V, key: K) => T): T[] {
|
||||||
const results = []
|
const results = []
|
||||||
for (const key of this.keys()) {
|
for (const key of this.keys()) {
|
||||||
const value = this.get(key)!
|
const value = this.get(key) as V
|
||||||
results.push(callback(value, key))
|
results.push(callback(value, key))
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
some(callback: (value: V, key: K) => boolean) {
|
some(callback: (value: V, key: K) => boolean): boolean {
|
||||||
for (const key of this.keys()) {
|
for (const key of this.keys()) {
|
||||||
const value = this.get(key)!
|
const value = this.get(key) as V
|
||||||
if (callback(value, key)) return true
|
if (callback(value, key)) return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
every(callback: (value: V, key: K) => boolean) {
|
every(callback: (value: V, key: K) => boolean): boolean {
|
||||||
for (const key of this.keys()) {
|
for (const key of this.keys()) {
|
||||||
const value = this.get(key)!
|
const value = this.get(key) as V
|
||||||
if (!callback(value, key)) return false
|
if (!callback(value, key)) return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,21 +65,21 @@ export class Collection<K = string, V = any> extends Map<K, V> {
|
||||||
callback: (accumulator: T, value: V, key: K) => T,
|
callback: (accumulator: T, value: V, key: K) => T,
|
||||||
initialValue?: T,
|
initialValue?: T,
|
||||||
): T {
|
): T {
|
||||||
let accumulator: T = initialValue!
|
let accumulator: T = initialValue as T
|
||||||
|
|
||||||
for (const key of this.keys()) {
|
for (const key of this.keys()) {
|
||||||
const value = this.get(key)!
|
const value = this.get(key) as V
|
||||||
accumulator = callback(accumulator, value, key)
|
accumulator = callback(accumulator, value, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return accumulator
|
return accumulator
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromObject<V>(object: { [key: string]: V }) {
|
static fromObject<V>(object: { [key: string]: V }): Collection<string, V> {
|
||||||
return new Collection<string, V>(Object.entries(object))
|
return new Collection<string, V>(Object.entries(object))
|
||||||
}
|
}
|
||||||
|
|
||||||
toObject() {
|
toObject(): { [name: string]: V } {
|
||||||
return Object.entries(this)
|
return Object.fromEntries(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue