-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8390eec
commit a1d8ed9
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PlayerOptions } from "../types/player"; | ||
import { Player } from "./player"; | ||
|
||
export class PlayerManager { | ||
private players: Player[] = []; | ||
|
||
/** | ||
* Creates a new PlayerManager for easier managing multiple guilds. Your bot should only have one PlayerManager. | ||
* | ||
* @param options Options that should be applied for all guilds. Guild specific options can be overridden when calling `getPlayer`. | ||
*/ | ||
constructor(private readonly options?: PlayerOptions) {} | ||
|
||
/** | ||
* Gets an existing player for the given guildId or creates one if it does not exist. | ||
* | ||
* @param optionOverrides Option overrides for the guild player. Will be merged with options passed to the PlayerManager. | ||
*/ | ||
getPlayer(guildId: string, optionOverrides?: Partial<PlayerOptions>): Player { | ||
const player = this.players.find((p) => p.guildId === guildId); | ||
if (player) return player; | ||
|
||
const newPlayer = new Player(guildId, { | ||
...this.options, | ||
...optionOverrides, | ||
}); | ||
this.players.push(newPlayer); | ||
return newPlayer; | ||
} | ||
|
||
/** Checks if a player for the given guildId exists. Does not create a player. */ | ||
exists(guildId: string): boolean { | ||
return !!this.players.find((player) => player.guildId === guildId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./includes/player"; | ||
export * from "./includes/player-manager"; | ||
export * from "./types/player"; | ||
export * from "./types/tracks"; |