Skip to content

Commit

Permalink
Merge branch 'main' into types/narrow-button-type
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 11, 2023
2 parents 78be3ea + 632a9b4 commit 8201db1
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/actions/src/uploadCoverage/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ runs:
files: ./packages/discord.js/coverage/cobertura-coverage.xml
flags: discord.js

- name: Upload Formatters Coverage
uses: codecov/codecov-action@v3
with:
files: ./packages/formatters/coverage/cobertura-coverage.xml
flags: formatters

- name: Upload Next Coverage
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 0 additions & 3 deletions packages/create-discord-bot/src/create-discord-bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env node

// eslint-disable-next-line n/shebang
import { cp, stat, mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';
Expand Down
3 changes: 3 additions & 0 deletions packages/create-discord-bot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env node

// eslint-disable-next-line n/shebang
import { program } from 'commander';
import prompts from 'prompts';
import { createDiscordBot } from './create-discord-bot.js';
Expand Down
21 changes: 19 additions & 2 deletions packages/discord.js/src/client/actions/WebhooksUpdate.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
'use strict';

const process = require('node:process');
const Action = require('./Action');
const Events = require('../../util/Events');

let deprecationEmitted = false;

class WebhooksUpdate extends Action {
handle(data) {
const client = this.client;
const channel = client.channels.cache.get(data.channel_id);
if (!channel) return;

// TODO: change to Events.WebhooksUpdate in the next major version
/**
* Emitted whenever a channel has its webhooks changed.
* @event Client#webhooksUpdate
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
* The channel that had a webhook update
*/
client.emit('webhooksUpdate', channel);

/**
* Emitted whenever a channel has its webhooks changed.
* @event Client#webhookUpdate
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
* The channel that had a webhook update
* @deprecated Use {@link Client#event:webhooksUpdate} instead.
*/
if (channel) client.emit(Events.WebhooksUpdate, channel);
if (client.emit('webhookUpdate', channel) && !deprecationEmitted) {
deprecationEmitted = true;
process.emitWarning('The webhookUpdate event is deprecated. Use webhooksUpdate instead.', 'DeprecationWarning');
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.DiscordjsErrorCodes = require('./errors/ErrorCodes');
// Utilities
exports.ActivityFlagsBitField = require('./util/ActivityFlagsBitField');
exports.ApplicationFlagsBitField = require('./util/ApplicationFlagsBitField');
exports.AttachmentFlagsBitField = require('./util/AttachmentFlagsBitField');
exports.BaseManager = require('./managers/BaseManager');
exports.BitField = require('./util/BitField');
exports.ChannelFlagsBitField = require('./util/ChannelFlagsBitField');
Expand All @@ -35,6 +36,7 @@ exports.MessageFlagsBitField = require('./util/MessageFlagsBitField');
exports.Options = require('./util/Options');
exports.Partials = require('./util/Partials');
exports.PermissionsBitField = require('./util/PermissionsBitField');
exports.RoleFlagsBitField = require('./util/RoleFlagsBitField');
exports.ShardEvents = require('./util/ShardEvents');
exports.Status = require('./util/Status');
exports.SnowflakeUtil = require('@sapphire/snowflake').DiscordSnowflake;
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/Attachment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const AttachmentFlagsBitField = require('../util/AttachmentFlagsBitField.js');
const { basename, flatten } = require('../util/Util');

/**
Expand Down Expand Up @@ -121,6 +122,16 @@ class Attachment {
} else {
this.waveform ??= null;
}

if ('flags' in data) {
/**
* The flags of this attachment
* @type {Readonly<AttachmentFlagsBitField>}
*/
this.flags = new AttachmentFlagsBitField(data.flags).freeze();
} else {
this.flags ??= new AttachmentFlagsBitField().freeze();
}
}

/**
Expand Down
35 changes: 32 additions & 3 deletions packages/discord.js/src/structures/ClientApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const PermissionsBitField = require('../util/PermissionsBitField');
*/

/**
* Represents a Client OAuth2 Application.
* Represents a client application.
* @extends {Application}
*/
class ClientApplication extends Application {
Expand Down Expand Up @@ -69,6 +69,26 @@ class ClientApplication extends Application {
this.flags = new ApplicationFlagsBitField(data.flags).freeze();
}

if ('approximate_guild_count' in data) {
/**
* An approximate amount of guilds this application is in.
* @type {?number}
*/
this.approximateGuildCount = data.approximate_guild_count;
} else {
this.approximateGuildCount ??= null;
}

if ('guild_id' in data) {
/**
* The id of the guild associated with this application.
* @type {?Snowflake}
*/
this.guildId = data.guild_id;
} else {
this.guildId ??= null;
}

if ('cover_image' in data) {
/**
* The hash of the application's cover image
Expand Down Expand Up @@ -130,6 +150,15 @@ class ClientApplication extends Application {
: this.owner ?? null;
}

/**
* The guild associated with this application.
* @type {?Guild}
* @readonly
*/
get guild() {
return this.client.guilds.cache.get(this.guildId) ?? null;
}

/**
* Whether this application is partial
* @type {boolean}
Expand All @@ -144,8 +173,8 @@ class ClientApplication extends Application {
* @returns {Promise<ClientApplication>}
*/
async fetch() {
const app = await this.client.rest.get(Routes.oauth2CurrentApplication());
this._patch(app);
const data = await this.client.rest.get(Routes.currentApplication());
this._patch(data);
return this;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { PermissionFlagsBits } = require('discord-api-types/v10');
const Base = require('./Base');
const { DiscordjsError, ErrorCodes } = require('../errors');
const PermissionsBitField = require('../util/PermissionsBitField');
const RoleFlagsBitField = require('../util/RoleFlagsBitField');

/**
* Represents a role on Discord.
Expand Down Expand Up @@ -101,6 +102,16 @@ class Role extends Base {

if ('unicode_emoji' in data) this.unicodeEmoji = data.unicode_emoji;

if ('flags' in data) {
/**
* The flags of this role
* @type {Readonly<RoleFlagsBitField>}
*/
this.flags = new RoleFlagsBitField(data.flags).freeze();
} else {
this.flags ??= new RoleFlagsBitField().freeze();
}

/**
* The tags this role has
* @type {?Object}
Expand Down
10 changes: 10 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationRoleConnectionMetadataType}
*/

/**
* @external AttachmentFlags
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AttachmentFlags}
*/

/**
* @external AutoModerationActionType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AutoModerationActionType}
Expand Down Expand Up @@ -405,6 +410,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-payloads/common#PermissionFlagsBits}
*/

/**
* @external RoleFlags
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/RoleFlags}
*/

/**
* @external RESTGetAPIGuildThreadsResult
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#RESTGetAPIGuildThreadsResult}
Expand Down
26 changes: 26 additions & 0 deletions packages/discord.js/src/util/AttachmentFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const { AttachmentFlags } = require('discord-api-types/v10');
const BitField = require('./BitField');

/**
* Data structure that makes it easy to interact with an {@link Attachment#flags} bitfield.
* @extends {BitField}
*/
class AttachmentFlagsBitField extends BitField {
/**
* Numeric attachment flags.
* @type {AttachmentFlags}
* @memberof AttachmentFlagsBitField
*/
static Flags = AttachmentFlags;
}

/**
* @name AttachmentFlagsBitField
* @kind constructor
* @memberof AttachmentFlagsBitField
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/

module.exports = AttachmentFlagsBitField;
26 changes: 26 additions & 0 deletions packages/discord.js/src/util/RoleFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const { RoleFlags } = require('discord-api-types/v10');
const BitField = require('./BitField');

/**
* Data structure that makes it easy to interact with a {@link Role#flags} bitfield.
* @extends {BitField}
*/
class RoleFlagsBitField extends BitField {
/**
* Numeric role flags.
* @type {RoleFlags}
* @memberof RoleFlagsBitField
*/
static Flags = RoleFlags;
}

/**
* @name RoleFlagsBitField
* @kind constructor
* @memberof RoleFlagsBitField
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/

module.exports = RoleFlagsBitField;
25 changes: 24 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ import {
APIGuildOnboardingPrompt,
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
AttachmentFlags,
RoleFlags,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -1010,8 +1012,11 @@ export class ClientApplication extends Application {
public botPublic: boolean | null;
public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager;
public guildId: Snowflake | null;
public get guild(): Guild | null;
public cover: string | null;
public flags: Readonly<ApplicationFlagsBitField>;
public approximateGuildCount: number | null;
public tags: string[];
public installParams: ClientApplicationInstallParams | null;
public customInstallURL: string | null;
Expand Down Expand Up @@ -2070,6 +2075,7 @@ export class Attachment {
public description: string | null;
public duration: number | null;
public ephemeral: boolean;
public flags: AttachmentFlagsBitField;
public height: number | null;
public id: Snowflake;
public name: string;
Expand All @@ -2082,6 +2088,13 @@ export class Attachment {
public toJSON(): unknown;
}

export type AttachmentFlagsString = keyof typeof AttachmentFlags;

export class AttachmentFlagsBitField extends BitField<AttachmentFlagsString> {
public static Flags: Record<AttachmentFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<AttachmentFlagsString, number>): number;
}

export class MessageCollector extends Collector<Snowflake, Message, [Collection<Snowflake, Message>]> {
public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions);
private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
Expand Down Expand Up @@ -2515,6 +2528,7 @@ export class Role extends Base {
public get createdAt(): Date;
public get createdTimestamp(): number;
public get editable(): boolean;
public flags: RoleFlagsBitField;
public guild: Guild;
public get hexColor(): HexColorString;
public hoist: boolean;
Expand Down Expand Up @@ -2550,6 +2564,13 @@ export class Role extends Base {
public toString(): RoleMention;
}

export type RoleFlagsString = keyof typeof RoleFlags;

export class RoleFlagsBitField extends BitField<RoleFlagsString> {
public static Flags: typeof RoleFlags;
public static resolve(bit?: BitFieldResolvable<RoleFlagsString, number>): number;
}

export class StringSelectMenuInteraction<
Cached extends CacheType = CacheType,
> extends MessageComponentInteraction<Cached> {
Expand Down Expand Up @@ -4861,7 +4882,9 @@ export interface ClientEvents {
typingStart: [typing: Typing];
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel];
/** @deprecated Use {@link webhooksUpdate} instead. */
webhookUpdate: ClientEvents['webhooksUpdate'];
webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel];
interactionCreate: [interaction: Interaction];
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
shardError: [error: Error, shardId: number];
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ client.on('voiceStateUpdate', ({ client: oldClient }, { client: newClient }) =>
expectType<Client<true>>(newClient);
});

client.on('webhookUpdate', ({ client }) => expectType<Client<true>>(client));
client.on('webhooksUpdate', ({ client }) => expectType<Client<true>>(client));

client.on('guildCreate', async g => {
expectType<Client<true>>(g.client);
Expand Down

0 comments on commit 8201db1

Please sign in to comment.