fix: errors
This commit is contained in:
		
							parent
							
								
									be2945c5eb
								
							
						
					
					
						commit
						7cbf1e5151
					
				
					 4 changed files with 271 additions and 271 deletions
				
			
		|  | @ -1,15 +1,16 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
|  | import { GuildMemberAddPayload } from "../../../mod.ts" | ||||||
| 
 | 
 | ||||||
| export const guildMemberAdd: GatewayEventHandler = async ( | export const guildMemberAdd: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|   d:  |   d: GuildMemberAddPayload | ||||||
| ) => { | ) => { | ||||||
|   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|   // Weird case, shouldn't happen
 |   // Weird case, shouldn't happen
 | ||||||
|   if (guild === undefined) return |   if (guild === undefined) return | ||||||
| 
 | 
 | ||||||
|   await guild.members.set(d.id, d) |   await guild.members.set(d.user.id, d) | ||||||
|   const member = await guild.members.get(d.id) |   const member = await guild.members.get(d.user.id) | ||||||
|   gateway.client.emit('guildMemberAdd', member) |   gateway.client.emit('guildMemberAdd', member) | ||||||
| } | } | ||||||
|  | @ -1,124 +1,123 @@ | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { GatewayIntents } from '../types/gateway.ts' | import { GatewayIntents } from '../types/gateway.ts' | ||||||
| import { Gateway } from '../gateway/index.ts' | import { Gateway } from '../gateway/index.ts' | ||||||
| import { RESTManager } from './rest.ts' | import { RESTManager } from './rest.ts' | ||||||
| import EventEmitter from 'https://deno.land/std@0.74.0/node/events.ts' | import EventEmitter from 'https://deno.land/std@0.74.0/node/events.ts' | ||||||
| import { DefaultCacheAdapter, ICacheAdapter } from './cacheAdapter.ts' | import { DefaultCacheAdapter, ICacheAdapter } from './cacheAdapter.ts' | ||||||
| import { UserManager } from '../managers/users.ts' | import { UserManager } from '../managers/users.ts' | ||||||
| import { GuildManager } from '../managers/guilds.ts' | import { GuildManager } from '../managers/guilds.ts' | ||||||
| import { ChannelsManager } from '../managers/channels.ts' | import { ChannelsManager } from '../managers/channels.ts' | ||||||
| import { | import { | ||||||
|   ActivityGame, |   ClientPresence | ||||||
|   ClientActivity, | } from '../structures/presence.ts' | ||||||
|   ClientPresence | import { EmojisManager } from '../managers/emojis.ts' | ||||||
| } from '../structures/presence.ts' | import { ActivityGame, ClientActivity } from "../types/presence.ts" | ||||||
| import { EmojisManager } from '../managers/emojis.ts' | 
 | ||||||
| 
 | /** Some Client Options to modify behaviour */ | ||||||
| /** Some Client Options to modify behaviour */ | export interface ClientOptions { | ||||||
| export interface ClientOptions { |   /** Token of the Bot/User */ | ||||||
|   /** Token of the Bot/User */ |   token?: string | ||||||
|   token?: string |   /** Gateway Intents */ | ||||||
|   /** Gateway Intents */ |   intents?: GatewayIntents[] | ||||||
|   intents?: GatewayIntents[] |   /** Cache Adapter to use, defaults to Collections one */ | ||||||
|   /** Cache Adapter to use, defaults to Collections one */ |   cache?: ICacheAdapter, | ||||||
|   cache?: ICacheAdapter, |   /** Force New Session and don't use cached Session (by persistent caching) */ | ||||||
|   /** Force New Session and don't use cached Session (by persistent caching) */ |   forceNewSession?: boolean, | ||||||
|   forceNewSession?: boolean, |   /** Startup presence of client */ | ||||||
|   /** Startup presence of client */ |   presence?: ClientPresence | ClientActivity | ActivityGame | ||||||
|   presence?: ClientPresence | ClientActivity | ActivityGame |   /** Whether it's a bot user or not? Use this if selfbot! */ | ||||||
|   /** Whether it's a bot user or not? Use this if selfbot! */ |   bot?: boolean | ||||||
|   bot?: boolean |   /** Force all requests to Canary API */ | ||||||
|   /** Force all requests to Canary API */ |   canary?: boolean | ||||||
|   canary?: boolean |   /** Time till which Messages are to be cached, in MS. Default is 3600000 */ | ||||||
|   /** Time till which Messages are to be cached, in MS. Default is 3600000 */ |   messageCacheLifetime?: number | ||||||
|   messageCacheLifetime?: number | } | ||||||
| } | 
 | ||||||
