-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Create client adapter skeleton
- Loading branch information
1 parent
42a8e6a
commit 10f7b07
Showing
9 changed files
with
108 additions
and
33 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
49 changes: 49 additions & 0 deletions
49
packages/discord-player/src/clientadapter/ClientAdapterFactory.ts
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,49 @@ | ||
import { Client as DiscordJsClient } from 'discord.js'; | ||
import { Client as ErisClient } from 'eris'; | ||
import { DiscordJsClientAdapter } from './DiscordJsClientAdapter'; | ||
import { IClientAdapter } from './IClientAdapter'; | ||
import { Util } from '../utils/Util'; | ||
|
||
enum ClientType { | ||
DiscordJs = 'DjsClient', | ||
Eris = 'ErisClient', | ||
Unknown = 'Unknown' | ||
} | ||
|
||
type SupportedClient = DiscordJsClient | ErisClient; | ||
|
||
export class ClientAdapterFactory { | ||
static createClientAdapter(client: SupportedClient): IClientAdapter { | ||
try { | ||
const clientType = this.getClientType(client); | ||
|
||
switch (clientType) { | ||
case ClientType.DiscordJs: | ||
return new DiscordJsClientAdapter((client as DiscordJsClient)); | ||
case ClientType.Eris: | ||
Util.warn( | ||
`You are using an Eris client, some things may not work correctly. This is currently under experimental support and it is still recommended to use a discord.js client.`, | ||
'ExperimentalClientInstance' | ||
); | ||
// return new ErisClientAdapter((client as ErisClient)); | ||
throw new Error('Eris client is not supported yet'); | ||
default: | ||
throw new Error('Unsupported client type'); | ||
} | ||
} catch (error) { | ||
throw new Error(`Failed to create client adapter: ${error}`); | ||
} | ||
} | ||
|
||
private static getClientType(client: SupportedClient): ClientType { | ||
if (client instanceof DiscordJsClient) { | ||
return ClientType.DiscordJs; | ||
} | ||
|
||
if (client instanceof ErisClient) { | ||
return ClientType.Eris; | ||
} | ||
|
||
return ClientType.Unknown; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/discord-player/src/clientadapter/DiscordJsClientAdapter.ts
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,10 @@ | ||
import { Client } from "discord.js"; | ||
import { IClientAdapter } from "./IClientAdapter"; | ||
|
||
export class DiscordJsClientAdapter implements IClientAdapter { | ||
private client: Client; | ||
|
||
constructor(client: Client) { | ||
this.client = client; | ||
} | ||
} |
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,3 @@ | ||
export interface IClientAdapter { | ||
|
||
} |
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
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
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
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
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