feat: member screening types update
This commit is contained in:
		
							parent
							
								
									a9338ad88a
								
							
						
					
					
						commit
						94a447921d
					
				
					 7 changed files with 115 additions and 34 deletions
				
			
		|  | @ -410,6 +410,7 @@ export class RESTManager { | |||
|           const query = | ||||
|             method === 'get' && body !== undefined | ||||
|               ? Object.entries(body as any) | ||||
|                   .filter(([k, v]) => v !== undefined) | ||||
|                   .map( | ||||
|                     ([key, value]) => | ||||
|                       `${encodeURIComponent(key)}=${encodeURIComponent( | ||||
|  |  | |||
|  | @ -46,6 +46,10 @@ export class Message extends Base { | |||
|   flags?: number | ||||
|   stickers?: MessageSticker[] | ||||
| 
 | ||||
|   get createdAt(): Date { | ||||
|     return new Date(this.timestamp) | ||||
|   } | ||||
| 
 | ||||
|   constructor( | ||||
|     client: Client, | ||||
|     data: MessagePayload, | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ import { Client } from '../models/client.ts' | |||
| import { | ||||
|   GuildTextChannelPayload, | ||||
|   MessageOption, | ||||
|   MessagePayload, | ||||
|   MessageReference, | ||||
|   ModifyGuildTextChannelOption, | ||||
|   ModifyGuildTextChannelPayload, | ||||
|  | @ -14,6 +15,7 @@ import { | |||
|   CHANNEL_MESSAGE, | ||||
|   CHANNEL_MESSAGES | ||||
| } from '../types/endpoint.ts' | ||||
| import { Collection } from '../utils/collection.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| import { Embed } from './embed.ts' | ||||
| import { Guild } from './guild.ts' | ||||
|  | @ -124,6 +126,48 @@ export class TextChannel extends Channel { | |||
|     await res.mentions.fromPayload(newMsg) | ||||
|     return res | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * Fetch Messages of a Channel | ||||
|    * @param options Options to configure fetching Messages | ||||
|    */ | ||||
|   async fetchMessages(options?: { | ||||
|     limit?: number | ||||
|     around?: Message | string | ||||
|     before?: Message | string | ||||
|     after?: Message | string | ||||
|   }): Promise<Collection<string, Message>> { | ||||
|     const res = new Collection<string, Message>() | ||||
|     const raws = (await this.client.rest.api.channels[this.id].messages.get({ | ||||
|       limit: options?.limit ?? 50, | ||||
|       around: | ||||
|         options?.around === undefined | ||||
|           ? undefined | ||||
|           : typeof options.around === 'string' | ||||
|           ? options.around | ||||
|           : options.around.id, | ||||
|       before: | ||||
|         options?.before === undefined | ||||
|           ? undefined | ||||
|           : typeof options.before === 'string' | ||||
|           ? options.before | ||||
|           : options.before.id, | ||||
|       after: | ||||
|         options?.after === undefined | ||||
|           ? undefined | ||||
|           : typeof options.after === 'string' | ||||
|           ? options.after | ||||
|           : options.after.id | ||||
|     })) as MessagePayload[] | ||||
| 
 | ||||
|     for (const raw of raws) { | ||||
|       await this.messages.set(raw.id, raw) | ||||
|       const msg = ((await this.messages.get(raw.id)) as unknown) as Message | ||||
|       res.set(msg.id, msg) | ||||
|     } | ||||
| 
 | ||||
|     return res | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export class GuildTextChannel extends TextChannel { | ||||
|  | @ -185,4 +229,40 @@ export class GuildTextChannel extends TextChannel { | |||
| 
 | ||||
|     return new GuildTextChannel(this.client, resp, this.guild) | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * Bulk Delete Messages in a Guild Text Channel | ||||
|    * @param messages Messages to delete. Can be a number, or Array of Message or IDs | ||||
|    */ | ||||
|   async bulkDelete( | ||||
|     messages: Array<Message | string> | number | ||||
|   ): Promise<GuildTextChannel> { | ||||
|     let ids: string[] = [] | ||||
| 
 | ||||
|     if (Array.isArray(messages)) | ||||
|       ids = messages.map((e) => (typeof e === 'string' ? e : e.id)) | ||||
|     else { | ||||
|       let list = await this.messages.array() | ||||
|       if (list.length < messages) list = (await this.fetchMessages()).array() | ||||
|       ids = list | ||||
|         .sort((b, a) => a.createdAt.getTime() - b.createdAt.getTime()) | ||||
|         .filter((e, i) => i < messages) | ||||
|         .filter( | ||||
|           (e) => | ||||
|             new Date().getTime() - e.createdAt.getTime() <= | ||||
|             1000 * 60 * 60 * 24 * 14 | ||||
|         ) | ||||
|         .map((e) => e.id) | ||||
|     } | ||||
| 
 | ||||
|     ids = [...new Set(ids)] | ||||
|     if (ids.length < 2 || ids.length > 100) | ||||
|       throw new Error('bulkDelete can only delete messages in range 2-100') | ||||
| 
 | ||||
|     await this.client.rest.api.channels[this.id].messages['bulk-delete'].post({ | ||||
|       messages: ids | ||||
|     }) | ||||
| 
 | ||||
|     return this | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -7,7 +7,8 @@ import { | |||
|   groupslash, | ||||
|   CommandContext, | ||||
|   Extension, | ||||
|   Collection | ||||
|   Collection, | ||||
|   GuildTextChannel | ||||
| } from '../../mod.ts' | ||||
| import { LL_IP, LL_PASS, LL_PORT, TOKEN } from './config.ts' | ||||
| import { | ||||
|  | @ -69,6 +70,17 @@ class MyClient extends CommandClient { | |||
|     d.respond({ content: 'sub-cmd-group worked' }) | ||||
|   } | ||||
| 
 | ||||
|   @command() | ||||
|   rmrf(ctx: CommandContext): any { | ||||
|     if (ctx.author.id !== '422957901716652033') return | ||||
|     ;((ctx.channel as any) as GuildTextChannel) | ||||
|       .bulkDelete(3) | ||||
|       .then((chan) => { | ||||
|         ctx.channel.send(`Bulk deleted 2 in ${chan}`) | ||||
|       }) | ||||
|       .catch((e) => ctx.channel.send(`${e.message}`)) | ||||
|   } | ||||
| 
 | ||||
|   @slash() | ||||
|   run(d: Interaction): void { | ||||
|     console.log(d.name) | ||||
|  |  | |||
|  | @ -1,36 +1,16 @@ | |||
| import { SlashClient, SlashBuilder } from '../models/slashClient.ts' | ||||
| import { SlashClient } from '../models/slashClient.ts' | ||||
| import { SlashCommandPartial } from '../types/slash.ts' | ||||
| import { TOKEN } from './config.ts' | ||||
| 
 | ||||
| const slash = new SlashClient({ token: TOKEN }) | ||||
| export const slash = new SlashClient({ token: TOKEN }) | ||||
| 
 | ||||
| slash.commands.all().then(console.log) | ||||
| // Cmd objects come here
 | ||||
| const commands: SlashCommandPartial[] = [] | ||||
| 
 | ||||
| const cmd = new SlashBuilder() | ||||
|   .name('searchmusic') | ||||
|   .description('Search for music.') | ||||
|   .option((o) => | ||||
|     o.string({ name: 'query', description: 'Query to search with.' }) | ||||
|   ) | ||||
|   .option((o) => | ||||
|     o.string({ | ||||
|       name: 'engine', | ||||
|       description: 'Search engine to use.', | ||||
|       choices: [{ name: 'YouTube', value: 'youtube' }, 'Spotify'] | ||||
| console.log('Creating...') | ||||
| commands.forEach((cmd) => { | ||||
|   slash.commands | ||||
|     .create(cmd, '!! Your testing guild ID comes here !!') | ||||
|     .then((c) => console.log(`Created command ${c.name}!`)) | ||||
|     .catch((e) => `Failed to create ${cmd.name} - ${e.message}`) | ||||
| }) | ||||
|   ) | ||||
|   .options({ | ||||
|     query: { | ||||
|       description: 'Query UWU', | ||||
|       type: 3 | ||||
|     }, | ||||
|     engine: { | ||||
|       description: 'Engine UWU', | ||||
|       type: 3, | ||||
|       choices: [ | ||||
|         { name: 'YouTube', value: 'youtube' }, | ||||
|         { name: 'Spotify', value: 'spotify' } | ||||
|       ] | ||||
|     } | ||||
|   }) | ||||
| 
 | ||||
| console.log(JSON.stringify(cmd.export())) | ||||
|  |  | |||
|  | @ -62,6 +62,7 @@ export interface MemberPayload { | |||
|   premium_since?: string | ||||
|   deaf: boolean | ||||
|   mute: boolean | ||||
|   pending?: boolean | ||||
| } | ||||
| 
 | ||||
| export enum MessageNotification { | ||||
|  | @ -113,6 +114,9 @@ export type GuildFeatures = | |||
|   | 'FEATURABLE' | ||||
|   | 'ANIMATED_ICON' | ||||
|   | 'BANNER' | ||||
|   | 'WELCOME_SCREEN_ENABLED' | ||||
|   | 'MEMBER_VERIFICATION_GATE_ENABLED' | ||||
|   | 'PREVIEW_ENABLED' | ||||
| 
 | ||||
| export enum IntegrationExpireBehavior { | ||||
|   REMOVE_ROLE = 0, | ||||
|  |  | |||
|  | @ -50,7 +50,7 @@ export interface SlashCommandChoice { | |||
|   /** (Display) name of the Choice */ | ||||
|   name: string | ||||
|   /** Actual value to be sent in Interaction */ | ||||
|   value: string | ||||
|   value: any | ||||
| } | ||||
| 
 | ||||
| export enum SlashCommandOptionType { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue