✨ Handle chat message commands (only for broadcaster)
This commit is contained in:
@@ -4,6 +4,8 @@ import { getAuthProvider, getUsernameFromId } from "../helpers/twitch";
|
|||||||
import { Action } from "../../interfaces/actions/Action";
|
import { Action } from "../../interfaces/actions/Action";
|
||||||
import { ActionType } from "../../enums/ActionType";
|
import { ActionType } from "../../enums/ActionType";
|
||||||
import { ChatClient } from "@twurple/chat";
|
import { ChatClient } from "@twurple/chat";
|
||||||
|
import { ChatCommands } from "../../enums/ChatCommands";
|
||||||
|
import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage";
|
||||||
import { broadcast } from "../helpers/webServer";
|
import { broadcast } from "../helpers/webServer";
|
||||||
import { start } from "../helpers/miniDb";
|
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}`);
|
console.log(`${LOG_PREFIX}No permission on ${channel}: ${message}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chatClient.onMessage(onMessage);
|
||||||
|
|
||||||
await chatClient.connect();
|
await chatClient.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,3 +83,32 @@ async function handleClientAction(action: Action): Promise<void> {
|
|||||||
console.log(`${[LOG_PREFIX]}Couldn't handle action:`, action);
|
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`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3
src/enums/ChatCommands.ts
Normal file
3
src/enums/ChatCommands.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export enum ChatCommands {
|
||||||
|
Commands = "commands",
|
||||||
|
}
|
Reference in New Issue
Block a user