Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function onMessage (message) {
try {
const room = message.room()
const sender = message.from()
const content = message.text()
const roomName = room ? `[${await room.topic()}] ` : ''
process.stdout.write(
`${roomName}<${sender.name()}>(${message.type()}:${message.typeSub()}): `)
if (message instanceof MediaMessage) {
saveMediaFile(message)
return
}
console.log(`${Misc.digestEmoji(message)}`)
// add an extra CR if too long
if (content.length > 80) console.log("")
const config = await hotImport('config.js')
// Hot import! Try to change the msgKW1&2 to 'ping' & 'pong'
// after the bot has already started!
if (content === config.msgKW1) {
await message.say(`${config.msgKW2}, thanks for ${config.msgKW1} me`)
log.info('Bot', `REPLY: ${config.msgKW2}`)
} else if (content === config.msgKW2) {
await sender.say('ok, ${config.msgKW2} me is welcome, too.')
} else if (/^hello/i.test(content)) {
return `How are you, ${sender.name()} from ${roomName}`
}
} catch (e) {
log.error('Bot', 'on(message) exception: %s' , e)