Merge branch 'main' into main
This commit is contained in:
		
						commit
						b15c5fb79d
					
				
					 22 changed files with 363 additions and 220 deletions
				
			
		|  | @ -14,4 +14,4 @@ export const guildBanRemove: GatewayEventHandler = async ( | |||
|   if (guild !== undefined) { | ||||
|     gateway.client.emit('guildBanRemove', guild, user) | ||||
|   } | ||||
| } | ||||
| } | ||||
|  | @ -6,47 +6,58 @@ import { GuildChannelPayload } from '../../types/channel.ts' | |||
| import { RolePayload } from '../../types/role.ts' | ||||
| import { RolesManager } from '../../managers/roles.ts' | ||||
| 
 | ||||
| export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: GuildPayload) => { | ||||
| export const guildCreate: GatewayEventHandler = async ( | ||||
|   gateway: Gateway, | ||||
|   d: GuildPayload | ||||
| ) => { | ||||
|   let guild: Guild | undefined = await gateway.client.guilds.get(d.id) | ||||
|   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
 | ||||
|     await gateway.client.guilds.set(d.id, d) | ||||
| 
 | ||||
|     if (d.members !== undefined) { | ||||
|       const members = new MembersManager(gateway.client, guild) | ||||
|       await members.fromPayload(d.members as MemberPayload[]) | ||||
|       guild.members = members | ||||
|     } | ||||
| 
 | ||||
|     if (d.channels !== undefined) { | ||||
|       for (const ch of d.channels as GuildChannelPayload[]) { | ||||
|         ch.guild_id = d.id | ||||
|         await gateway.client.channels.set(ch.id, ch) | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     if (d.roles !== undefined) { | ||||
|       const roles = new RolesManager(gateway.client, guild) | ||||
|       await roles.fromPayload(d.roles as RolePayload[]) | ||||
|       guild.roles = roles | ||||
|     } | ||||
| 
 | ||||
|     guild.refreshFromData(d) | ||||
|   } else { | ||||
|     await gateway.client.guilds.set(d.id, d) | ||||
|     guild = new Guild(gateway.client, d) | ||||
| 
 | ||||
|     if ((d as any).members !== undefined) { | ||||
|       const members = new MembersManager(gateway.client, guild) | ||||
|       await members.fromPayload(d.members as MemberPayload[]) | ||||
|       guild.members = members | ||||
|     } | ||||
| 
 | ||||
|     if (d.channels !== undefined) { | ||||
|       for (const ch of d.channels as GuildChannelPayload[]) { | ||||
|         (ch as any).guild_id = d.id | ||||
|         ;(ch as any).guild_id = d.id | ||||
|         await gateway.client.channels.set(ch.id, ch) | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     if (d.roles !== undefined) { | ||||
|       const roles = new RolesManager(gateway.client, guild) | ||||
|       await roles.fromPayload(d.roles) | ||||
|       guild.roles = roles | ||||
|     } | ||||
| 
 | ||||
|     await guild.roles.fromPayload(d.roles) | ||||
|     guild = new Guild(gateway.client, d) | ||||
|     gateway.client.emit('guildCreate', guild) | ||||
|  |  | |||
|  | @ -10,10 +10,12 @@ export const guildDelte: GatewayEventHandler = async ( | |||
| 
 | ||||
|   if (guild !== undefined) { | ||||
|     guild.refreshFromData(d) | ||||
| 
 | ||||
|     await guild.members.flush() | ||||
|     await guild.channels.flush() | ||||
|     await guild.roles.flush() | ||||
|     await gateway.client.guilds.delete(d.id) | ||||
| 
 | ||||
|     gateway.client.emit('guildDelete', guild) | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -36,7 +36,7 @@ class Gateway { | |||
|   client: Client | ||||
|   cache: GatewayCache | ||||
| 
 | ||||
|   constructor(client: Client, token: string, intents: GatewayIntents[]) { | ||||
|   constructor (client: Client, token: string, intents: GatewayIntents[]) { | ||||
|     this.token = token | ||||
|     this.intents = intents | ||||
|     this.client = client | ||||
|  | @ -53,12 +53,12 @@ class Gateway { | |||
|     this.websocket.onerror = this.onerror.bind(this) | ||||
|   } | ||||
| 
 | ||||
|   private onopen(): void { | ||||
|   private onopen (): void { | ||||
|     this.connected = true | ||||
|     this.debug('Connected to Gateway!') | ||||
|   } | ||||
| 
 | ||||
|   private async onmessage(event: MessageEvent): Promise<void> { | ||||
|   private async onmessage (event: MessageEvent): Promise<void> { | ||||
|     let data = event.data | ||||
|     if (data instanceof ArrayBuffer) { | ||||
|       data = new Uint8Array(data) | ||||
|  | @ -140,7 +140,7 @@ class Gateway { | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private onclose(event: CloseEvent): void { | ||||
|   private onclose (event: CloseEvent): void { | ||||
|     this.debug(`Connection Closed with code: ${event.code}`) | ||||
| 
 | ||||
|     if (event.code === GatewayCloseCodes.UNKNOWN_ERROR) { | ||||
|  | @ -184,12 +184,12 @@ class Gateway { | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private onerror(event: Event | ErrorEvent): void { | ||||
|   private onerror (event: Event | ErrorEvent): void { | ||||
|     const eventError = event as ErrorEvent | ||||
|     console.log(eventError) | ||||
|   } | ||||
| 
 | ||||
|   private async sendIdentify(forceNewSession?: boolean): Promise<void> { | ||||
|   private async sendIdentify (forceNewSession?: boolean): Promise<void> { | ||||
|     if (this.client.bot === true) { | ||||
|       this.debug('Fetching /gateway/bot...') | ||||
|       const info = await this.client.rest.get(GATEWAY_BOT()) | ||||
|  | @ -219,8 +219,8 @@ class Gateway { | |||
|         token: this.token, | ||||
|         properties: { | ||||
|           $os: Deno.build.os, | ||||
|           $browser: 'discord.deno', // TODO: Change lib name
 | ||||
|           $device: 'discord.deno' | ||||
|           $browser: 'harmony', // TODO: Change lib name
 | ||||
|           $device: 'harmony' | ||||
|         }, | ||||
|         compress: true, | ||||
|         shard: [0, 1], // TODO: Make sharding possible
 | ||||
|  | @ -234,23 +234,23 @@ class Gateway { | |||
| 
 | ||||
|     if (this.client.bot === false) { | ||||
|       // TODO: Complete Selfbot support
 | ||||
|       this.debug("Modify Identify Payload for Self-bot..") | ||||
|       this.debug('Modify Identify Payload for Self-bot..') | ||||
|       // delete payload.d['intents']
 | ||||
|       // payload.d.intents = Intents.None
 | ||||
|       payload.d.presence = null | ||||
|       payload.d.properties = { | ||||
|         $os: "Windows", | ||||
|         $browser: "Firefox", | ||||
|         $device: "" | ||||
|         $os: 'Windows', | ||||
|         $browser: 'Firefox', | ||||
|         $device: '' | ||||
|       } | ||||
| 
 | ||||
|       this.debug("Warn: Support for selfbots is incomplete") | ||||
|       this.debug('Warn: Support for selfbots is incomplete') | ||||
|     } | ||||
| 
 | ||||
|     this.send(payload) | ||||
|   } | ||||
| 
 | ||||
|   private async sendResume(): Promise<void> { | ||||
|   private async sendResume (): Promise<void> { | ||||
|     this.debug(`Preparing to resume with Session: ${this.sessionID}`) | ||||
|     if (this.sequenceID === undefined) { | ||||
|       const cached = await this.cache.get('seq') | ||||
|  | @ -268,11 +268,11 @@ class Gateway { | |||
|     this.send(resumePayload) | ||||
|   } | ||||
| 
 | ||||
|   debug(msg: string): void { | ||||
|   debug (msg: string): void { | ||||
|     this.client.debug('Gateway', msg) | ||||
|   } | ||||
| 
 | ||||
|   async reconnect(forceNew?: boolean): Promise<void> { | ||||
|   async reconnect (forceNew?: boolean): Promise<void> { | ||||
|     clearInterval(this.heartbeatIntervalID) | ||||
|     if (forceNew === undefined || !forceNew) | ||||
|       await this.cache.delete('session_id') | ||||
|  | @ -280,7 +280,7 @@ class Gateway { | |||
|     this.initWebsocket() | ||||
|   } | ||||
| 
 | ||||
|   initWebsocket(): void { | ||||
|   initWebsocket (): void { | ||||
|     this.websocket = new WebSocket( | ||||
|       // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
 | ||||
|       `${DISCORD_GATEWAY_URL}/?v=${DISCORD_API_VERSION}&encoding=json`, | ||||
|  | @ -293,39 +293,41 @@ class Gateway { | |||
|     this.websocket.onerror = this.onerror.bind(this) | ||||
|   } | ||||
| 
 | ||||
|   close(): void { | ||||
|   close (): void { | ||||
|     this.websocket.close(1000) | ||||
|   } | ||||
| 
 | ||||
|   send(data: GatewayResponse): boolean { | ||||
|   send (data: GatewayResponse): boolean { | ||||
|     if (this.websocket.readyState !== this.websocket.OPEN) return false | ||||
|     this.websocket.send(JSON.stringify({ | ||||
|       op: data.op, | ||||
|       d: data.d, | ||||
|       s: typeof data.s === "number" ? data.s : null, | ||||
|       t: data.t === undefined ? null : data.t, | ||||
|     })) | ||||
|     this.websocket.send( | ||||
|       JSON.stringify({ | ||||
|         op: data.op, | ||||
|         d: data.d, | ||||
|         s: typeof data.s === 'number' ? data.s : null, | ||||
|         t: data.t === undefined ? null : data.t | ||||
|       }) | ||||
|     ) | ||||
|     return true | ||||
|   } | ||||
| 
 | ||||
|   sendPresence(data: ClientActivityPayload): void { | ||||
|   sendPresence (data: ClientActivityPayload): void { | ||||
|     this.send({ | ||||
|       op: GatewayOpcodes.PRESENCE_UPDATE, | ||||
|       d: data | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   sendHeartbeat(): void { | ||||
|   sendHeartbeat (): void { | ||||
|     const payload = { | ||||
|       op: GatewayOpcodes.HEARTBEAT, | ||||
|       d: this.sequenceID ?? null | ||||
|     }; | ||||
|     } | ||||
| 
 | ||||
|     this.send(payload) | ||||
|     this.lastPingTimestamp = Date.now() | ||||
|   } | ||||
| 
 | ||||
|   heartbeat(): void { | ||||
|   heartbeat (): void { | ||||
|     if (this.heartbeatServerResponded) { | ||||
|       this.heartbeatServerResponded = false | ||||
|     } else { | ||||
|  |  | |||
|  | @ -1,18 +1,22 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { Emoji } from '../structures/emoji.ts' | ||||
| import { Guild } from '../structures/guild.ts' | ||||
| import { EmojiPayload } from '../types/emoji.ts' | ||||
| import { CHANNEL } from '../types/endpoint.ts' | ||||
| import { GUILD_EMOJI } from '../types/endpoint.ts' | ||||
| import { BaseManager } from './base.ts' | ||||
| 
 | ||||
| export class EmojisManager extends BaseManager<EmojiPayload, Emoji> { | ||||
|   constructor (client: Client) { | ||||
|     super(client, 'emojis', Emoji) | ||||
|   guild: Guild | ||||
| 
 | ||||
|   constructor (client: Client, guild: Guild) { | ||||
|     super(client, `emojis:${guild.id}`, Emoji) | ||||
|     this.guild = guild | ||||
|   } | ||||
| 
 | ||||
|   async fetch (id: string): Promise<Emoji> { | ||||
|     return await new Promise((resolve, reject) => { | ||||
|       this.client.rest | ||||
|         .get(CHANNEL(id)) | ||||
|         .get(GUILD_EMOJI(this.guild.id, id)) | ||||
|         .then(data => { | ||||
|           this.set(id, data as EmojiPayload) | ||||
|           resolve(new Emoji(this.client, data as EmojiPayload)) | ||||
|  |  | |||
|  | @ -13,37 +13,45 @@ import { CHANNEL } from '../types/endpoint.ts' | |||
| import { BaseChildManager } from './baseChild.ts' | ||||
| import { ChannelsManager } from './channels.ts' | ||||
| 
 | ||||
| export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload | ||||
| export type GuildChannelPayloads = | ||||
|   | GuildTextChannelPayload | ||||
|   | GuildVoiceChannelPayload | ||||
|   | GuildChannelCategoryPayload | ||||
| export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel | ||||
| 
 | ||||
| export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads, GuildChannel> { | ||||
| export class GuildChannelsManager extends BaseChildManager< | ||||
|   GuildChannelPayloads, | ||||
|   GuildChannel | ||||
| > { | ||||
|   guild: Guild | ||||
| 
 | ||||
|   constructor(client: Client, parent: ChannelsManager, guild: Guild) { | ||||
|   constructor (client: Client, parent: ChannelsManager, guild: Guild) { | ||||
|     super(client, parent as any) | ||||
|     this.guild = guild | ||||
|   } | ||||
| 
 | ||||
|   async get(id: string): Promise<GuildChannel | undefined> { | ||||
|   async get (id: string): Promise<GuildChannel | undefined> { | ||||
|     const res = await this.parent.get(id) | ||||
|     if (res !== undefined && res.guild.id === this.guild.id) return res | ||||
|     else return undefined | ||||
|   } | ||||
| 
 | ||||
|    | ||||
|   async delete(id: string): Promise<boolean> { | ||||
|     return this.client.rest.delete(CHANNEL(id)) | ||||
|   } | ||||
| 
 | ||||
|   async array(): Promise<GuildChannel[]> { | ||||
|     const arr = await this.parent.array() as Channel[] | ||||
|     return arr.filter((c: any) => c.guild !== undefined && c.guild.id === this.guild.id) as any | ||||
|   async array (): Promise<GuildChannel[]> { | ||||
|     const arr = (await this.parent.array()) as Channel[] | ||||
|     return arr.filter( | ||||
|       (c: any) => c.guild !== undefined && c.guild.id === this.guild.id | ||||
|     ) as any | ||||
|   } | ||||
| 
 | ||||
|   async flush(): Promise<boolean> { | ||||
|   async flush (): Promise<boolean> { | ||||
|     const arr = await this.array() | ||||
|     for (const elem of arr) { | ||||
|       this.parent.delete(elem.id) | ||||
|     } | ||||
|     return true | ||||
|   } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -10,18 +10,26 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|     super(client, 'guilds', Guild) | ||||
|   } | ||||
| 
 | ||||
|   async fetch(id: string): Promise<Guild> { | ||||
|   async fetch (id: string): Promise<Guild> { | ||||
|     return await new Promise((resolve, reject) => { | ||||
|       this.client.rest.get(GUILD(id)).then(async (data: any) => { | ||||
|         this.set(id, data) | ||||
|         const guild = new Guild(this.client, data) | ||||
|         if ((data as GuildPayload).members !== undefined) { | ||||
|           const members = new MembersManager(this.client, guild) | ||||
|           await members.fromPayload((data as GuildPayload).members as MemberPayload[]) | ||||
|           guild.members = members | ||||
|         } | ||||
|         resolve(guild) | ||||
|       }).catch(e => reject(e)) | ||||
|       this.client.rest | ||||
|         .get(GUILD(id)) | ||||
|         .then(async (data: any) => { | ||||
|           this.set(id, data) | ||||
| 
 | ||||
|           const guild = new Guild(this.client, data) | ||||
| 
 | ||||
|           if ((data as GuildPayload).members !== undefined) { | ||||
|             const members = new MembersManager(this.client, guild) | ||||
|             await members.fromPayload( | ||||
|               (data as GuildPayload).members as MemberPayload[] | ||||
|             ) | ||||
|             guild.members = members | ||||
|           } | ||||
| 
 | ||||
|           resolve(guild) | ||||
|         }) | ||||
|         .catch(e => reject(e)) | ||||
|     }) | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -12,29 +12,53 @@ export class MessagesManager extends BaseManager<MessagePayload, Message> { | |||
|     super(client, 'messages', Message) | ||||
|   } | ||||
| 
 | ||||
|   async get(key: string): Promise<Message | undefined> { | ||||
|   async get (key: string): Promise<Message | undefined> { | ||||
|     const raw = await this._get(key) | ||||
|     if (raw === undefined) return | ||||
| 
 | ||||
|     let channel = await this.client.channels.get(raw.channel_id) | ||||
|     if (channel === undefined) channel = await this.client.channels.fetch(raw.channel_id) | ||||
|     if (channel === undefined) return | ||||
|     if (channel === undefined) | ||||
|       channel = await this.client.channels.fetch(raw.channel_id) | ||||
| 
 | ||||
|     const author = new User(this.client, raw.author) | ||||
|     const mentions = new MessageMentions() | ||||
| 
 | ||||
|     return new this.DataType(this.client, raw, channel, author, mentions) as any | ||||
|   } | ||||
| 
 | ||||
|   async fetch(channelID: string, id: string): Promise<Message> { | ||||
|   async fetch (channelID: string, id: string): Promise<Message> { | ||||
|     return await new Promise((resolve, reject) => { | ||||
|       this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => { | ||||
|         this.set(id, data as MessagePayload) | ||||
|         let channel: any = await this.client.channels.get<TextChannel>(channelID) | ||||
|         if (channel === undefined) channel = await this.client.channels.fetch(channelID) | ||||
|         const author = new User(this.client, (data as MessagePayload).author) | ||||
|         await this.client.users.set(author.id, (data as MessagePayload).author) | ||||
|         // TODO: Make this thing work (MessageMentions)
 | ||||
|         const mentions = new MessageMentions() | ||||
|         resolve(new Message(this.client, data as MessagePayload, channel as TextChannel, author, mentions)) | ||||
|       }).catch(e => reject(e)) | ||||
|       this.client.rest | ||||
|         .get(CHANNEL_MESSAGE(channelID, id)) | ||||
|         .then(async data => { | ||||
|           this.set(id, data as MessagePayload) | ||||
| 
 | ||||
|           let channel: any = await this.client.channels.get<TextChannel>( | ||||
|             channelID | ||||
|           ) | ||||
|           if (channel === undefined) | ||||
|             channel = await this.client.channels.fetch(channelID) | ||||
| 
 | ||||
|           const author = new User(this.client, (data as MessagePayload).author) | ||||
|           await this.client.users.set( | ||||
|             author.id, | ||||
|             (data as MessagePayload).author | ||||
|           ) | ||||
| 
 | ||||
|           // TODO: Make this thing work (MessageMentions)
 | ||||
|           const mentions = new MessageMentions() | ||||
| 
 | ||||
|           resolve( | ||||
|             new Message( | ||||
|               this.client, | ||||
|               data as MessagePayload, | ||||
|               channel as TextChannel, | ||||
|               author, | ||||
|               mentions | ||||
|             ) | ||||
|           ) | ||||
|         }) | ||||
|         .catch(e => reject(e)) | ||||
|     }) | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -73,7 +73,11 @@ export class Client extends EventEmitter { | |||
|     this.intents = options.intents | ||||
|     this.forceNewSession = options.forceNewSession | ||||
|     if (options.cache !== undefined) this.cache = options.cache | ||||
|     if (options.presence !== undefined) this.presence = options.presence instanceof ClientPresence ? options.presence : new ClientPresence(options.presence) | ||||
|     if (options.presence !== undefined) | ||||
|       this.presence = | ||||
|         options.presence instanceof ClientPresence | ||||
|           ? options.presence | ||||
|           : new ClientPresence(options.presence) | ||||
|     if (options.bot === false) this.bot = false | ||||
|     if (options.canary === true) this.canary = true | ||||
|   } | ||||
|  | @ -94,7 +98,7 @@ export class Client extends EventEmitter { | |||
| 
 | ||||
|   /** Emit debug event */ | ||||
|   debug (tag: string, msg: string): void { | ||||
|     this.emit("debug", `[${tag}] ${msg}`) | ||||
|     this.emit('debug', `[${tag}] ${msg}`) | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ export interface CommandTexts { | |||
| export const DefaultCommandTexts: CommandTexts = { | ||||
|   GUILD_ONLY: 'This command can only be used in a Server!', | ||||
|   OWNER_ONLY: 'This command can only be used by Bot Owners!', | ||||
|   DMS_ONLY: 'This command can only be used in Bot\'s DMs!', | ||||
|   DMS_ONLY: "This command can only be used in Bot's DMs!", | ||||
|   ERROR: 'An error occured while executing command!' | ||||
| } | ||||
| 
 | ||||
|  | @ -44,7 +44,7 @@ export const massReplace = (text: string, replaces: Replaces): string => { | |||
|   return text | ||||
| } | ||||
| 
 | ||||
| export class CommandClient extends Client { | ||||
| export class CommandClient extends Client implements CommandClientOptions { | ||||
|   prefix: string | string[] | ||||
|   mentionPrefix: boolean | ||||
|   getGuildPrefix: (guildID: string) => PrefixReturnType | ||||
|  | @ -58,23 +58,38 @@ export class CommandClient extends Client { | |||
|   commands: CommandsManager = new CommandsManager(this) | ||||
|   texts: CommandTexts = DefaultCommandTexts | ||||
| 
 | ||||
|   constructor(options: CommandClientOptions) { | ||||
|   constructor (options: CommandClientOptions) { | ||||
|     super(options) | ||||
|     this.prefix = options.prefix | ||||
|     this.mentionPrefix = options.mentionPrefix === undefined ? false : options.mentionPrefix | ||||
|     this.getGuildPrefix = options.getGuildPrefix === undefined ? (id: string) => this.prefix : options.getGuildPrefix | ||||
|     this.getUserPrefix = options.getUserPrefix === undefined ? (id: string) => this.prefix : options.getUserPrefix | ||||
|     this.spacesAfterPrefix = options.spacesAfterPrefix === undefined ? false : options.spacesAfterPrefix | ||||
|     this.betterArgs = options.betterArgs === undefined ? false : options.betterArgs | ||||
|     this.mentionPrefix = | ||||
|       options.mentionPrefix === undefined ? false : options.mentionPrefix | ||||
|     this.getGuildPrefix = | ||||
|       options.getGuildPrefix === undefined | ||||
|         ? (id: string) => this.prefix | ||||
|         : options.getGuildPrefix | ||||
|     this.getUserPrefix = | ||||
|       options.getUserPrefix === undefined | ||||
|         ? (id: string) => this.prefix | ||||
|         : options.getUserPrefix | ||||
|     this.spacesAfterPrefix = | ||||
|       options.spacesAfterPrefix === undefined | ||||
|         ? false | ||||
|         : options.spacesAfterPrefix | ||||
|     this.betterArgs = | ||||
|       options.betterArgs === undefined ? false : options.betterArgs | ||||
|     this.owners = options.owners === undefined ? [] : options.owners | ||||
|     this.allowBots = options.allowBots === undefined ? false : options.allowBots | ||||
|     this.allowDMs = options.allowDMs === undefined ? true : options.allowDMs | ||||
|     this.caseSensitive = options.caseSensitive === undefined ? false : options.caseSensitive | ||||
|     this.caseSensitive = | ||||
|       options.caseSensitive === undefined ? false : options.caseSensitive | ||||
| 
 | ||||
|     this.on('messageCreate', async (msg: Message) => await this.processMessage(msg)) | ||||
|     this.on( | ||||
|       'messageCreate', | ||||
|       async (msg: Message) => await this.processMessage(msg) | ||||
|     ) | ||||
|   } | ||||
| 
 | ||||
|   async processMessage(msg: Message): Promise<any> { | ||||
|   async processMessage (msg: Message): Promise<any> { | ||||
|     if (!this.allowBots && msg.author.bot === true) return | ||||
| 
 | ||||
|     let prefix: string | string[] = this.prefix | ||||
|  | @ -113,15 +128,18 @@ export class CommandClient extends Client { | |||
|     } | ||||
| 
 | ||||
|     if (command.guildOnly === true && msg.guild === undefined) { | ||||
|       if (this.texts.GUILD_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.GUILD_ONLY, baseReplaces) | ||||
|       if (this.texts.GUILD_ONLY !== undefined) | ||||
|         return this.sendProcessedText(msg, this.texts.GUILD_ONLY, baseReplaces) | ||||
|       return | ||||
|     } | ||||
|     if (command.dmOnly === true && msg.guild !== undefined) { | ||||
|       if (this.texts.DMS_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.DMS_ONLY, baseReplaces) | ||||
|       if (this.texts.DMS_ONLY !== undefined) | ||||
|         return this.sendProcessedText(msg, this.texts.DMS_ONLY, baseReplaces) | ||||
|       return | ||||
|     } | ||||
|     if (command.ownerOnly === true && !this.owners.includes(msg.author.id)) { | ||||
|       if (this.texts.OWNER_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.OWNER_ONLY, baseReplaces) | ||||
|       if (this.texts.OWNER_ONLY !== undefined) | ||||
|         return this.sendProcessedText(msg, this.texts.OWNER_ONLY, baseReplaces) | ||||
|       return | ||||
|     } | ||||
| 
 | ||||
|  | @ -151,16 +169,20 @@ export class CommandClient extends Client { | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   sendProcessedText(msg: Message, text: CommandText, replaces: Replaces): any { | ||||
|     if (typeof text === "string") { | ||||
|   sendProcessedText (msg: Message, text: CommandText, replaces: Replaces): any { | ||||
|     if (typeof text === 'string') { | ||||
|       text = massReplace(text, replaces) | ||||
|       return msg.channel.send(text) | ||||
|     } else { | ||||
|       if (text.description !== undefined) text.description = massReplace(text.description, replaces) | ||||
|       if (text.title !== undefined) text.description = massReplace(text.title, replaces) | ||||
|       if (text.author?.name !== undefined) text.description = massReplace(text.author.name, replaces) | ||||
|       if (text.footer?.text !== undefined) text.description = massReplace(text.footer.text, replaces) | ||||
|       if (text.description !== undefined) | ||||
|         text.description = massReplace(text.description, replaces) | ||||
|       if (text.title !== undefined) | ||||
|         text.description = massReplace(text.title, replaces) | ||||
|       if (text.author?.name !== undefined) | ||||
|         text.description = massReplace(text.author.name, replaces) | ||||
|       if (text.footer?.text !== undefined) | ||||
|         text.description = massReplace(text.footer.text, replaces) | ||||
|       return msg.channel.send(text) | ||||
|     } | ||||
|   } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -156,7 +156,7 @@ export class RESTManager { | |||
|   ): { [key: string]: any } { | ||||
|     const headers: { [key: string]: string } = { | ||||
|       Authorization: `Bot ${this.client.token}`, | ||||
|       'User-Agent': `DiscordBot (discord.deno)` | ||||
|       'User-Agent': `DiscordBot (harmony)` | ||||
|     } | ||||
| 
 | ||||
|     if (this.client.token === undefined) delete headers.Authorization | ||||
|  | @ -190,7 +190,9 @@ export class RESTManager { | |||
|       data.headers['sec-fetch-dest'] = 'empty' | ||||
|       data.headers['sec-fetch-mode'] = 'cors' | ||||
|       data.headers['sec-fetch-site'] = 'same-origin' | ||||
|       data.headers['x-super-properties'] = btoa(JSON.stringify(getBuildInfo(this.client))) | ||||
|       data.headers['x-super-properties'] = btoa( | ||||
|         JSON.stringify(getBuildInfo(this.client)) | ||||
|       ) | ||||
|       delete data.headers['User-Agent'] | ||||
|       delete data.headers.Authorization | ||||
|       headers.credentials = 'include' | ||||
|  | @ -259,10 +261,7 @@ export class RESTManager { | |||
| 
 | ||||
|           const requestData = this.createRequestBody(body, method) | ||||
| 
 | ||||
|           const response = await fetch( | ||||
|             urlToUse, | ||||
|             requestData | ||||
|           ) | ||||
|           const response = await fetch(urlToUse, requestData) | ||||
|           const bucketIDFromHeaders = this.processHeaders(url, response.headers) | ||||
|           this.handleStatusCode(response, errorStack) | ||||
| 
 | ||||
|  | @ -328,7 +327,8 @@ export class RESTManager { | |||
|     // eslint-disable-next-line @typescript-eslint/no-floating-promises
 | ||||
|     this.logErrors(response, errorStack) | ||||
| 
 | ||||
|     if (status === HttpResponseCode.Unauthorized) throw new Error("Request was not successful. Invalid Token.") | ||||
|     if (status === HttpResponseCode.Unauthorized) | ||||
|       throw new Error('Request was not successful. Invalid Token.') | ||||
| 
 | ||||
|     switch (status) { | ||||
|       case HttpResponseCode.BadRequest: | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ import { VoiceState } from './voiceState.ts' | |||
| import { RolesManager } from '../managers/roles.ts' | ||||
| import { GuildChannelsManager } from '../managers/guildChannels.ts' | ||||
| import { MembersManager } from '../managers/members.ts' | ||||
| import { EmojisManager } from "../managers/emojis.ts" | ||||
| import { Emoji } from "./emoji.ts" | ||||
| 
 | ||||
| export class Guild extends Base { | ||||
|   id: string | ||||
|  | @ -27,7 +27,7 @@ export class Guild extends Base { | |||
|   defaultMessageNotifications?: string | ||||
|   explicitContentFilter?: string | ||||
|   roles: RolesManager | ||||
|   emojis: EmojisManager | ||||
|   emojis: Emoji[] = [] | ||||
|   features?: GuildFeatures[] | ||||
|   mfaLevel?: string | ||||
|   applicationID?: string | ||||
|  | @ -39,7 +39,7 @@ export class Guild extends Base { | |||
|   unavailable: boolean | ||||
|   memberCount?: number | ||||
|   voiceStates?: VoiceState[] | ||||
|   members: MembersManager  | ||||
|   members: MembersManager | ||||
|   channels: GuildChannelsManager | ||||
|   presences?: PresenceUpdatePayload[] | ||||
|   maxPresences?: number | ||||
|  |  | |||
|  | @ -122,8 +122,8 @@ export enum UpdateStatus { | |||
| 
 | ||||
| export interface IdentityConnection { | ||||
|   $os: 'darwin' | 'windows' | 'linux' | 'custom os' | ||||
|   $browser: 'discord.deno' | ||||
|   $device: 'discord.deno' | ||||
|   $browser: 'harmony' | ||||
|   $device: 'harmony' | ||||
| } | ||||
| 
 | ||||
| export interface Resume { | ||||
|  | @ -314,4 +314,4 @@ export interface VoiceServerUpdatePayload { | |||
| export interface WebhooksUpdatePayload { | ||||
|   guild_id: string | ||||
|   channel_id: string | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -1,40 +1,53 @@ | |||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||||
| import { Client } from '../models/client.ts' | ||||
| 
 | ||||
| export const getBuildInfo = (client: Client): { | ||||
|     os: string | ||||
|     os_version: string | ||||
|     browser: string | ||||
|     browser_version: string | ||||
|     browser_user_agent: string | ||||
|     client_build_number: number | ||||
|     client_event_source: null | ||||
|     release_channel: string | ||||
| export const getBuildInfo = ( | ||||
|   client: Client | ||||
| ): { | ||||
|   os: string | ||||
|   os_version: string | ||||
|   browser: string | ||||
|   browser_version: string | ||||
|   browser_user_agent: string | ||||
|   client_build_number: number | ||||
|   client_event_source: null | ||||
|   release_channel: string | ||||
| } => { | ||||
|     const os = 'Windows' | ||||
|     const os_version = '10' | ||||
|     let client_build_number = 71073 | ||||
|     const client_event_source = null | ||||
|     let release_channel = 'stable' | ||||
|     if (client.canary === true) { | ||||
|         release_channel = 'canary' | ||||
|         client_build_number = 71076 | ||||
|     } | ||||
|     const browser = 'Firefox' | ||||
|     const browser_version = '83.0' | ||||
|     const browser_user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 ' + browser + '/' + browser_version | ||||
|     // TODO: Use current OS properties, but also browser_user_agent accordingly
 | ||||
|     // if (Deno.build.os === 'darwin') os = 'MacOS'
 | ||||
|     // else if (Deno.build.os === 'linux') os = 'Ubuntu'
 | ||||
|   let os = 'Windows' | ||||
|   let os_version = '10' | ||||
|   let client_build_number = 71073 | ||||
|   const client_event_source = null | ||||
|   let release_channel = 'stable' | ||||
|   if (client.canary === true) { | ||||
|     release_channel = 'canary' | ||||
|     client_build_number = 71076 | ||||
|   } | ||||
|   let browser = 'Firefox' | ||||
|   let browser_version = '83.0' | ||||
|   let browser_user_agent = | ||||
|     'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 ' + | ||||
|     browser + | ||||
|     '/' + | ||||
|     browser_version | ||||
|   // TODO: Use current OS properties, but also browser_user_agent accordingly
 | ||||
|   if (Deno.build.os === 'darwin') { | ||||
|     os = 'MacOS' | ||||
|     os_version = '10.15.6' | ||||
|     browser = 'Safari' | ||||
|     browser_version = '14.0.1' | ||||
|     browser_user_agent = | ||||
|       'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15' | ||||
|   } | ||||
|   // else if (Deno.build.os === 'linux') os = 'Ubuntu'
 | ||||
| 
 | ||||
|     return { | ||||
|         os, | ||||
|         os_version, | ||||
|         browser, | ||||
|         browser_version, | ||||
|         browser_user_agent, | ||||
|         client_build_number, | ||||
|         client_event_source, | ||||
|         release_channel, | ||||
|     } | ||||
| }; | ||||
|   return { | ||||
|     os, | ||||
|     os_version, | ||||
|     browser, | ||||
|     browser_version, | ||||
|     browser_user_agent, | ||||
|     client_build_number, | ||||
|     client_event_source, | ||||
|     release_channel | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -18,55 +18,19 @@ export class Intents { | |||
|     GatewayIntents.GUILD_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILD_VOICE_STATES, | ||||
|     GatewayIntents.GUILD_WEBHOOKS | ||||
|   ]; | ||||
|   ] | ||||
| 
 | ||||
|   static Presence: number[] = [ | ||||
|     GatewayIntents.GUILD_PRESENCES, | ||||
|     GatewayIntents.GUILD_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.DIRECT_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILDS, | ||||
|     GatewayIntents.GUILD_BANS, | ||||
|     GatewayIntents.GUILD_EMOJIS, | ||||
|     GatewayIntents.GUILD_INTEGRATIONS, | ||||
|     GatewayIntents.GUILD_INVITES, | ||||
|     GatewayIntents.GUILD_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.GUILD_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILD_VOICE_STATES, | ||||
|     GatewayIntents.GUILD_WEBHOOKS | ||||
|   ]; | ||||
|     GatewayIntents.GUILDS | ||||
|   ] | ||||
| 
 | ||||
|   static GuildMembers: number[] = [ | ||||
|     GatewayIntents.GUILD_MEMBERS, | ||||
|     GatewayIntents.GUILD_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.DIRECT_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILDS, | ||||
|     GatewayIntents.GUILD_BANS, | ||||
|     GatewayIntents.GUILD_EMOJIS, | ||||
|     GatewayIntents.GUILD_INTEGRATIONS, | ||||
|     GatewayIntents.GUILD_INVITES, | ||||
|     GatewayIntents.GUILD_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.GUILD_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILD_VOICE_STATES, | ||||
|     GatewayIntents.GUILD_WEBHOOKS | ||||
|   ]; | ||||
| 
 | ||||
|   static None: number[] = [ | ||||
|     GatewayIntents.GUILD_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGES, | ||||
|     GatewayIntents.DIRECT_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.DIRECT_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILDS, | ||||
|     GatewayIntents.GUILD_BANS, | ||||
|     GatewayIntents.GUILD_EMOJIS, | ||||
|     GatewayIntents.GUILD_INTEGRATIONS, | ||||
|     GatewayIntents.GUILD_INVITES, | ||||
|     GatewayIntents.GUILD_MESSAGE_REACTIONS, | ||||
|     GatewayIntents.GUILD_MESSAGE_TYPING, | ||||
|     GatewayIntents.GUILD_VOICE_STATES, | ||||
|     GatewayIntents.GUILD_WEBHOOKS | ||||
|     GatewayIntents.GUILD_VOICE_STATES | ||||
|   ] | ||||
| } | ||||
| 
 | ||||
|   static None: number[] = [] | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue