Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// console.log('Bot Id: ', this.wechaty.userSelf().id)
// console.log(activity)
if (!recipientId) {
throw new Error('no recipient id')
}
if (!text) {
throw new Error('no text')
}
const user = this.wechaty.Contact.load(recipientId)
await user.say(text)
// console.log((activity.text != null) ? activity.text : '')
break
default:
log.error(`The [${activity.type}] is not supported by the Wechaty Adapter(yet).`)
break
}
}
return responses
}
log.info('on-message', 'Begin to find the OSS Bot ChatOps room')
const room = this.Room.load(CHATOPS_ROOM_ID)
if (room) {
await room.add(contact)
// To Be Fix: Change a formal welcome message
await room.say('Welcome to join OSS Bot ChatOps Group', contact)
}
}
log.info('on-message', 'onMessage(%s)', message)
try {
await VoteManager.checkVote(message)
} catch (e) {
log.error('on-message', 'Failed to check vote for the message:\n', e)
}
await dingDong.call(this, message)
await ctpStatus(this, message)
}
.catch(async e => {
log.error('Bot', 'start() fail: %s', e)
await bot.stop()
process.exit(-1)
})
.catch(async e => {
log.error('Bot', 'start() fail: %s', e)
await bot.stop()
process.exit(-1)
})
bot.on('error', async e => {
log.error('Bot', 'error: %s', e)
if (bot.logonoff()) {
await bot.say('Wechaty error: ' + e.message).catch(console.error)
}
})
/**
* room not found
*/
log.info('Bot', 'onMessage: dingRoom not found, try to create one')
/**
* create the ding room
*/
const newRoom = await createDingRoom(from)
console.log('createDingRoom id:', newRoom.id)
/**
* listen events from ding room
*/
await manageDingRoom()
}
} catch (e) {
log.error(e)
}
}
}
})
.start()
async function getOutRoom(contact, room) {
log.info('Bot', 'getOutRoom("%s", "%s")', contact, room)
try {
await room.say('You said "ding" in my room, I will remove you out.')
await room.del(contact)
} catch (e) {
log.error('Bot', 'getOutRoom() exception: ' + e.stack)
}
}
.on('room-topic', async function(room, topic, oldTopic, changer) {
try {
log.info('Bot', 'EVENT: room-topic - Room "%s" change topic from "%s" to "%s" by member "%s"',
room,
oldTopic,
topic,
changer,
)
await room.say(`room-topic - change topic from "${oldTopic}" to "${topic}" by member "${changer.name()}"` )
} catch (e) {
log.error('Bot', 'room-topic event exception: %s', e.stack)
}
})
.catch(e => log.error('StarterBot', e))
.catch(e => log.error('StarterBot', e))