-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting OOP ready for multiple chat platforms
- Loading branch information
Showing
4 changed files
with
184 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
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,46 @@ | ||
/** | ||
* Abstract class to define a standard interface for chat platform clients. | ||
* This will ensure that all chat platform clients have a consistent interface. | ||
*/ | ||
export default class ChatPlatformClient { | ||
/** | ||
* Connect to the chat platform. | ||
*/ | ||
async connect() { | ||
throw new Error('connect method must be implemented') | ||
} | ||
|
||
/** | ||
* Send a message to a specified channel. | ||
* @param {string} channel - The channel to send the message to. | ||
* @param {string} message - The message to send. | ||
*/ | ||
async say(channel, message) { | ||
throw new Error('say method must be implemented') | ||
} | ||
|
||
/** | ||
* Join a specific channel. | ||
* @param {string} channel - The channel to join. | ||
*/ | ||
async join(channel) { | ||
throw new Error('join method must be implemented') | ||
} | ||
|
||
/** | ||
* Leave a specific channel. | ||
* @param {string} channel - The channel to leave. | ||
*/ | ||
async part(channel) { | ||
throw new Error('part method must be implemented') | ||
} | ||
|
||
/** | ||
* Handle incoming messages. | ||
* This method should be overridden to handle messages in a platform-specific way. | ||
* @param {function} callback - The callback function to handle messages. | ||
*/ | ||
onMessage(callback) { | ||
throw new Error('onMessage method must be implemented') | ||
} | ||
} |
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,68 @@ | ||
// path/filename: src/chat/KickChatClient.js | ||
|
||
import { Kient } from 'kient' // Assuming Kient is the correct package for the Kick API | ||
|
||
import ChatPlatformClient from './ChatPlatformClient' | ||
|
||
/** | ||
* Kick chat client implementation. | ||
*/ | ||
export default class KickChatClient extends ChatPlatformClient { | ||
constructor(channelId) { | ||
super() | ||
this.client = null | ||
this.channelId = channelId | ||
} | ||
|
||
/** | ||
* Connect to Kick chat. | ||
*/ | ||
async connect() { | ||
this.client = await Kient.create() | ||
await this.client.api.authentication.login({ | ||
email: 'info@x.com', // Replace with actual credentials or configuration | ||
password: 'x', // Replace with actual credentials or configuration | ||
}) | ||
|
||
const channel = await this.client.api.channel.getChannel(this.channelId) | ||
await this.client.ws.chatroom.listen(channel.chatroom.id) | ||
|
||
console.log('[KICK] Connected to chat client') | ||
} | ||
|
||
/** | ||
* Send a message to a Kick channel. | ||
* This might need adjustment based on Kick API capabilities. | ||
* @param {string} channel - The channel to send the message to. | ||
* @param {string} message - The message to send. | ||
*/ | ||
async say(channel, message) { | ||
// Implementation depends on Kick API's capabilities | ||
} | ||
|
||
/** | ||
* Join a Kick channel. | ||
* This might be redundant or need adjustment based on Kick API capabilities. | ||
* @param {string} channel - The channel to join. | ||
*/ | ||
async join(channel) { | ||
// Implementation depends on Kick API's capabilities | ||
} | ||
|
||
/** | ||
* Leave a Kick channel. | ||
* This might be redundant or need adjustment based on Kick API capabilities. | ||
* @param {string} channel - The channel to leave. | ||
*/ | ||
async part(channel) { | ||
// Implementation depends on Kick API's capabilities | ||
} | ||
|
||
/** | ||
* Handle incoming messages from Kick. | ||
* @param {function} callback - The callback function to handle messages. | ||
*/ | ||
onMessage(callback) { | ||
this.client.on('onMessage', callback) | ||
} | ||
} |
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,66 @@ | ||
// path/filename: src/chat/TwitchChatClient.js | ||
|
||
import { ChatClient } from '@twurple/chat' | ||
|
||
import ChatPlatformClient from './ChatPlatformClient' | ||
import { getBotAuthProvider } from './twitch/lib/getBotAuthProvider' | ||
import { getChannels } from './twitch/lib/getChannels' | ||
|
||
/** | ||
* Twitch chat client implementation. | ||
*/ | ||
export default class TwitchChatClient extends ChatPlatformClient { | ||
constructor() { | ||
super() | ||
this.client = null | ||
} | ||
|
||
/** | ||
* Connect to Twitch chat. | ||
*/ | ||
async connect() { | ||
this.client = new ChatClient({ | ||
isAlwaysMod: true, | ||
botLevel: process.env.NODE_ENV === 'production' ? 'verified' : undefined, | ||
authProvider: await getBotAuthProvider(), | ||
channels: getChannels, | ||
webSocket: true, | ||
}) | ||
|
||
await this.client.connect() | ||
console.log('[TWITCH] Connected to chat client') | ||
} | ||
|
||
/** | ||
* Send a message to a Twitch channel. | ||
* @param {string} channel - The channel to send the message to. | ||
* @param {string} message - The message to send. | ||
*/ | ||
async say(channel, message) { | ||
await this.client.say(channel, message) | ||
} | ||
|
||
/** | ||
* Join a Twitch channel. | ||
* @param {string} channel - The channel to join. | ||
*/ | ||
async join(channel) { | ||
await this.client.join(channel) | ||
} | ||
|
||
/** | ||
* Leave a Twitch channel. | ||
* @param {string} channel - The channel to leave. | ||
*/ | ||
async part(channel) { | ||
await this.client.part(channel) | ||
} | ||
|
||
/** | ||
* Handle incoming messages from Twitch. | ||
* @param {function} callback - The callback function to handle messages. | ||
*/ | ||
onMessage(callback) { | ||
this.client.on('message', callback) | ||
} | ||
} |