当前位置: 首页>>代码示例>>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;未经允许,请勿转载。