| 
 | /** | ||||||
| /** |  * Discord Client. | ||||||
|  * Discord Client. |  */ | ||||||
|  */ | export class Client extends EventEmitter { | ||||||
| export class Client extends EventEmitter { |   /** Gateway object */ | ||||||
|   /** Gateway object */ |   gateway?: Gateway | ||||||
|   gateway?: Gateway |   /** REST Manager - used to make all requests */ | ||||||
|   /** REST Manager - used to make all requests */ |   rest: RESTManager = new RESTManager(this) | ||||||
|   rest: RESTManager = new RESTManager(this) |   /** User which Client logs in to, undefined until logs in */ | ||||||
|   /** User which Client logs in to, undefined until logs in */ |   user?: User | ||||||
|   user?: User |   /** WebSocket ping of Client */ | ||||||
|   /** WebSocket ping of Client */ |   ping = 0 | ||||||
|   ping = 0 |   /** Token of the Bot/User */ | ||||||
|   /** Token of the Bot/User */ |   token?: string | ||||||
|   token?: string |   /** Cache Adapter */ | ||||||
|   /** Cache Adapter */ |   cache: ICacheAdapter = new DefaultCacheAdapter() | ||||||
|   cache: ICacheAdapter = new DefaultCacheAdapter() |   /** Gateway Intents */ | ||||||
|   /** Gateway Intents */ |   intents?: GatewayIntents[] | ||||||
|   intents?: GatewayIntents[] |   /** Whether to force new session or not */ | ||||||
|   /** Whether to force new session or not */ |   forceNewSession?: boolean | ||||||
|   forceNewSession?: boolean |   /** Time till messages to stay cached, in MS. */ | ||||||
|   /** Time till messages to stay cached, in MS. */ |   messageCacheLifetime: number = 3600000 | ||||||
|   messageCacheLifetime: number = 3600000 | 
 | ||||||
| 
 |   users: UserManager = new UserManager(this) | ||||||
|   users: UserManager = new UserManager(this) |   guilds: GuildManager = new GuildManager(this) | ||||||
|   guilds: GuildManager = new GuildManager(this) |   channels: ChannelsManager = new ChannelsManager(this) | ||||||
|   channels: ChannelsManager = new ChannelsManager(this) |   emojis: EmojisManager = new EmojisManager(this) | ||||||
|   emojis: EmojisManager = new EmojisManager(this) |    | ||||||
|    |   /** Whether this client will login as bot user or not */ | ||||||
|   /** Whether this client will login as bot user or not */ |   bot: boolean = true | ||||||
|   bot: boolean = true |   /** Whether the REST Manager will use Canary API or not */ | ||||||
|   /** Whether the REST Manager will use Canary API or not */ |   canary: boolean = false | ||||||
|   canary: boolean = false |   /** Client's presence. Startup one if set before connecting */ | ||||||
|   /** Client's presence. Startup one if set before connecting */ |   presence: ClientPresence = new ClientPresence() | ||||||
|   presence: ClientPresence = new ClientPresence() | 
 | ||||||
| 
 |   constructor (options: ClientOptions = {}) { | ||||||
|   constructor (options: ClientOptions = {}) { |     super() | ||||||
|     super() |     this.token = options.token | ||||||
|     this.token = options.token |     this.intents = options.intents | ||||||
|     this.intents = options.intents |     this.forceNewSession = options.forceNewSession | ||||||
|     this.forceNewSession = options.forceNewSession |     if (options.cache !== undefined) this.cache = options.cache | ||||||
|     if (options.cache !== undefined) this.cache = options.cache |     if (options.presence !== undefined) | ||||||
|     if (options.presence !== undefined) |       this.presence = | ||||||
|       this.presence = |         options.presence instanceof ClientPresence | ||||||
|         options.presence instanceof ClientPresence |           ? options.presence | ||||||
|           ? options.presence |           : new ClientPresence(options.presence) | ||||||
|           : new ClientPresence(options.presence) |     if (options.bot === false) this.bot = false | ||||||
|     if (options.bot === false) this.bot = false |     if (options.canary === true) this.canary = true | ||||||
|     if (options.canary === true) this.canary = true |     if (options.messageCacheLifetime !== undefined) this.messageCacheLifetime = options.messageCacheLifetime | ||||||
|     if (options.messageCacheLifetime !== undefined) this.messageCacheLifetime = options.messageCacheLifetime |   } | ||||||
|   } | 
 | ||||||
| 
 |   /** Set Cache Adapter */ | ||||||
|   /** Set Cache Adapter */ |   setAdapter (adapter: ICacheAdapter): Client { | ||||||
|   setAdapter (adapter: ICacheAdapter): Client { |     this.cache = adapter | ||||||
|     this.cache = adapter |     return this | ||||||
|     return this |   } | ||||||
|   } | 
 | ||||||
| 
 |   /** Change Presence of Client */ | ||||||
|   /** Change Presence of Client */ |   setPresence (presence: ClientPresence | ClientActivity | ActivityGame): void { | ||||||
|   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()) |   } | ||||||
|   } | 
 | ||||||
