many things
This commit is contained in:
		
							parent
							
								
									c1cd6276ae
								
							
						
					
					
						commit
						dce4c99cbd
					
				
					 6 changed files with 100 additions and 18 deletions
				
			
		|  | @ -44,16 +44,18 @@ export const guildEmojiUpdate: GatewayEventHandler = async ( | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     gateway.client.emit('guildEmojisUpdate', guild) | ||||||
|  | 
 | ||||||
|     for (const emoji of deleted) { |     for (const emoji of deleted) { | ||||||
|       gateway.client.emit('guildEmojiDelete', guild, emoji) |       gateway.client.emit('guildEmojiDelete', emoji) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of added) { |     for (const emoji of added) { | ||||||
|       gateway.client.emit('guildEmojiAdd', guild, emoji) |       gateway.client.emit('guildEmojiAdd', emoji) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of updated) { |     for (const emoji of updated) { | ||||||
|       gateway.client.emit('guildEmojiUpdate', guild, emoji.before, emoji.after) |       gateway.client.emit('guildEmojiUpdate', emoji.before, emoji.after) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -113,11 +113,12 @@ export interface VoiceServerUpdateData { | ||||||
|   guild: Guild |   guild: Guild | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** All Client Events */ | ||||||
| // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
 | // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
 | ||||||
| export type ClientEvents = { | export type ClientEvents = { | ||||||
|   /** When Client has successfully connected to Discord */ |   /** When Client has successfully connected to Discord */ | ||||||
|   ready: [shard: number] |   ready: [shard: number] | ||||||
|   /** When a successful reconnect has been made */ |   /** When a reconnect was requested by Discord */ | ||||||
|   reconnect: [shard: number] |   reconnect: [shard: number] | ||||||
|   /** When a successful session resume has been done */ |   /** When a successful session resume has been done */ | ||||||
|   resumed: [shard: number] |   resumed: [shard: number] | ||||||
|  | @ -178,25 +179,28 @@ export type ClientEvents = { | ||||||
|    * @param guild Guild in which Emoji was added |    * @param guild Guild in which Emoji was added | ||||||
|    * @param emoji The Emoji which was added |    * @param emoji The Emoji which was added | ||||||
|    */ |    */ | ||||||
|   guildEmojiAdd: [guild: Guild, emoji: Emoji] |   guildEmojiAdd: [emoji: Emoji] | ||||||
|   /** |   /** | ||||||
|    * An Emoji was deleted from Guild |    * An Emoji was deleted from Guild | ||||||
|    * @param guild Guild from which Emoji was deleted |  | ||||||
|    * @param emoji Emoji which was deleted |    * @param emoji Emoji which was deleted | ||||||
|    */ |    */ | ||||||
|   guildEmojiDelete: [Guild, Emoji] |   guildEmojiDelete: [emoji: Emoji] | ||||||
|   /** |   /** | ||||||
|    * An Emoji in a Guild was updated |    * An Emoji in a Guild was updated | ||||||
|    * @param guild Guild in which Emoji was updated |  | ||||||
|    * @param before Emoji object before update |    * @param before Emoji object before update | ||||||
|    * @param after Emoji object after update |    * @param after Emoji object after update | ||||||
|    */ |    */ | ||||||
|   guildEmojiUpdate: [guild: Guild, before: Emoji, after: Emoji] |   guildEmojiUpdate: [before: Emoji, after: Emoji] | ||||||
|   /** |   /** | ||||||
|    * Guild's Integrations were updated |    * Guild's Integrations were updated | ||||||
|    * @param guild The Guild object |    * @param guild The Guild object | ||||||
|    */ |    */ | ||||||
|   guildIntegrationsUpdate: [guild: Guild] |   guildIntegrationsUpdate: [guild: Guild] | ||||||
|  |   /** | ||||||
|  |    * Guild's Emojis were updated | ||||||
|  |    * @param guild The Guild object | ||||||
|  |    */ | ||||||
|  |   guildEmojisUpdate: [guild: Guild] | ||||||
|   /** |   /** | ||||||
|    * A new Member has joined a Guild |    * A new Member has joined a Guild | ||||||
|    * @param member The Member object |    * @param member The Member object | ||||||
|  |  | ||||||
|  | @ -4,5 +4,6 @@ export const reconnect: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|   d: any |   d: any | ||||||
| ) => { | ) => { | ||||||
|  |   gateway.client.emit('reconnect', gateway.shards?.[0] ?? 0) | ||||||
|   gateway.reconnect() |   gateway.reconnect() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ export class Message extends SnowflakeBase { | ||||||
|   author: User |   author: User | ||||||
|   member?: Member |   member?: Member | ||||||
|   content: string |   content: string | ||||||
|   editedTimestamp?: string |   editedTimestamp?: Date | ||||||
|   tts: boolean |   tts: boolean | ||||||
|   mentions: MessageMentions |   mentions: MessageMentions | ||||||
|   attachments: Attachment[] |   attachments: Attachment[] | ||||||
|  | @ -62,7 +62,10 @@ export class Message extends SnowflakeBase { | ||||||
|     this.guildID = data.guild_id |     this.guildID = data.guild_id | ||||||
|     this.author = author |     this.author = author | ||||||
|     this.content = data.content |     this.content = data.content | ||||||
|     this.editedTimestamp = data.edited_timestamp |     this.editedTimestamp = | ||||||
|  |       data.edited_timestamp === undefined | ||||||
|  |         ? undefined | ||||||
|  |         : new Date(data.edited_timestamp) | ||||||
|     this.tts = data.tts |     this.tts = data.tts | ||||||
|     this.mentions = new MessageMentions(this.client, this) |     this.mentions = new MessageMentions(this.client, this) | ||||||
|     this.attachments = data.attachments |     this.attachments = data.attachments | ||||||
|  | @ -89,7 +92,10 @@ export class Message extends SnowflakeBase { | ||||||
|     this.channelID = data.channel_id ?? this.channelID |     this.channelID = data.channel_id ?? this.channelID | ||||||
|     this.guildID = data.guild_id ?? this.guildID |     this.guildID = data.guild_id ?? this.guildID | ||||||
|     this.content = data.content ?? this.content |     this.content = data.content ?? this.content | ||||||
|     this.editedTimestamp = data.edited_timestamp ?? this.editedTimestamp |     this.editedTimestamp = | ||||||
|  |       data.edited_timestamp === undefined | ||||||
|  |         ? this.editedTimestamp | ||||||
|  |         : new Date(data.edited_timestamp) | ||||||
|     this.tts = data.tts ?? this.tts |     this.tts = data.tts ?? this.tts | ||||||
|     this.attachments = data.attachments ?? this.attachments |     this.attachments = data.attachments ?? this.attachments | ||||||
|     this.embeds = data.embeds.map((v) => new Embed(v)) ?? this.embeds |     this.embeds = data.embeds.map((v) => new Embed(v)) ?? this.embeds | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { SnowflakeBase } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { RoleModifyPayload, RolePayload } from '../types/role.ts' | import { RoleModifyPayload, RolePayload } from '../types/role.ts' | ||||||
| import { Permissions } from '../utils/permissions.ts' | import { Permissions } from '../utils/permissions.ts' | ||||||
| import { Guild } from './guild.ts' | import { Guild } from './guild.ts' | ||||||
| 
 | 
 | ||||||
| export class Role extends SnowflakeBase { | export class Role extends Base { | ||||||
|   id: string |   id: string | ||||||
|   guild: Guild |   guild: Guild | ||||||
|   name: string |   name: string | ||||||
|  |  | ||||||
|  | @ -24,6 +24,7 @@ import { Channel } from './channel.ts' | ||||||
| import { Embed } from './embed.ts' | import { Embed } from './embed.ts' | ||||||
| import { Emoji } from './emoji.ts' | import { Emoji } from './emoji.ts' | ||||||
| import { Guild } from './guild.ts' | import { Guild } from './guild.ts' | ||||||
|  | import { CategoryChannel } from './guildCategoryChannel.ts' | ||||||
| import { Invite } from './invite.ts' | import { Invite } from './invite.ts' | ||||||
| import { Member } from './member.ts' | import { Member } from './member.ts' | ||||||
| import { Message } from './message.ts' | import { Message } from './message.ts' | ||||||
|  | @ -244,7 +245,7 @@ export class GuildTextChannel extends TextChannel { | ||||||
|   permissionOverwrites: Overwrite[] |   permissionOverwrites: Overwrite[] | ||||||
|   nsfw: boolean |   nsfw: boolean | ||||||
|   parentID?: string |   parentID?: string | ||||||
|   rateLimit: number |   slowmode: number | ||||||
|   topic?: string |   topic?: string | ||||||
|   guild: Guild |   guild: Guild | ||||||
| 
 | 
 | ||||||
|  | @ -266,7 +267,7 @@ export class GuildTextChannel extends TextChannel { | ||||||
|     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.slowmode = data.rate_limit_per_user | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   readFromData(data: GuildTextChannelPayload): void { |   readFromData(data: GuildTextChannelPayload): void { | ||||||
|  | @ -279,7 +280,7 @@ export class GuildTextChannel extends TextChannel { | ||||||
|     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.slowmode = data.rate_limit_per_user ?? this.slowmode | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Edit the Guild Text Channel */ |   /** Edit the Guild Text Channel */ | ||||||
|  | @ -290,7 +291,10 @@ export class GuildTextChannel extends TextChannel { | ||||||
|       name: options?.name, |       name: options?.name, | ||||||
|       position: options?.position, |       position: options?.position, | ||||||
|       permission_overwrites: options?.permissionOverwrites, |       permission_overwrites: options?.permissionOverwrites, | ||||||
|       parent_id: options?.parentID |       parent_id: options?.parentID, | ||||||
|  |       nsfw: options?.nsfw, | ||||||
|  |       topic: options?.topic, | ||||||
|  |       rate_limit_per_user: options?.rateLimitPerUser | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const resp = await this.client.rest.patch(CHANNEL(this.id), body) |     const resp = await this.client.rest.patch(CHANNEL(this.id), body) | ||||||
|  | @ -388,4 +392,69 @@ export class GuildTextChannel extends TextChannel { | ||||||
|       .remove(memberOWs.length === 0 ? 0 : memberOWs.map((e) => Number(e.deny))) |       .remove(memberOWs.length === 0 ? 0 : memberOWs.map((e) => Number(e.deny))) | ||||||
|       .add(memberOWs.length === 0 ? 0 : memberOWs.map((e) => Number(e.allow))) |       .add(memberOWs.length === 0 ? 0 : memberOWs.map((e) => Number(e.allow))) | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit name of the channel */ | ||||||
|  |   async setName(name: string): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ name }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit topic of the channel */ | ||||||
|  |   async setTopic(topic: string): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ topic }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit topic of the channel */ | ||||||
|  |   async setCategory( | ||||||
|  |     category: CategoryChannel | string | ||||||
|  |   ): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ | ||||||
|  |       parentID: typeof category === 'object' ? category.id : category | ||||||
|  |     }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit position of the channel */ | ||||||
|  |   async setPosition(position: number): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ position }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit Slowmode of the channel */ | ||||||
|  |   async setSlowmode(slowmode?: number | null): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ rateLimitPerUser: slowmode ?? null }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit NSFW property of the channel */ | ||||||
|  |   async setNSFW(nsfw: boolean): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ nsfw }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Set Permission Overwrites of the Channel */ | ||||||
|  |   async setOverwrites(overwrites: Overwrite[]): Promise<GuildTextChannel> { | ||||||
|  |     return await this.edit({ permissionOverwrites: overwrites }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Add a Permission Overwrite */ | ||||||
|  |   async addOverwrite(overwrite: Overwrite): Promise<GuildTextChannel> { | ||||||
|  |     const overwrites = this.permissionOverwrites | ||||||
|  |     overwrites.push(overwrite) | ||||||
|  |     return await this.edit({ permissionOverwrites: overwrites }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Remove a Permission Overwrite */ | ||||||
|  |   async removeOverwrite(id: string): Promise<GuildTextChannel> { | ||||||
|  |     if (this.permissionOverwrites.findIndex((e) => e.id === id) < 0) | ||||||
|  |       throw new Error('Permission Overwrite not found') | ||||||
|  |     const overwrites = this.permissionOverwrites.filter((e) => e.id !== id) | ||||||
|  |     return await this.edit({ permissionOverwrites: overwrites }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit a Permission Overwrite */ | ||||||
|  |   async editOverwrite(overwrite: Overwrite): Promise<GuildTextChannel> { | ||||||
|  |     const index = this.permissionOverwrites.findIndex( | ||||||
|  |       (e) => e.id === overwrite.id | ||||||
|  |     ) | ||||||
|  |     if (index < 0) throw new Error('Permission Overwrite not found') | ||||||
|  |     const overwrites = this.permissionOverwrites | ||||||
|  |     overwrites[index] = overwrite | ||||||
|  |     return await this.edit({ permissionOverwrites: overwrites }) | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue