Skip to content

Commit

Permalink
Merge pull request #250 from discordjs/main
Browse files Browse the repository at this point in the history
Create a new pull request by comparing changes across two branches
  • Loading branch information
GulajavaMinistudio committed Sep 30, 2023
2 parents a942b0b + 93e5bed commit 6aeeb15
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 140 deletions.
7 changes: 5 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ If you'd like to create another package under the `@discordjs` organization run
pnpm run create-package <package-name> [package-description]
```

This will create new package directory under `packages/` with the required configuration files. You can
begin to make changes within the `src/` directory. It may also be required to update the CODEOWNERS file.
This will create new package directory under `packages/` with the required configuration files. You may begin
to make changes within the `src/` directory. You may also need to:

- Update workflows that utilize packages
- Update the CODEOWNERS file
50 changes: 50 additions & 0 deletions .github/workflows/deprecate-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deprecate version
on:
workflow_dispatch:
inputs:
package:
description: Package
required: true
type: choice
options:
- '@discordjs/brokers'
- '@discordjs/builders'
- '@discordjs/collection'
- '@discordjs/core'
- create-discord-bot
- '@discordjs/formatters'
- discord.js
- '@discordjs/next'
- '@discordjs/proxy'
- '@discordjs/rest'
- '@discordjs/util'
- '@discordjs/voice'
- '@discordjs/ws'
version:
description: Version(s)
required: true
type: string
message:
description: Deprecation message
required: false
type: string
jobs:
deprecate:
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node.js v18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
uses: ./packages/actions/src/pnpmCache

- name: Deprecate
run: pnpm exec npm-deprecate --name "${{inputs.version}}" --message "${{inputs.message || 'This version is deprecated. Please use a newer version.'}}" --package ${{inputs.package}}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/npm-auto-deprecate.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ jobs:
pnpm --filter=${{ matrix.package }} publish --no-git-checks --tag dev || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Deprecate prior development releases
run: pnpm exec npm-deprecate --name "*dev*" --message "This version is deprecated. Please use a newer version." --package ${{ matrix.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: |
pnpm --filter=${{ steps.extract-tag.outputs.subpackage == 'true' && '@discordjs/' || '' }}${{ steps.extract-tag.outputs.package }} publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
3 changes: 1 addition & 2 deletions packages/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

## Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
[documentation][documentation].
Before creating an issue, please ensure that it hasn't already been reported/suggested.
See [the contribution guide][contributing] if you'd like to submit a PR.

## Help
Expand Down
3 changes: 1 addition & 2 deletions packages/api-extractor-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

## Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
[documentation][documentation].
Before creating an issue, please ensure that it hasn't already been reported/suggested.
See [the contribution guide][contributing] if you'd like to submit a PR.

## Help
Expand Down
2 changes: 1 addition & 1 deletion packages/brokers/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
END OF TERMS AND CONDITIONS

Copyright 2022 Noel Buechler
Copyright 2022 Charlotte Cristea
Copyright 2022 Denis Cristea

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class CategoryChannelChildManager extends DataManager {
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the new channel in seconds
* @property {string} [rtcRegion] The specific region of the new channel.
* @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the voice channel
* @property {number} [defaultThreadRateLimitPerUser] The initial rate limit per user (slowmode)
* to set on newly created threads in a channel.
* @property {GuildForumTagData[]} [availableTags] The tags that can be used in this channel (forum only).
* @property {DefaultReactionEmoji} [defaultReactionEmoji]
* The emoji to show in the add reaction button on a thread in a guild forum channel.
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class GuildChannelManager extends CachedManager {
rateLimitPerUser,
rtcRegion,
videoQualityMode,
defaultThreadRateLimitPerUser,
availableTags,
defaultReactionEmoji,
defaultAutoArchiveDuration,
Expand All @@ -181,6 +182,7 @@ class GuildChannelManager extends CachedManager {
rate_limit_per_user: rateLimitPerUser,
rtc_region: rtcRegion,
video_quality_mode: videoQualityMode,
default_thread_rate_limit_per_user: defaultThreadRateLimitPerUser,
available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
default_auto_archive_duration: defaultAutoArchiveDuration,
Expand Down
7 changes: 6 additions & 1 deletion packages/discord.js/src/managers/StageInstanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class StageInstanceManager extends CachedManager {
* @property {string} topic The topic of the stage instance
* @property {StageInstancePrivacyLevel} [privacyLevel] The privacy level of the stage instance
* @property {boolean} [sendStartNotification] Whether to notify `@everyone` that the stage instance has started
* @property {GuildScheduledEventResolvable} [guildScheduledEvent]
* The guild scheduled event associated with the stage instance
*/

/**
Expand Down Expand Up @@ -59,14 +61,17 @@ class StageInstanceManager extends CachedManager {
const channelId = this.guild.channels.resolveId(channel);
if (!channelId) throw new DiscordjsError(ErrorCodes.StageChannelResolve);
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
let { topic, privacyLevel, sendStartNotification } = options;
const { guildScheduledEvent, topic, privacyLevel, sendStartNotification } = options;

const guildScheduledEventId = guildScheduledEvent && this.resolveId(guildScheduledEvent);

const data = await this.client.rest.post(Routes.stageInstances(), {
body: {
channel_id: channelId,
topic,
privacy_level: privacyLevel,
send_start_notification: sendStartNotification,
guild_scheduled_event_id: guildScheduledEventId,
},
});

Expand Down
10 changes: 10 additions & 0 deletions packages/discord.js/src/structures/BaseGuildTextChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ class BaseGuildTextChannel extends GuildChannel {
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
}

if ('default_thread_rate_limit_per_user' in data) {
/**
* The initial rate limit per user (slowmode) to set on newly created threads in a channel.
* @type {?number}
*/
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user;
} else {
this.defaultThreadRateLimitPerUser ??= null;
}

if ('messages' in data) {
for (const message of data.messages) this.messages._add(message);
}
Expand Down
114 changes: 30 additions & 84 deletions packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ const Targets = {
* @typedef {string} AuditLogTargetType
*/

/**
* Contructs an object of known properties for a structure from an array of changes.
* @param {AuditLogChange[]} changes The array of changes
* @param {Object} [initialData={}] The initial data passed to the function
* @returns {Object}
* @ignore
*/
function changesReduce(changes, initialData = {}) {
return changes.reduce((accumulator, change) => {
accumulator[change.key] = change.new ?? change.old;
return accumulator;
}, initialData);
}

/**
* Audit logs entry.
*/
Expand Down Expand Up @@ -268,10 +282,7 @@ class GuildAuditLogsEntry {
*/
this.target = null;
if (targetType === Targets.Unknown) {
this.target = this.changes.reduce((o, c) => {
o[c.key] = c.new ?? c.old;
return o;
}, {});
this.target = changesReduce(this.changes);
this.target.id = data.target_id;
// MemberDisconnect and similar types do not provide a target_id.
} else if (targetType === Targets.User && data.target_id) {
Expand All @@ -285,33 +296,16 @@ class GuildAuditLogsEntry {
logs?.webhooks.get(data.target_id) ??
new Webhook(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{
id: data.target_id,
guild_id: guild.id,
},
),
changesReduce(this.changes, {
id: data.target_id,
guild_id: guild.id,
}),
);
} else if (targetType === Targets.Invite) {
let change = this.changes.find(c => c.key === 'code');
change = change.new ?? change.old;

this.target =
guild.invites.cache.get(change) ??
new Invite(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ guild },
),
);
this.target = guild.invites.cache.get(change) ?? new Invite(guild.client, changesReduce(this.changes, { guild }));
} else if (targetType === Targets.Message) {
// Discord sends a channel id for the MessageBulkDelete action type.
this.target =
Expand All @@ -321,84 +315,36 @@ class GuildAuditLogsEntry {
} else if (targetType === Targets.Integration) {
this.target =
logs?.integrations.get(data.target_id) ??
new Integration(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ id: data.target_id },
),
guild,
);
new Integration(guild.client, changesReduce(this.changes, { id: data.target_id }), guild);
} else if (targetType === Targets.Channel || targetType === Targets.Thread) {
this.target =
guild.channels.cache.get(data.target_id) ??
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ id: data.target_id },
);
this.target = guild.channels.cache.get(data.target_id) ?? changesReduce(this.changes, { id: data.target_id });
} else if (targetType === Targets.StageInstance) {
this.target =
guild.stageInstances.cache.get(data.target_id) ??
new StageInstance(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{
id: data.target_id,
channel_id: data.options?.channel_id,
guild_id: guild.id,
},
),
changesReduce(this.changes, {
id: data.target_id,
channel_id: data.options?.channel_id,
guild_id: guild.id,
}),
);
} else if (targetType === Targets.Sticker) {
this.target =
guild.stickers.cache.get(data.target_id) ??
new Sticker(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ id: data.target_id },
),
);
new Sticker(guild.client, changesReduce(this.changes, { id: data.target_id }));
} else if (targetType === Targets.GuildScheduledEvent) {
this.target =
guild.scheduledEvents.cache.get(data.target_id) ??
new GuildScheduledEvent(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ id: data.target_id, guild_id: guild.id },
),
);
new GuildScheduledEvent(guild.client, changesReduce(this.changes, { id: data.target_id, guild_id: guild.id }));
} else if (targetType === Targets.ApplicationCommand) {
this.target = logs?.applicationCommands.get(data.target_id) ?? { id: data.target_id };
} else if (targetType === Targets.AutoModeration) {
this.target =
guild.autoModerationRules.cache.get(data.target_id) ??
new AutoModerationRule(
guild.client,
this.changes.reduce(
(o, c) => {
o[c.key] = c.new ?? c.old;
return o;
},
{ id: data.target_id, guild_id: guild.id },
),
changesReduce(this.changes, { id: data.target_id, guild_id: guild.id }),
guild,
);
} else if (data.target_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ class TextBasedChannel {
* @typedef {string} MessageMentionTypes
*/

/**
* @typedef {Object} FileOptions
* @property {BufferResolvable} attachment File to attach
* @property {string} [name='file.jpg'] Filename of the attachment
* @property {string} description The description of the file
*/

/**
* Sends a message to this channel.
* @param {string|MessagePayload|MessageCreateOptions} options The options to provide
Expand Down
Loading

0 comments on commit 6aeeb15

Please sign in to comment.