1
0

Handle chat message commands (only for broadcaster)

This commit is contained in:
2022-01-06 02:49:09 +01:00
parent 1f78fdda64
commit ab8786b68b
2 changed files with 36 additions and 0 deletions

View File

@@ -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<any>): Promise<void> {
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<void> {
console.log(`${[LOG_PREFIX]}Couldn't handle action:`, action);
}
}
const commandPrefix = "!";
async function onMessage(
channel: string,
user: string,
message: string,
msg: TwitchPrivateMessage
): Promise<void> {
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`
);
}
}
}