How to use the wechaty.log.warn function in wechaty

To help you get started, we’ve selected a few wechaty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wechaty / wechaty-getting-started / examples / professional / ctrl-c-signal-bot.ts View on Github external
finis(async (code, signal) => {
  log.info('Bot', 'finis(%s, %s)', code, signal)

  if (!bot.logonoff()) {
    log.info('Bot', 'finis() bot had been already stopped')
    doExit(code)
  }

  if (quiting) {
    log.warn('Bot', 'finis() already quiting... return and wait...')
    return
  }

  quiting = true
  let done = false
  // let checkNum = 0

  const exitMsg = `Wechaty will exit ${code} because of ${signal} `

  log.info('Bot', 'finis() broadcast quiting message for bot')
  await bot.say(exitMsg)
      // .then(() => bot.stop())
      .catch(e => log.error('Bot', 'finis() catch rejection: %s', e))
      .then(() => done = true)

  setImmediate(checkForExit)
github wechaty / wechaty-getting-started / examples / advanced / room-bot.js View on Github external
async function manageDingRoom() {
  log.info('Bot', 'manageDingRoom()')

  /**
   * Find Room
   */
  try {
    const room = await bot.Room.find({ topic: /^ding/i })
    if (!room) {
      log.warn('Bot', 'there is no room topic ding(yet)')
      return
    }
    log.info('Bot', 'start monitor "ding" room join/leave/topic event')

    /**
     * Event: Join
     */
    room.on('join', function(inviteeList, inviter) {
      log.verbose('Bot', 'Room EVENT: join - "%s", "%s"',
                         inviteeList.map(c => c.name()).join(', '),
                         inviter.name(),
      )
      console.log('room.on(join) id:', this.id)
      checkRoomJoin.call(this, room, inviteeList, inviter)
    })
github wechaty / wechaty-getting-started / examples / advanced / room-bot.js View on Github external
room.on('leave', (leaverList, remover) => {
      log.info('Bot', 'Room EVENT: leave - "%s" leave(remover "%s"), byebye', leaverList.join(','), remover || 'unknown')
    })

    /**
     * Event: Topic Change
     */
    room.on('topic', (topic, oldTopic, changer) => {
      log.info('Bot', 'Room EVENT: topic - changed from "%s" to "%s" by member "%s"',
            oldTopic,
            topic,
            changer.name(),
        )
    })
  } catch (e) {
    log.warn('Bot', 'Room.find rejected: "%s"', e.stack)
  }
}
github wechaty / wechaty-getting-started / examples / advanced / room-bot.js View on Github external
async function createDingRoom(contact) {
  log.info('Bot', 'createDingRoom("%s")', contact)

  try {
    const helperContact = await getHelperContact()

    if (!helperContact) {
      log.warn('Bot', 'getHelperContact() found nobody')
      await contact.say(`You don't have a friend called "${HELPER_CONTACT_NAME}",
                         because create a new room at least need 3 contacts, please set [HELPER_CONTACT_NAME] in the code first!`)
      return
    }

    log.info('Bot', 'getHelperContact() ok. got: "%s"', helperContact.name())

    const contactList = [contact, helperContact]
    log.verbose('Bot', 'contactList: "%s"', contactList.join(','))

    await contact.say(`There isn't ding room. I'm trying to create a room with "${helperContact.name()}" and you`)
    const room = await bot.Room.create(contactList, 'ding')
    log.info('Bot', 'createDingRoom() new ding room created: "%s"', room)

    await room.topic('ding - created')
    await room.say('ding - created')