feat(Player#search): change User to UserResolvable

This commit is contained in:
Snowflake107 2021-06-17 19:46:07 +05:45
parent 687b001426
commit 233a24dd34
2 changed files with 10 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import { Client, Collection, Guild, GuildResolvable, Snowflake, VoiceState } from "discord.js"; import { Client, Collection, Guild, GuildResolvable, Snowflake, User, UserResolvable, VoiceState } from "discord.js";
import { TypedEmitter as EventEmitter } from "tiny-typed-emitter"; import { TypedEmitter as EventEmitter } from "tiny-typed-emitter";
import { Queue } from "./Structures/Queue"; import { Queue } from "./Structures/Queue";
import { VoiceUtils } from "./VoiceInterface/VoiceUtils"; import { VoiceUtils } from "./VoiceInterface/VoiceUtils";
@ -139,12 +139,13 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
/** /**
* Search tracks * Search tracks
* @param {string|Track} query The search query * @param {string|Track} query The search query
* @param {User} requestedBy The person who requested track search * @param {UserResolvable} requestedBy The person who requested track search
* @returns {Promise<{playlist?: Playlist; tracks: Track[]}>} * @returns {Promise<{playlist?: Playlist; tracks: Track[]}>}
*/ */
async search(query: string | Track, options: SearchOptions) { async search(query: string | Track, options: SearchOptions) {
if (query instanceof Track) return { playlist: null, tracks: [query] }; if (query instanceof Track) return { playlist: null, tracks: [query] };
if (!options) throw new Error("DiscordPlayer#search needs search options!"); if (!options) throw new Error("DiscordPlayer#search needs search options!");
options.requestedBy = this.client.users.resolve(options.requestedBy);
if (!("searchEngine" in options)) options.searchEngine = QueryType.AUTO; if (!("searchEngine" in options)) options.searchEngine = QueryType.AUTO;
for (const [_, extractor] of this.extractors) { for (const [_, extractor] of this.extractors) {
@ -162,7 +163,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
(m) => (m) =>
new Track(this, { new Track(this, {
...m, ...m,
requestedBy: options.requestedBy, requestedBy: options.requestedBy as User,
duration: Util.buildTimeCode(Util.parseMS(m.duration)), duration: Util.buildTimeCode(Util.parseMS(m.duration)),
playlist: playlist playlist: playlist
}) })
@ -189,7 +190,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
description: m.description, description: m.description,
author: m.channel?.name, author: m.channel?.name,
url: m.url, url: m.url,
requestedBy: options.requestedBy, requestedBy: options.requestedBy as User,
thumbnail: m.thumbnail?.displayThumbnailURL("maxresdefault"), thumbnail: m.thumbnail?.displayThumbnailURL("maxresdefault"),
views: m.views, views: m.views,
duration: m.durationFormatted, duration: m.durationFormatted,
@ -284,7 +285,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
thumbnail: spotifyPlaylist.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg", thumbnail: spotifyPlaylist.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg",
duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)), duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)),
views: 0, views: 0,
requestedBy: options.requestedBy, requestedBy: options.requestedBy as User,
playlist, playlist,
source: "spotify" source: "spotify"
}); });
@ -301,7 +302,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
thumbnail: m.track.album?.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg", thumbnail: m.track.album?.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg",
duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)), duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)),
views: 0, views: 0,
requestedBy: options.requestedBy, requestedBy: options.requestedBy as User,
playlist, playlist,
source: "spotify" source: "spotify"
}); });
@ -381,7 +382,7 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
description: video.description, description: video.description,
author: video.channel?.name, author: video.channel?.name,
url: video.url, url: video.url,
requestedBy: options.requestedBy, requestedBy: options.requestedBy as User,
thumbnail: video.thumbnail.url, thumbnail: video.thumbnail.url,
views: video.views, views: video.views,
duration: video.durationFormatted, duration: video.durationFormatted,

View file

@ -1,4 +1,4 @@
import { Snowflake, User } from "discord.js"; import { Snowflake, User, UserResolvable } from "discord.js";
import { Readable, Duplex } from "stream"; import { Readable, Duplex } from "stream";
import { Queue } from "../Structures/Queue"; import { Queue } from "../Structures/Queue";
import Track from "../Structures/Track"; import Track from "../Structures/Track";
@ -189,7 +189,7 @@ export interface PlayOptions {
} }
export interface SearchOptions { export interface SearchOptions {
requestedBy: User; requestedBy: UserResolvable;
searchEngine?: QueryType; searchEngine?: QueryType;
} }