mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
|
||||
interface Methods {
|
||||
open: (buffer: Buffer, nonce: Buffer, secretKey: Uint8Array) => Buffer | null;
|
||||
close: (opusPacket: Buffer, nonce: Buffer, secretKey: Uint8Array) => Buffer;
|
||||
random: (bytes: number, nonce: Buffer) => Buffer;
|
||||
close(opusPacket: Buffer, nonce: Buffer, secretKey: Uint8Array): Buffer;
|
||||
open(buffer: Buffer, nonce: Buffer, secretKey: Uint8Array): Buffer | null;
|
||||
random(bytes: number, nonce: Buffer): Buffer;
|
||||
}
|
||||
|
||||
const libs = {
|
||||
@@ -14,6 +16,7 @@ const libs = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
if (sodium.crypto_secretbox_open_easy(output, buffer, nonce, secretKey)) return output;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
close: (opusPacket: Buffer, nonce: Buffer, secretKey: Uint8Array) => {
|
||||
@@ -24,7 +27,7 @@ const libs = {
|
||||
return output;
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
random: (n: number, buffer: Buffer = Buffer.allocUnsafe(n)) => {
|
||||
random: (num: number, buffer: Buffer = Buffer.allocUnsafe(num)) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
sodium.randombytes_buf(buffer);
|
||||
return buffer;
|
||||
@@ -36,7 +39,7 @@ const libs = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
||||
close: sodium.api.crypto_secretbox_easy,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
random: (n: number, buffer: Buffer = Buffer.allocUnsafe(n)) => {
|
||||
random: (num: number, buffer: Buffer = Buffer.allocUnsafe(num)) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
sodium.api.randombytes_buf(buffer);
|
||||
return buffer;
|
||||
@@ -77,7 +80,7 @@ const methods: Methods = {
|
||||
void (async () => {
|
||||
for (const libName of Object.keys(libs) as (keyof typeof libs)[]) {
|
||||
try {
|
||||
// eslint-disable-next-line
|
||||
// eslint-disable-next-line unicorn/no-abusive-eslint-disable, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const lib = require(libName);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (libName === 'libsodium-wrappers' && lib.ready) await lib.ready;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
export function abortAfter(delay: number): [AbortController, AbortSignal] {
|
||||
const ac = new AbortController();
|
||||
const timeout = setTimeout(() => ac.abort(), delay);
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: No type for timeout
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
ac.signal.addEventListener('abort', () => clearTimeout(timeout));
|
||||
return [ac, ac.signal];
|
||||
|
||||
@@ -5,41 +5,40 @@ import type { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispa
|
||||
* Discord gateway DiscordGatewayAdapters.
|
||||
*/
|
||||
export interface DiscordGatewayAdapterLibraryMethods {
|
||||
/**
|
||||
* Call this when the adapter can no longer be used (e.g. due to a disconnect from the main gateway)
|
||||
*/
|
||||
destroy(): void;
|
||||
/**
|
||||
* Call this when you receive a VOICE_SERVER_UPDATE payload that is relevant to the adapter.
|
||||
*
|
||||
* @param data - The inner data of the VOICE_SERVER_UPDATE payload
|
||||
*/
|
||||
onVoiceServerUpdate: (data: GatewayVoiceServerUpdateDispatchData) => void;
|
||||
onVoiceServerUpdate(data: GatewayVoiceServerUpdateDispatchData): void;
|
||||
/**
|
||||
* Call this when you receive a VOICE_STATE_UPDATE payload that is relevant to the adapter.
|
||||
*
|
||||
* @param data - The inner data of the VOICE_STATE_UPDATE payload
|
||||
*/
|
||||
onVoiceStateUpdate: (data: GatewayVoiceStateUpdateDispatchData) => void;
|
||||
/**
|
||||
* Call this when the adapter can no longer be used (e.g. due to a disconnect from the main gateway)
|
||||
*/
|
||||
destroy: () => void;
|
||||
onVoiceStateUpdate(data: GatewayVoiceStateUpdateDispatchData): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods that are provided by the implementer of a Discord gateway DiscordGatewayAdapter.
|
||||
*/
|
||||
export interface DiscordGatewayAdapterImplementerMethods {
|
||||
/**
|
||||
* Implement this method such that the given payload is sent to the main Discord gateway connection.
|
||||
*
|
||||
* @param payload - The payload to send to the main Discord gateway connection
|
||||
*
|
||||
* @returns `false` if the payload definitely failed to send - in this case, the voice connection disconnects
|
||||
*/
|
||||
sendPayload: (payload: any) => boolean;
|
||||
/**
|
||||
* This will be called by \@discordjs/voice when the adapter can safely be destroyed as it will no
|
||||
* longer be used.
|
||||
*/
|
||||
destroy: () => void;
|
||||
destroy(): void;
|
||||
/**
|
||||
* Implement this method such that the given payload is sent to the main Discord gateway connection.
|
||||
*
|
||||
* @param payload - The payload to send to the main Discord gateway connection
|
||||
* @returns `false` if the payload definitely failed to send - in this case, the voice connection disconnects
|
||||
*/
|
||||
sendPayload(payload: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
import process from 'node:process';
|
||||
import { Readable } from 'node:stream';
|
||||
import prism from 'prism-media';
|
||||
import { noop } from './util';
|
||||
import { StreamType } from '..';
|
||||
import { noop } from './util';
|
||||
|
||||
/**
|
||||
* Takes an Opus Head, and verifies whether the associated Opus audio is suitable to play in a Discord voice channel.
|
||||
*
|
||||
* @param opusHead - The Opus Head to validate
|
||||
*
|
||||
* @returns `true` if suitable to play in a Discord voice channel, otherwise `false`
|
||||
*/
|
||||
export function validateDiscordOpusHead(opusHead: Buffer): boolean {
|
||||
const channels = opusHead.readUInt8(9);
|
||||
const sampleRate = opusHead.readUInt32LE(12);
|
||||
return channels === 2 && sampleRate === 48000;
|
||||
return channels === 2 && sampleRate === 48_000;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,22 +39,28 @@ export interface ProbeInfo {
|
||||
* @param stream - The readable stream to probe
|
||||
* @param probeSize - The number of bytes to attempt to read before giving up on the probe
|
||||
* @param validator - The Opus Head validator function
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function demuxProbe(
|
||||
export async function demuxProbe(
|
||||
stream: Readable,
|
||||
probeSize = 1024,
|
||||
probeSize = 1_024,
|
||||
validator = validateDiscordOpusHead,
|
||||
): Promise<ProbeInfo> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Preconditions
|
||||
if (stream.readableObjectMode) return reject(new Error('Cannot probe a readable stream in object mode'));
|
||||
if (stream.readableEnded) return reject(new Error('Cannot probe a stream that has ended'));
|
||||
if (stream.readableObjectMode) {
|
||||
reject(new Error('Cannot probe a readable stream in object mode'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream.readableEnded) {
|
||||
reject(new Error('Cannot probe a stream that has ended'));
|
||||
return;
|
||||
}
|
||||
|
||||
let readBuffer = Buffer.alloc(0);
|
||||
|
||||
let resolved: StreamType | undefined = undefined;
|
||||
let resolved: StreamType | undefined;
|
||||
|
||||
const finish = (type: StreamType) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
@@ -73,6 +80,7 @@ export function demuxProbe(
|
||||
if (readBuffer.length > 0) {
|
||||
stream.push(readBuffer);
|
||||
}
|
||||
|
||||
resolve({
|
||||
stream,
|
||||
type,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import EventEmitter, { once } from 'node:events';
|
||||
import { abortAfter } from './abortAfter';
|
||||
import { type EventEmitter, once } from 'node:events';
|
||||
import type { VoiceConnection, VoiceConnectionStatus } from '../VoiceConnection';
|
||||
import type { AudioPlayer, AudioPlayerStatus } from '../audio/AudioPlayer';
|
||||
import { abortAfter } from './abortAfter';
|
||||
|
||||
/**
|
||||
* Allows a voice connection a specified amount of time to enter a given state, otherwise rejects with an error.
|
||||
@@ -13,7 +13,7 @@ import type { AudioPlayer, AudioPlayerStatus } from '../audio/AudioPlayer';
|
||||
export function entersState(
|
||||
target: VoiceConnection,
|
||||
status: VoiceConnectionStatus,
|
||||
timeoutOrSignal: number | AbortSignal,
|
||||
timeoutOrSignal: AbortSignal | number,
|
||||
): Promise<VoiceConnection>;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ export function entersState(
|
||||
export function entersState(
|
||||
target: AudioPlayer,
|
||||
status: AudioPlayerStatus,
|
||||
timeoutOrSignal: number | AbortSignal,
|
||||
timeoutOrSignal: AbortSignal | number,
|
||||
): Promise<AudioPlayer>;
|
||||
|
||||
/**
|
||||
@@ -36,10 +36,10 @@ export function entersState(
|
||||
* @param status - The status that the target should be in
|
||||
* @param timeoutOrSignal - The maximum time we are allowing for this to occur, or a signal that will abort the operation
|
||||
*/
|
||||
export async function entersState<T extends VoiceConnection | AudioPlayer>(
|
||||
export async function entersState<T extends AudioPlayer | VoiceConnection>(
|
||||
target: T,
|
||||
status: VoiceConnectionStatus | AudioPlayerStatus,
|
||||
timeoutOrSignal: number | AbortSignal,
|
||||
status: AudioPlayerStatus | VoiceConnectionStatus,
|
||||
timeoutOrSignal: AbortSignal | number,
|
||||
) {
|
||||
if (target.state.status !== status) {
|
||||
const [ac, signal] =
|
||||
@@ -50,5 +50,6 @@ export async function entersState<T extends VoiceConnection | AudioPlayer>(
|
||||
ac?.abort();
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ function findPackageJSON(
|
||||
if (pkg.name !== packageName) throw new Error('package.json does not match');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return pkg;
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return findPackageJSON(resolve(dir, '..'), packageName, depth - 1);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ function version(name: string): string {
|
||||
: findPackageJSON(dirname(require.resolve(name)), name, 3);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
|
||||
return pkg?.version ?? 'not found';
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return 'not found';
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export function generateDependencyReport() {
|
||||
const info = prism.FFmpeg.getInfo();
|
||||
report.push(`- version: ${info.version}`);
|
||||
report.push(`- libopus: ${info.output.includes('--enable-libopus') ? 'yes' : 'no'}`);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
report.push('- not found');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user