diff --git a/src/backend/chatClient/index.ts b/src/backend/chatClient/index.ts index 15aeeb7..a029ef7 100644 --- a/src/backend/chatClient/index.ts +++ b/src/backend/chatClient/index.ts @@ -4,6 +4,8 @@ import { getAuthProvider, getUsernameFromId } from "../helpers/twitch"; import { Action } from "../../interfaces/actions/Action"; import { ActionType } from "../../enums/ActionType"; import { ChatClient } from "@twurple/chat"; +import { ChatCommands } from "../../enums/ChatCommands"; +import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage"; import { broadcast } from "../helpers/webServer"; import { start } from "../helpers/miniDb"; @@ -35,6 +37,8 @@ async function connect(channels: Array): Promise { console.log(`${LOG_PREFIX}No permission on ${channel}: ${message}`); }); + chatClient.onMessage(onMessage); + await chatClient.connect(); } @@ -79,3 +83,32 @@ async function handleClientAction(action: Action): Promise { console.log(`${[LOG_PREFIX]}Couldn't handle action:`, action); } } + +const commandPrefix = "!"; + +async function onMessage( + channel: string, + user: string, + message: string, + msg: TwitchPrivateMessage +): Promise { + if (msg.userInfo.isBroadcaster && message.startsWith(commandPrefix)) { + message = message.substring(commandPrefix.length); + + const args = message.split(" "); + const commandName = args.shift(); + + switch (commandName) { + case ChatCommands.Commands: + await say( + channel, + `Comandos disponibles: "${Object.values(ChatCommands).join('", "')}"` + ); + break; + default: + console.log( + `${LOG_PREFIX}Command ${commandPrefix}${commandName} not handled` + ); + } + } +} diff --git a/src/enums/ChatCommands.ts b/src/enums/ChatCommands.ts new file mode 100644 index 0000000..21bec92 --- /dev/null +++ b/src/enums/ChatCommands.ts @@ -0,0 +1,3 @@ +export enum ChatCommands { + Commands = "commands", +}