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)
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');
}