Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/examples/chat_parsing.js
Views: 788
/*1this example is to show the different ways to parse chat messages23Expected output in console:45bot has just joined!6bot has just left!7bot has just rejoined!8bot has just left!9*/10const mineflayer = require('mineflayer')11const bot = mineflayer.createBot({12host: 'localhost',13username: 'bot'14})1516bot.once('spawn', () => {17bot.addChatPattern('bot_left_the_game', /bot. left the game/)18bot.addChatPatternSet('bot_rejoins_the_game', [/bot. left the game/, /bot. joined the game/])19bot.addChatPattern('who_just_joined', /(.+) joined the game/, { parse: true, repeat: false })20makeChatMessages()21})2223bot.on('chat:bot_left_the_game', matches => {24// => ['bot left the game']25console.log('bot has just left!')26})2728bot.on('chat:bot_rejoins_the_game', matches => {29// => ['bot left the game', 'bot joined the game']30console.log('bot has just rejoined!')31})3233bot.on('chat:who_just_joined', matches => {34console.log(`${matches[0]} has just joined!`) // should only run once35})3637async function makeChatMessages () {38let bot1 = mineflayer.createBot({39host: 'localhost',40username: 'bot1'41})42let bot243setTimeout(() => bot1.quit(), 1500)44setTimeout(() => {45bot1 = mineflayer.createBot({46host: 'localhost',47username: 'bot1'48})49}, 1750)50setTimeout(() => {51bot2 = mineflayer.createBot({52host: 'localhost',53username: 'bot2'54}, 2000)55})56setTimeout(() => bot2.quit(), 2500)57}5859bot.on('error', console.log)606162