提交 099f64af 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 2cd28d87
......@@ -76,6 +76,10 @@ async function saveMediaFile(message: Message) {
const filename = message.filename()
console.log('IMAGE local filename: ' + filename)
if (!filename) {
throw new Error('no filename found for media file')
}
const fileStream = createWriteStream(filename)
console.log('start to readyStream()')
......
......@@ -52,7 +52,7 @@ bot
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
})
.on('login' , user => console.log(`${user} logined`))
.on('message', async function(this, msg) {
.on('message', async function(msg) {
console.log(`RECV: ${msg}`)
if (msg.type() !== Message.Type.VOICE) {
......@@ -61,7 +61,12 @@ bot
const mp3Stream = await msg.readyStream()
const file = createWriteStream(msg.filename())
const filename = msg.filename()
if (!filename) {
throw new Error('no filename for media message')
}
const file = createWriteStream(filename)
mp3Stream.pipe(file)
const text = await speechToText(mp3Stream)
......
......@@ -24,7 +24,9 @@ export abstract class PuppetAccessory extends EventEmitter {
}
public static get puppet(): Puppet {
log.silly('PuppetAccessory', '<%s> static get puppet()', this[this.PUPPET_ACCESSORY_NAME])
log.silly('PuppetAccessory', '<%s> static get puppet()',
this[this.PUPPET_ACCESSORY_NAME] || this.constructor.name,
)
if (this._puppet) {
return this._puppet
......
......@@ -156,7 +156,7 @@ export class MockMessage extends Message {
throw new Error('to be mocked')
}
public filename(): string {
public filename(): string | null {
return 'mocked_filename.txt'
}
......
......@@ -74,7 +74,10 @@ export abstract class Message extends PuppetAccessory implements Sayable {
readonly fileOrObj?: string | Object,
) {
super()
log.silly('Message', 'constructor()')
log.silly('Message', 'constructor(%s) for class %s',
fileOrObj || '',
this.constructor.name,
)
}
/**
......@@ -264,7 +267,7 @@ export abstract class Message extends PuppetAccessory implements Sayable {
/**
* Get the MediaMessage filename, etc: `how to build a chatbot.pdf`..
*
* @returns {string}
* @returns {string | null}
* @example
* bot.on('message', async function (m) {
* if (m instanceof MediaMessage) {
......@@ -272,7 +275,7 @@ export abstract class Message extends PuppetAccessory implements Sayable {
* }
* })
*/
public abstract filename(): string
public abstract filename(): string | null
/**
* Get the MediaMessage file extension, etc: `jpg`, `gif`, `pdf`, `word` ..
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册