當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript FileBox.fromFile方法代碼示例

本文整理匯總了TypeScript中file-box.FileBox.fromFile方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript FileBox.fromFile方法的具體用法?TypeScript FileBox.fromFile怎麽用?TypeScript FileBox.fromFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在file-box.FileBox的用法示例。


在下文中一共展示了FileBox.fromFile方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: contactAvatar

  public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
    log.verbose('PuppetMock', 'contactAvatar(%s)', contactId)

    /**
     * 1. set
     */
    if (file) {
      return
    }

    /**
     * 2. get
     */
    const WECHATY_ICON_PNG = path.resolve('../../docs/images/wechaty-icon.png')
    return FileBox.fromFile(WECHATY_ICON_PNG)
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:16,代碼來源:puppet-mock.ts

示例2: older


//.........這裏部分代碼省略.........
      )
      return
    }

    // Contact.findAll()
    if (/^testContact$/i.test(text)) {
      const contactList = await bot.Contact.findAll()
      let n = 0
      await from.say(
        contactList
          .map(contact => contact.name())
          .map(name => ++n + '. ' + name)
          .join('\n'),
      )
      return
    }

    if (/^fcontact$/.test(text)) {
      console.log('begin to check msg forward contact')
      // const contact = await bot.Contact.find({
      //   name: /李佳芮/,
      // })
      const contact = await bot.Contact.load('qq512436430')
      if (!contact) {
        console.error('contact not found')
        return
      }
      await msg.forward(contact)
      return
    }

    if (/^froom$/.test(text)) {
      console.log('begin to check msg forward room')
      const dingRoom = await bot.Room.find({ topic: /^ding/i })
      if (dingRoom) {
        await msg.forward(dingRoom)
      } else {
        await msg.say('Cannot find dingRoom, please create a ding room first!')
      }
      return
    }

    if (/^geta$/.test(text)) {
      console.log('begin to check get contact alias')
      await from.say(from.alias() || 'no alias')
      return
    }

    if (/^seta$/.test(text)) {
      console.log('begin to check set contact alias')
      await from.alias('wechaty-alias')
      setTimeout(async () => {
        await from.say(from.alias() || 'no alais')
      }, 3 * 1000)
      return
    }

    if (/^avatar$/.test(text)) {
      console.log('begin to check get contact avatar')
      const file = await from.avatar()
      await from.say(file)
      return
    }

    if (/^(ding|ping|bing|code)$/i.test(msg.text()) /*&& !msg.self()*/) {
      /**
       * 1. reply 'dong'
       */
      log.info('Bot', 'REPLY: dong')
      await msg.say('dong')

      const joinWechaty =  `Join Wechaty Developers' Community\n\n` +
                            `Wechaty is used in many ChatBot projects by hundreds of developers.\n\n` +
                            `If you want to talk with other developers, just scan the following QR Code in WeChat with secret code: wechaty,\n\n` +
                            `you can join our Wechaty Developers' Home at once`
      await msg.say(joinWechaty)

      /**
       * 2. reply qrcode image
       */
      const fileBox = FileBox.fromFile(BOT_QR_CODE_IMAGE_FILE)
      // const fileBox = FileBox.packStream(
      //   fs.createReadStream(BOT_QR_CODE_IMAGE_FILE),
      //   BOT_QR_CODE_IMAGE_FILE,
      // )

      log.info('Bot', 'REPLY: %s', fileBox)
      await msg.say(fileBox)

      /**
       * 3. reply 'scan now!'
       */
      await msg.say('Scan now, because other Wechaty developers want to talk with you too!\n\n(secret code: wechaty)')

    }
  } catch (e) {
    log.error('Bot', 'on(message) exception: %s' , e)
    console.error(e)
  }
})
開發者ID:miggame,項目名稱:wechaty,代碼行數:101,代碼來源:self-testing-bot.ts


注:本文中的file-box.FileBox.fromFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。