Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* 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)
/**
* 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)
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,
)
}
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
}
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+.+?<\/title>/si)
if (!matches) {
throw new Error('no matches for pr title')
}
const prTitle = matches[1]
return prTitle
}
</title>
/* && !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(''))
}
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!`)
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;
}
const avatarImg = () => {
const num = dayjs().day();
return FileBox.fromFile(`${process.cwd()}/assets/avatar/${num}.jpg`, 'avatar');
}
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)
}