Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
Add manager option "defaultSearchPlatform" (#137)
Browse files Browse the repository at this point in the history
* Add manager option "defaultSearchPlatform"

* Fix build errors?
  • Loading branch information
2D authored Sep 19, 2021
1 parent b24db56 commit 819bdcd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ function check(options: ManagerOptions) {
typeof options.clientName !== "string"
)
throw new TypeError('Manager option "clientName" must be a string.');

if (
typeof options.defaultSearchPlatform !== "undefined" &&
typeof options.defaultSearchPlatform !== "string"
)
throw new TypeError('Manager option "defaultSearchPlatform" must be a string.');
}

export interface Manager {
Expand Down Expand Up @@ -257,6 +263,7 @@ export class Manager extends EventEmitter {
shards: 1,
autoPlay: true,
clientName: "erela.js",
defaultSearchPlatform: "youtube",
...options,
};

Expand Down Expand Up @@ -313,9 +320,10 @@ export class Manager extends EventEmitter {
const sources = {
soundcloud: "sc",
youtube: "yt",
"youtube music": "ytm"
};

const source = sources[(query as SearchQuery).source ?? "youtube"];
const source = sources[(query as SearchQuery).source ?? this.options.defaultSearchPlatform];
let search = (query as SearchQuery).query || (query as string);

if (!/^https?:\/\//.test(search)) {
Expand Down Expand Up @@ -500,6 +508,8 @@ export interface ManagerOptions {
autoPlay?: boolean;
/** An array of track properties to keep. `track` will always be present. */
trackPartial?: string[];
/** The default search platform to use, can be "youtube", "youtube music", or "soundcloud". */
defaultSearchPlatform?: SearchPlatform;
/**
* Function to send data to the websocket.
* @param id
Expand All @@ -508,9 +518,11 @@ export interface ManagerOptions {
send(id: string, payload: Payload): void;
}

export type SearchPlatform = "youtube" | "youtube music" | "soundcloud";

export interface SearchQuery {
/** The source to search from. */
source?: "youtube" | "soundcloud";
source?: SearchPlatform;
/** The query to search for. */
query: string;
}
Expand Down

0 comments on commit 819bdcd

Please sign in to comment.