| 
 |   /** Emit debug event */ | ||||||
|   /** Emit debug event */ |   debug (tag: string, msg: string): void { | ||||||
|   debug (tag: string, msg: string): void { |     this.emit('debug', `[${tag}] ${msg}`) | ||||||
|     this.emit('debug', `[${tag}] ${msg}`) |   } | ||||||
|   } | 
 | ||||||
| 
 |   /** | ||||||
|   /** |    * This function is used for connect to discord. | ||||||
|    * This function is used for connect to discord. |    * @param token Your token. This is required. | ||||||
|    * @param token Your token. This is required. |    * @param intents Gateway intents in array. This is required. | ||||||
|    * @param intents Gateway intents in array. This is required. |    */ | ||||||
|    */ |   connect (token?: string, intents?: GatewayIntents[]): void { | ||||||
|   connect (token?: string, intents?: GatewayIntents[]): void { |     if (token === undefined && this.token !== undefined) token = this.token | ||||||
|     if (token === undefined && this.token !== undefined) token = this.token |     else if (this.token === undefined && token !== undefined) { | ||||||
|     else if (this.token === undefined && token !== undefined) { |       this.token = token | ||||||
|       this.token = token |     } else throw new Error('No Token Provided') | ||||||
|     } else throw new Error('No Token Provided') |     if (intents === undefined && this.intents !== undefined) | ||||||
|     if (intents === undefined && this.intents !== undefined) |       intents = this.intents | ||||||
|       intents = this.intents |     else if (intents !== undefined && this.intents === undefined) { | ||||||
|     else if (intents !== undefined && this.intents === undefined) { |       this.intents = intents | ||||||
|       this.intents = intents |     } else throw new Error('No Gateway Intents were provided') | ||||||
|     } else throw new Error('No Gateway Intents were provided') |     this.gateway = new Gateway(this, token, intents) | ||||||
|     this.gateway = new Gateway(this, token, intents) |   } | ||||||
|   } | } | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -1,143 +1,143 @@ | ||||||
| import { MessagesManager } from "../../mod.ts" | import { MessagesManager } from "../../mod.ts" | ||||||
| import { Client } from '../models/client.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_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts' | ||||||
| import { Channel } from './channel.ts' | import { Channel } from './channel.ts' | ||||||
| import { Embed } from './embed.ts' | import { Embed } from './embed.ts' | ||||||
| import { Guild } from "./guild.ts" | import { Guild } from "./guild.ts" | ||||||
| import { Message } from './message.ts' | import { Message } from './message.ts' | ||||||
| 
 | 
 | ||||||
