Add guild edit feature, fix some types
This commit is contained in:
		
							parent
							
								
									7e11b8a351
								
							
						
					
					
						commit
						19e2020e38
					
				
					 3 changed files with 123 additions and 7 deletions
				
			
		|  | @ -12,7 +12,9 @@ import { | ||||||
|   GuildCreateChannelOptions, |   GuildCreateChannelOptions, | ||||||
|   GuildCreateChannelPayload, |   GuildCreateChannelPayload, | ||||||
|   GuildPreview, |   GuildPreview, | ||||||
|   GuildPreviewPayload |   GuildPreviewPayload, | ||||||
|  |   GuildModifyOptions, | ||||||
|  |   GuildModifyPayload | ||||||
| } from '../types/guild.ts' | } from '../types/guild.ts' | ||||||
| import { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| import { MembersManager } from './members.ts' | import { MembersManager } from './members.ts' | ||||||
|  | @ -133,4 +135,74 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | ||||||
| 
 | 
 | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   async edit( | ||||||
|  |     guildID: string, | ||||||
|  |     options: GuildModifyOptions, | ||||||
|  |     asRaw: false | ||||||
|  |   ): Promise<Guild> | ||||||
|  |   async edit( | ||||||
|  |     guildID: string, | ||||||
|  |     options: GuildModifyOptions, | ||||||
|  |     asRaw: true | ||||||
|  |   ): Promise<GuildPayload> | ||||||
|  |   async edit( | ||||||
|  |     guildID: string, | ||||||
|  |     options: GuildModifyOptions, | ||||||
|  |     asRaw: boolean = false | ||||||
|  |   ): Promise<Guild | GuildPayload> { | ||||||
|  |     if ( | ||||||
|  |       options.icon !== undefined && | ||||||
|  |       options.icon !== null && | ||||||
|  |       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
 | ||||||
|  |       !options.icon.startsWith('data:') | ||||||
|  |     ) { | ||||||
|  |       options.icon = await fetchAuto(options.icon) | ||||||
|  |     } | ||||||
|  |     if ( | ||||||
|  |       options.splash !== undefined && | ||||||
|  |       options.splash !== null && | ||||||
|  |       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
 | ||||||
|  |       !options.splash.startsWith('data:') | ||||||
|  |     ) { | ||||||
|  |       options.splash = await fetchAuto(options.splash) | ||||||
|  |     } | ||||||
|  |     if ( | ||||||
|  |       options.banner !== undefined && | ||||||
|  |       options.banner !== null && | ||||||
|  |       // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
 | ||||||
|  |       !options.banner.startsWith('data:') | ||||||
|  |     ) { | ||||||
|  |       options.banner = await fetchAuto(options.banner) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const body: GuildModifyPayload = { | ||||||
|  |       name: options.name, | ||||||
|  |       region: options.region, | ||||||
|  |       verification_level: options.verificationLevel, | ||||||
|  |       default_message_notifications: options.defaultMessageNotifications, | ||||||
|  |       explicit_content_filter: options.explicitContentFilter, | ||||||
|  |       afk_channel_id: options.afkChannelID, | ||||||
|  |       afk_timeout: options.afkTimeout, | ||||||
|  |       icon: options.icon, | ||||||
|  |       splash: options.splash, | ||||||
|  |       banner: options.banner, | ||||||
|  |       system_channel_id: options.systemChannelID, | ||||||
|  |       rules_channel_id: options.rulesChannelID, | ||||||
|  |       public_updates_channel_id: options.publicUpdatesChannelID, | ||||||
|  |       preferred_locale: options.preferredLocale | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const result: GuildPayload = await this.client.rest.patch( | ||||||
|  |       GUILD(guildID), | ||||||
|  |       body | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |     if (asRaw) { | ||||||
|  |       const guild = new Guild(this.client, result) | ||||||
|  |       return guild | ||||||
|  |     } else { | ||||||
|  |       return result | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,7 +8,10 @@ import { | ||||||
|   IntegrationExpireBehavior, |   IntegrationExpireBehavior, | ||||||
|   Verification, |   Verification, | ||||||
|   GuildChannels, |   GuildChannels, | ||||||
|   GuildPreview |   GuildPreview, | ||||||
|  |   MessageNotification, | ||||||
|  |   ContentFilter, | ||||||
|  |   GuildModifyOptions | ||||||
| } from '../types/guild.ts' | } from '../types/guild.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts' | import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts' | ||||||
|  | @ -134,8 +137,8 @@ export class Guild extends Base { | ||||||
|   widgetEnabled?: boolean |   widgetEnabled?: boolean | ||||||
|   widgetChannelID?: string |   widgetChannelID?: string | ||||||
|   verificationLevel?: Verification |   verificationLevel?: Verification | ||||||
|   defaultMessageNotifications?: number |   defaultMessageNotifications?: MessageNotification | ||||||
|   explicitContentFilter?: number |   explicitContentFilter?: ContentFilter | ||||||
|   roles: RolesManager |   roles: RolesManager | ||||||
|   emojis: GuildEmojisManager |   emojis: GuildEmojisManager | ||||||
|   invites: InviteManager |   invites: InviteManager | ||||||
|  | @ -332,6 +335,13 @@ export class Guild extends Base { | ||||||
|   async preview(): Promise<GuildPreview> { |   async preview(): Promise<GuildPreview> { | ||||||
|     return this.client.guilds.preview(this.id) |     return this.client.guilds.preview(this.id) | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   async edit(options: GuildModifyOptions): Promise<Guild> { | ||||||
|  |     const result = await this.client.guilds.edit(this.id, options, true) | ||||||
|  |     this.readFromData(result) | ||||||
|  | 
 | ||||||
|  |     return new Guild(this.client, result) | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class GuildIntegration extends Base { | export class GuildIntegration extends Base { | ||||||
|  |  | ||||||
|  | @ -32,8 +32,8 @@ export interface GuildPayload { | ||||||
|   widget_enabled?: boolean |   widget_enabled?: boolean | ||||||
|   widget_channel_id?: string |   widget_channel_id?: string | ||||||
|   verification_level: Verification |   verification_level: Verification | ||||||
|   default_message_notifications: number |   default_message_notifications: MessageNotification | ||||||
|   explicit_content_filter: number |   explicit_content_filter: ContentFilter | ||||||
|   roles: RolePayload[] |   roles: RolePayload[] | ||||||
|   emojis: EmojiPayload[] |   emojis: EmojiPayload[] | ||||||
|   features: GuildFeatures[] |   features: GuildFeatures[] | ||||||
|  | @ -83,7 +83,7 @@ export enum MessageNotification { | ||||||
| export enum ContentFilter { | export enum ContentFilter { | ||||||
|   DISABLED = 0, |   DISABLED = 0, | ||||||
|   MEMBERS_WITHOUT_ROLES = 1, |   MEMBERS_WITHOUT_ROLES = 1, | ||||||
|   ALL_MEMBERS = 3 |   ALL_MEMBERS = 2 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum MFA { | export enum MFA { | ||||||
|  | @ -231,3 +231,37 @@ export interface GuildPreview { | ||||||
|   approximatePresenceCount: number |   approximatePresenceCount: number | ||||||
|   description: string | null |   description: string | null | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export interface GuildModifyPayload { | ||||||
|  |   name?: string | ||||||
|  |   region?: string | null | ||||||
|  |   verification_level?: Verification | null | ||||||
|  |   default_message_notifications?: MessageNotification | null | ||||||
|  |   explicit_content_filter?: ContentFilter | null | ||||||
|  |   afk_channel_id?: string | null | ||||||
|  |   afk_timeout?: number | ||||||
|  |   icon?: string | null | ||||||
|  |   splash?: string | null | ||||||
|  |   banner?: string | null | ||||||
|  |   system_channel_id?: string | null | ||||||
|  |   rules_channel_id?: string | null | ||||||
|  |   public_updates_channel_id?: string | null | ||||||
|  |   preferred_locale?: string | null | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface GuildModifyOptions { | ||||||
|  |   name?: string | ||||||
|  |   region?: string | null | ||||||
|  |   verificationLevel?: Verification | null | ||||||
|  |   defaultMessageNotifications?: MessageNotification | null | ||||||
|  |   explicitContentFilter?: ContentFilter | null | ||||||
|  |   afkChannelID?: string | null | ||||||
|  |   afkTimeout?: number | ||||||
|  |   icon?: string | null | ||||||
|  |   splash?: string | null | ||||||
|  |   banner?: string | null | ||||||
|  |   systemChannelID?: string | null | ||||||
|  |   rulesChannelID?: string | null | ||||||
|  |   publicUpdatesChannelID?: string | null | ||||||
|  |   preferredLocale?: string | null | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue