Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Oct 31, 2022
2 parents 0433d87 + 6e348ff commit bda8ae1
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/brokers/__tests__/index.test.ts
Expand Up @@ -2,6 +2,12 @@ import type Redis from 'ioredis';
import { test, expect, vi } from 'vitest';
import { PubSubRedisBroker } from '../src/index.js';

vi.mock('node:fs', () => {
return {
readFileSync: vi.fn(),
};
});

const mockRedisClient = {
defineCommand: vi.fn(),
xadd: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion packages/brokers/src/brokers/redis/BaseRedis.ts
Expand Up @@ -61,7 +61,7 @@ export abstract class BaseRedisBroker<TEvents extends Record<string, any>>
this.options = { ...DefaultBrokerOptions, ...options };
options.redisClient.defineCommand('xcleangroup', {
numberOfKeys: 1,
lua: readFileSync(resolve(__dirname, '..', '..', '..', 'scripts', 'xcleangroup.lua'), 'utf8'),
lua: readFileSync(resolve(__dirname, '..', 'scripts', 'xcleangroup.lua'), 'utf8'),
});
this.streamReadClient = options.redisClient.duplicate();
}
Expand Down
23 changes: 16 additions & 7 deletions packages/discord.js/src/client/Client.js
Expand Up @@ -214,13 +214,7 @@ class Client extends BaseClient {
if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
this.rest.setToken(token);
this.emit(
Events.Debug,
`Provided token: ${token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
.join('.')}`,
);
this.emit(Events.Debug, `Provided token: ${this._censoredToken}`);

if (this.options.presence) {
this.options.ws.presence = this.presence._parse(this.options.presence);
Expand Down Expand Up @@ -459,6 +453,21 @@ class Client extends BaseClient {
});
}

/**
* Partially censored client token for debug logging purposes.
* @type {?string}
* @readonly
* @private
*/
get _censoredToken() {
if (!this.token) return null;

return this.token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
.join('.');
}

/**
* Calls {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
* with the client as `this`.
Expand Down
7 changes: 6 additions & 1 deletion packages/discord.js/src/client/websocket/WebSocketShard.js
Expand Up @@ -740,7 +740,12 @@ class WebSocketShard extends EventEmitter {
*/
_send(data) {
if (this.connection?.readyState !== WebSocket.OPEN) {
this.debug(`Tried to send packet '${JSON.stringify(data)}' but no WebSocket is available!`);
this.debug(
`Tried to send packet '${JSON.stringify(data).replaceAll(
this.manager.client.token,
this.manager.client._censoredToken,
)}' but no WebSocket is available!`,
);
this.destroy({ closeCode: 4_000 });
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/src/errors/ErrorCodes.js
Expand Up @@ -128,6 +128,7 @@
* @property {'InteractionAlreadyReplied'} InteractionAlreadyReplied
* @property {'InteractionNotReplied'} InteractionNotReplied
* @property {'InteractionEphemeralReplied'} InteractionEphemeralReplied
* <warn>This property is deprecated.</warn>
* @property {'CommandInteractionOptionNotFound'} CommandInteractionOptionNotFound
* @property {'CommandInteractionOptionType'} CommandInteractionOptionType
Expand Down
1 change: 0 additions & 1 deletion packages/discord.js/src/structures/Message.js
Expand Up @@ -769,7 +769,6 @@ class Message extends Base {
/**
* Options provided when sending a message as an inline reply.
* @typedef {BaseMessageCreateOptions} MessageReplyOptions
* @property {StickerResolvable[]} [stickers=[]] The stickers to send in the message
* @property {boolean} [failIfNotExists=this.client.options.failIfNotExists] Whether to error if the referenced
* message does not exist (creates a standard message in this case when false)
* @property {StickerResolvable[]} [stickers=[]] Stickers to send in the message
Expand Down
Expand Up @@ -164,7 +164,6 @@ class InteractionResponses {
* .catch(console.error);
*/
async deleteReply() {
if (this.ephemeral) throw new DiscordjsError(ErrorCodes.InteractionEphemeralReplied);
await this.webhook.deleteMessage('@original');
}

Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -766,6 +766,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
private presence: ClientPresence;
private _eval(script: string): unknown;
private _validateOptions(options: ClientOptions): void;
private get _censoredToken(): string | null;

public application: If<Ready, ClientApplication>;
public channels: ChannelManager;
Expand Down Expand Up @@ -3246,6 +3247,7 @@ export enum DiscordjsErrorCodes {

InteractionAlreadyReplied = 'InteractionAlreadyReplied',
InteractionNotReplied = 'InteractionNotReplied',
/** @deprecated */
InteractionEphemeralReplied = 'InteractionEphemeralReplied',

CommandInteractionOptionNotFound = 'CommandInteractionOptionNotFound',
Expand Down

0 comments on commit bda8ae1

Please sign in to comment.