| type AllMessageOptions = MessageOption | Embed | type AllMessageOptions = MessageOption | Embed | ||||||
| 
 | 
 | ||||||
| export class TextChannel extends Channel { | export class TextChannel extends Channel { | ||||||
|   lastMessageID?: string |   lastMessageID?: string | ||||||
|   lastPinTimestamp?: string |   lastPinTimestamp?: string | ||||||
|   messages: MessagesManager |   messages: MessagesManager | ||||||
| 
 | 
 | ||||||
|   constructor(client: Client, data: TextChannelPayload) { |   constructor(client: Client, data: TextChannelPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.messages = new MessagesManager(this.client, this) |     this.messages = new MessagesManager(this.client, this) | ||||||
|     this.lastMessageID = data.last_message_id |     this.lastMessageID = data.last_message_id | ||||||
|     this.lastPinTimestamp = data.last_pin_timestamp |     this.lastPinTimestamp = data.last_pin_timestamp | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData(data: TextChannelPayload): void { |   protected readFromData(data: TextChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.lastMessageID = data.last_message_id ?? this.lastMessageID |     this.lastMessageID = data.last_message_id ?? this.lastMessageID | ||||||
|     this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp |     this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> { |   async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> { | ||||||
|     if (typeof text === "object") { |     if (typeof text === "object") { | ||||||
|       option = text |       option = text | ||||||
|       text = undefined |       text = undefined | ||||||
|     } |     } | ||||||
|     if (text === undefined && option === undefined) { |     if (text === undefined && option === undefined) { | ||||||
|       throw new Error('Either text or option is necessary.') |       throw new Error('Either text or option is necessary.') | ||||||
|     } |     } | ||||||
|     if (option instanceof Embed) option = { |     if (option instanceof Embed) option = { | ||||||
|       embed: option |       embed: option | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const payload: any = { |     const payload: any = { | ||||||
|       content: text, |       content: text, | ||||||
|       embed: option?.embed, |       embed: option?.embed, | ||||||
|       file: option?.file, |       file: option?.file, | ||||||
|       tts: option?.tts, |       tts: option?.tts, | ||||||
|       allowed_mentions: option?.allowedMention |       allowed_mentions: option?.allowedMention | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (reply !== undefined) { |     if (reply !== undefined) { | ||||||
|       const reference: MessageReference = { |       const reference: MessageReference = { | ||||||
|         message_id: reply.id, |         message_id: reply.id, | ||||||
|         channel_id: reply.channel.id, |         channel_id: reply.channel.id, | ||||||
|         guild_id: reply.guild?.id, |         guild_id: reply.guild?.id, | ||||||
|       } |       } | ||||||
|       payload.message_reference = reference |       payload.message_reference = reference | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const resp = await this.client.rest.post(CHANNEL_MESSAGES(this.id), payload) |     const resp = await this.client.rest.post(CHANNEL_MESSAGES(this.id), payload) | ||||||
| 
 | 
 | ||||||
|     const res = new Message(this.client, resp, this, this.client.user as any) |     const res = new Message(this.client, resp, this, this.client.user as any) | ||||||
|     await res.mentions.fromPayload(resp) |     await res.mentions.fromPayload(resp) | ||||||
|     return res |     return res | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async editMessage( |   async editMessage( | ||||||
|     message: Message | string, |     message: Message | string, | ||||||
|     text?: string, |     text?: string, | ||||||
|     option?: MessageOption |     option?: MessageOption | ||||||
|   ): Promise<Message> { |   ): Promise<Message> { | ||||||
|     if (text === undefined && option === undefined) { |     if (text === undefined && option === undefined) { | ||||||
|       throw new Error('Either text or option is necessary.') |       throw new Error('Either text or option is necessary.') | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client.user === undefined) { |     if (this.client.user === undefined) { | ||||||
|       throw new Error('Client user has not initialized.') |       throw new Error('Client user has not initialized.') | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const newMsg = await this.client.rest.patch( |     const newMsg = await this.client.rest.patch( | ||||||
|       CHANNEL_MESSAGE( |       CHANNEL_MESSAGE( | ||||||
|         this.id, |         this.id, | ||||||
|         typeof message === 'string' ? message : message.id |         typeof message === 'string' ? message : message.id | ||||||
|       ), |       ), | ||||||
|       { |       { | ||||||
|         content: text, |         content: text, | ||||||
|         embed: option?.embed.toJSON(), |         embed: option?.embed !== undefined ? option.embed.toJSON() : undefined, | ||||||
|         file: option?.file, |         file: option?.file, | ||||||
|         tts: option?.tts, |         tts: option?.tts, | ||||||
|         allowed_mentions: option?.allowedMention |         allowed_mentions: option?.allowedMention | ||||||
|       } |       } | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     const res = new Message(this.client, newMsg, this, this.client.user) |     const res = new Message(this.client, newMsg, this, this.client.user) | ||||||
|     await res.mentions.fromPayload(newMsg) |     await res.mentions.fromPayload(newMsg) | ||||||
|     return res |     return res | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class GuildTextChannel extends TextChannel { | export class GuildTextChannel extends TextChannel { | ||||||
|   guildID: string |   guildID: string | ||||||
|   name: string |   name: string | ||||||
|   position: number |   position: number | ||||||
|   permissionOverwrites: Overwrite[] |   permissionOverwrites: Overwrite[] | ||||||
|   nsfw: boolean |   nsfw: boolean | ||||||
|   parentID?: string |   parentID?: string | ||||||
|   rateLimit: number |   rateLimit: number | ||||||
|   topic?: string |   topic?: string | ||||||
|   guild: Guild |   guild: Guild | ||||||
| 
 | 
 | ||||||
|   get mention(): string { |   get mention(): string { | ||||||
|     return `<#${this.id}>` |     return `<#${this.id}>` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   toString(): string { |   toString(): string { | ||||||
|     return this.mention |     return this.mention | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   constructor(client: Client, data: GuildTextChannelPayload, guild: Guild) { |   constructor(client: Client, data: GuildTextChannelPayload, guild: Guild) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.guildID = data.guild_id |     this.guildID = data.guild_id | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|     this.guild = guild |     this.guild = guild | ||||||
|     this.position = data.position |     this.position = data.position | ||||||
|     this.permissionOverwrites = data.permission_overwrites |     this.permissionOverwrites = data.permission_overwrites | ||||||
|     this.nsfw = data.nsfw |     this.nsfw = data.nsfw | ||||||
|     this.parentID = data.parent_id |     this.parentID = data.parent_id | ||||||
|     this.topic = data.topic |     this.topic = data.topic | ||||||
|     this.rateLimit = data.rate_limit_per_user |     this.rateLimit = data.rate_limit_per_user | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData(data: GuildTextChannelPayload): void { |   protected readFromData(data: GuildTextChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.guildID = data.guild_id ?? this.guildID |     this.guildID = data.guild_id ?? this.guildID | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|     this.position = data.position ?? this.position |     this.position = data.position ?? this.position | ||||||
|     this.permissionOverwrites = |     this.permissionOverwrites = | ||||||
|       data.permission_overwrites ?? this.permissionOverwrites |       data.permission_overwrites ?? this.permissionOverwrites | ||||||
|     this.nsfw = data.nsfw ?? this.nsfw |     this.nsfw = data.nsfw ?? this.nsfw | ||||||
|     this.parentID = data.parent_id ?? this.parentID |     this.parentID = data.parent_id ?? this.parentID | ||||||
|     this.topic = data.topic ?? this.topic |     this.topic = data.topic ?? this.topic | ||||||
|     this.rateLimit = data.rate_limit_per_user ?? this.rateLimit |     this.rateLimit = data.rate_limit_per_user ?? this.rateLimit | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -191,7 +191,7 @@ export interface GuildIntegrationsUpdatePayload { | ||||||
|   guild_id: string |   guild_id: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface GuildMemberAddPayload { | export interface GuildMemberAddPayload extends MemberPayload { | ||||||
|   guild_id: string |   guild_id: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue