How to use file-box - 10 common examples

To help you get started, we’ve selected a few file-box 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 / examples / self-testing-bot.ts View on Github external
/**
       * 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)
github wechaty / wechaty-getting-started / examples / advanced / self-testing-bot.js View on Github external
/**
       * 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)
github wechaty / wechaty / src / puppet-padchat / padchat-manager.ts View on Github external
if (this.loginScanQrcode) {
      throw new Error('qrcode exist')
    }

    const result = await this.WXGetQRCode()
    if (!result || !result.qr_code) {
      log.verbose('PuppetPadchatManager', `emitLoginQrCode() result not found. Call WXInitialize() and try again ...`)

      await this.WXInitialize()

      // wait 1 second and try again
      await new Promise(r => setTimeout(r, 1000))
      return await this.emitLoginQrcode()
    }

    const fileBox = FileBox.fromBase64(result.qr_code, 'qrcode.jpg')
    const qrcodeDecoded = await fileBoxToQrcode(fileBox)

    this.loginScanQrcode = qrcodeDecoded
    this.loginScanStatus = WXCheckQRCodeStatus.WaitScan

    this.emit(
      'scan',
      this.loginScanQrcode,
      this.loginScanStatus,
    )
  }
github BUPT / ai-ml.club / src / pr-number-to-title.ts View on Github external
export async function prNumberToTitleByApi (
  org: string,
  repo: string,
  pr: number,
): Promise {
  const fileBox = FileBox.fromUrl(
    // https://stackoverflow.com/a/34601082/1123955
    `https://api.github.com/repos/${org}/${repo}/pulls/${pr}`,
    'pr.json',
    {
      'User-Agent': 'FileBox',
    }
  )
  const prJsonText = (await fileBox.toBuffer()).toString()
  // console.log(prJsonText)
  const prJson = JSON.parse(prJsonText)
  const prTitle = prJson.title as string
  return prTitle
}
github BUPT / ai-ml.club / src / pr-number-to-title.ts View on Github external
export async function prNumberToTitle (
  org: string,
  repo: string,
  pr: number,
): Promise {
  const fileBox = FileBox.fromUrl(
    `https://github.com/${org}/${repo}/pull/${pr}`,
    'pr.json',
  )
  const prHtml = (await fileBox.toBuffer()).toString()
  // console.log(prHtml)

  const matches = prHtml.match(/.+?<title>(.+?) by .+? · Pull Request #\d+.+?&lt;\/title&gt;/si)
  if (!matches) {
    throw new Error('no matches for pr title')
  }
  const prTitle = matches[1]
  return prTitle
}
</title>
github wechaty / wechaty / examples / ding-dong-bot.ts View on Github external
/* && !msg.self() */
  ) {
    console.info('Message discarded because it does not match ding/ping/bing/code')
    return
  }

  /**
   * 1. reply 'dong'
   */
  await msg.say('dong')
  console.info('REPLY: dong')

  /**
   * 2. reply image(qrcode image)
   */
  const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')

  await msg.say(fileBox)
  console.info('REPLY: %s', fileBox.toString())

  /**
   * 3. reply 'scan now!'
   */
  await msg.say([
    'Join Wechaty Developers Community\n\n',
    'Scan now, because other Wechaty developers want to talk with you too!\n\n',
    '(secret code: wechaty)',
  ].join(''))
}
github huan / file-box / tests / fixtures / smoke-testing.ts View on Github external
import Default, {
  FileBox,
  VERSION,
}             from 'file-box'

if (VERSION as any === '0.0.0') {
  throw new Error('version not set right before publish!')
}

if (Default !== FileBox) {
  throw new Error('default export does not match the exported module!')
}

const box = FileBox.fromFile(__filename)
console.log(`FileBox v${box.version()} smoke testing passed!`)
github BingKui / WeChatRobot / tools / assetTools.js View on Github external
const randomFile = (foolder) => {
    const path = `${process.cwd()}/assets/${foolder}`;
    const pathData = readDirData(path);
    let result = '暂时没有相关资源!';
    if (pathData.length > 0) {
        const filename = pathData[randomNum(0, pathData.length - 1)];
        result = FileBox.fromFile(`${path}/${filename}`);
    }
    console.log('获取到的文件为:', result);
    return result;
}
github BingKui / WeChatRobot / tools / assetTools.js View on Github external
const avatarImg = () => {
    const num = dayjs().day();
    return FileBox.fromFile(`${process.cwd()}/assets/avatar/${num}.jpg`, 'avatar');
}
github juzibot / wechaty-puppet-macpro / src / config.ts View on Github external
export function qrCodeForChatie (): FileBox {
  const name                           = 'qrcode-for-chatie.png'
  const type                           = 'png'

  const qrStream = qrImage.image(CHATIE_OFFICIAL_ACCOUNT_QRCODE, { type })
  return FileBox.fromStream(qrStream, name)
}

file-box

Pack a File into Box for easy move/transfer between servers no matter of where it is.(local path, remote url, or cloud storage)

Apache-2.0
Latest version published 2 years ago

Package Health Score

39 / 100
Full package analysis