Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chatAddPattern but with colours (raw message text I guess) #736

Closed
ghost opened this issue Nov 1, 2018 · 3 comments
Closed

chatAddPattern but with colours (raw message text I guess) #736

ghost opened this issue Nov 1, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 1, 2018

How can I add a pattern that checks for colours?

@plexigras
Copy link
Member

bot.on('message', msg => console.log(msg.toMotd()))

bot.on('message', msg => msg.toMotd().match(/regex/g) && console.log(msg.toString()))

@ghost
Copy link
Author

ghost commented Nov 1, 2018

@plexigras can I make new 'chat' events that match against the motd-formatted raw message?

@plexigras
Copy link
Member

you can do bot.emit('chat', ...) or copy, modify and use

function checkForChatPatterns (msg) {
const stringMsg = msg.toString()
// iterate through each object in chat.patterns array and test if .pattern matches
for (let i = 0; i < bot.chatPatterns.length; i++) {
const match = stringMsg.match(bot.chatPatterns[i].pattern)
if (match) {
bot.emit(bot.chatPatterns[i].type, ...match.slice(1), msg.translate, msg)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant