29 lines
816 B
JavaScript
29 lines
816 B
JavaScript
// commandMatcher.js
|
||
|
||
/**
|
||
* Ищет команду в начале текста и возвращает объект с ботом и командой
|
||
* @param {string} text
|
||
* @param {Array<{ name: string, commands: Array<{ command: string }> }>} bots
|
||
* @returns {{ botName: string, commandName: string } | null}
|
||
*/
|
||
export function findCommandTargetBot(text, bots) {
|
||
if (!text) return null
|
||
|
||
// первое слово, без ведущего "/"
|
||
const [firstWord] = text.trim().split(/\s+/)
|
||
const normalized = firstWord.replace(/^\//, '').toLowerCase()
|
||
|
||
for (const b of bots) {
|
||
for (const cmd of b.commands || []) {
|
||
if (cmd.command.toLowerCase() === normalized) {
|
||
return {
|
||
botName: b.name,
|
||
commandName: cmd.command
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return null
|
||
}
|