Skip to content

Commit

Permalink
Merge branch 'player-client-adapter-wip' of https://github.com/Androz…
Browse files Browse the repository at this point in the history
…2091/discord-player into player-client-adapter-wip
  • Loading branch information
retrouser955 committed Aug 12, 2024
2 parents edd97e1 + 70a3d87 commit 99d9ea0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
45 changes: 34 additions & 11 deletions packages/discord-player/src/clientadapter/ClientAdapterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,40 @@ export class ClientAdapterFactory {
// throw new Error(`Failed to create client adapter: ${error}`);
// }
}
}

/** old code just in case */
// private static getClientType(client: SupportedClient): ClientType {
// if (client instanceof DiscordJsClient) {
// return ClientType.DiscordJs;
// }
/** old code in case I f it up */

// if (client instanceof ErisClient) {
// return ClientType.Eris;
// }
// try {
// const clientType = this.getClientType(client);

// return ClientType.Unknown;
// }
}
// 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}`);
// }


/** old code just in case */
// private static getClientType(client: SupportedClient): ClientType {
// if (client instanceof DiscordJsClient) {
// return ClientType.DiscordJs;
// }

// if (client instanceof ErisClient) {
// return ClientType.Eris;
// }

// return ClientType.Unknown;
// }
20 changes: 10 additions & 10 deletions packages/discord-player/src/clientadapter/ClientModeDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export const VALID_PACKAGES: ValidPackagesStructure[] = [
await import("discord.js")
return true
} catch {
return false
return false;
}
},
async testClient(client: SupportedClient) {
try {
const { Client } = await import("discord.js")

return client instanceof Client
return client instanceof Client;
} catch {
return false
return false;
}
}
},
Expand All @@ -35,28 +35,28 @@ export const VALID_PACKAGES: ValidPackagesStructure[] = [
await import("eris")
return true
} catch {
return false
return false;
}
},
async testClient(client) {
try {
const { Client } = await import("eris")

return client instanceof Client
return client instanceof Client;
} catch {
return false
return false;
}
},
}
]
];

export async function detectClientMode(client: SupportedClient): Promise<ClientType> {
for(const pkg of VALID_PACKAGES) {
const isValid = await pkg.test()
const isInstance = await pkg.testClient(client)

if(isValid && isInstance) return pkg.name
if (isValid && isInstance) return pkg.name;
}

return "unknown"
}
return "unknown";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ClientType = {
DiscordJS: "discord.js",
Eris: "eris",
Unknown: "unknown"
} as const
} as const;

export type ClientType = typeof ClientType[keyof typeof ClientType]

Expand Down

0 comments on commit 99d9ea0

Please sign in to comment.