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

merge

......@@ -132,7 +132,12 @@ function wechaty::runBot() {
case "$botFile" in
*.js)
echo "Executing node $*"
node "$@" &
if [ "$NODE_ENV" != "production" ]; then
echo "Executing babel-node --presets es2015 $*"
babel-node --presets es2015 "$@" &
else
node "$@" &
fi
;;
*.ts)
# yarn add @types/node
......
{
"name": "wechaty",
"version": "0.8.31",
"version": "0.8.35",
"description": "Wechat for Bot(Personal Account)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -108,7 +108,7 @@
"@types/socket.io": "1.4.29",
"bl": "1.2.1",
"body-parser": "1.17.1",
"brolog": "1.1.16",
"brolog": "1.1.18",
"chromedriver": "2.29.0",
"express": "4.15.2",
"is-ci": "1.0.10",
......@@ -132,7 +132,9 @@
"@types/ws": "0.0.41",
"apiai": "4.0.2",
"ava": "0.18.2",
"babel-cli": "^6.24.1",
"babel-eslint": "7.2.3",
"babel-preset-es2015": "^6.24.1",
"check-node-version": "2.1.0",
"codelyzer": "3.0.1",
"cookie-parser": "1.4.3",
......@@ -154,7 +156,7 @@
"tslint-jsdoc-rules": "0.1.2",
"tuling123-client": "0.0.1",
"typescript": "2.3.2",
"yarn": "0.23.4"
"yarn": "0.24.4"
},
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
"files": [
......
......@@ -188,7 +188,7 @@ export interface RecommendInfo {
}
export interface Sayable {
say(content: string, replyTo?: any|any[]): Promise<void>
say(content: string, replyTo?: any|any[]): Promise<boolean>
}
export interface Sleepable {
......
......@@ -703,7 +703,7 @@ export class Contact implements Sayable {
public async say(text: string)
public async say(mediaMessage: MediaMessage)
public async say(textOrMedia: string | MediaMessage): Promise<void> {
public async say(textOrMedia: string | MediaMessage): Promise<boolean> {
const content = textOrMedia instanceof MediaMessage ? textOrMedia.filename() : textOrMedia
log.verbose('Contact', 'say(%s)', content)
......@@ -726,8 +726,7 @@ export class Contact implements Sayable {
m.to(this)
log.silly('Contact', 'say() from: %s to: %s content: %s', user.name(), this.name(), content)
await wechaty.send(m)
return
return await wechaty.send(m)
}
}
......
......@@ -141,8 +141,11 @@ export class Bridge {
try {
return await this.proxyWechaty('contactRemarkAsync', contactId, remark)
} catch (e) {
log.error('PuppetWebBridge', 'contactRemarkAsync() exception: %s', e.message)
throw e
log.verbose('PuppetWebBridge', 'contactRemarkAsync() exception: %s', e.message)
// Issue #509 return false instead of throw when contact is not a friend.
// throw e
log.warn('PuppetWebBridge', 'contactRemark() does not work on contact is not a friend')
return false
}
}
......@@ -245,7 +248,7 @@ export class Bridge {
})
}
public send(toUserName: string, content: string): Promise<void> {
public send(toUserName: string, content: string): Promise<boolean> {
if (!toUserName) {
throw new Error('UserName not found')
}
......@@ -384,7 +387,7 @@ export class Bridge {
}
}
public sendMedia(toUserName: string, mediaId: string, type: number): Promise<void> {
public sendMedia(toUserName: string, mediaId: string, type: number): Promise<boolean> {
if (!toUserName) {
throw new Error('UserName not found')
}
......
......@@ -425,7 +425,7 @@ export class PuppetWeb extends Puppet {
return mediaId as string
}
public async sendMedia(message: MediaMessage): Promise<void> {
public async sendMedia(message: MediaMessage): Promise<boolean> {
const to = message.to()
const room = message.room()
......@@ -448,16 +448,17 @@ export class PuppetWeb extends Puppet {
mediaId,
)
let ret = false
try {
await this.bridge.sendMedia(destinationId, mediaId, msgType)
ret = await this.bridge.sendMedia(destinationId, mediaId, msgType)
} catch (e) {
log.error('PuppetWeb', 'send() exception: %s', e.message)
throw e
return false
}
return
return ret
}
public async send(message: Message | MediaMessage): Promise<void> {
public async send(message: Message | MediaMessage): Promise<boolean> {
const to = message.to()
const room = message.room()
......@@ -472,8 +473,10 @@ export class PuppetWeb extends Puppet {
destinationId = to.id
}
let ret = false
if (message instanceof MediaMessage) {
await this.sendMedia(message)
ret = await this.sendMedia(message)
} else {
const content = message.content()
......@@ -483,20 +486,20 @@ export class PuppetWeb extends Puppet {
)
try {
await this.bridge.send(destinationId, content)
ret = await this.bridge.send(destinationId, content)
} catch (e) {
log.error('PuppetWeb', 'send() exception: %s', e.message)
throw e
}
}
return
return ret
}
/**
* Bot say...
* send to `filehelper` for notice / log
*/
public async say(content: string): Promise<void> {
public async say(content: string): Promise<boolean> {
if (!this.logined()) {
throw new Error('can not say before login')
}
......@@ -505,8 +508,7 @@ export class PuppetWeb extends Puppet {
m.to('filehelper')
m.content(content)
await this.send(m)
return
return await this.send(m)
}
/**
......
......@@ -444,7 +444,7 @@
function getBaseRequest() {
var accountFactory = WechatyBro.glue.accountFactory
var BaseRequest = accountFactory.getBaseRequest()
return JSON.stringify(BaseRequest)
}
......@@ -463,17 +463,23 @@
var confFactory = WechatyBro.glue.confFactory
if (!chatFactory || !confFactory) {
log('send() chatFactory or confFactory not exist.')
log('sendMedia() chatFactory or confFactory not exist.')
return false
}
var m = chatFactory.createMessage({
ToUserName: ToUserName
, MediaId: MediaId
, MsgType: Type
})
chatFactory.appendMessage(m)
return chatFactory.sendMessage(m)
try {
var m = chatFactory.createMessage({
ToUserName: ToUserName
, MediaId: MediaId
, MsgType: Type
})
chatFactory.appendMessage(m)
chatFactory.sendMessage(m)
} catch (e) {
log('sendMedia() exception: ' + e.message)
return false
}
return true
}
function send(ToUserName, Content) {
......@@ -484,13 +490,19 @@
log('send() chatFactory or confFactory not exist.')
return false
}
var m = chatFactory.createMessage({
ToUserName: ToUserName
, Content: Content
, MsgType: confFactory.MSGTYPE_TEXT
})
chatFactory.appendMessage(m)
return chatFactory.sendMessage(m)
try {
var m = chatFactory.createMessage({
ToUserName: ToUserName
, Content: Content
, MsgType: confFactory.MSGTYPE_TEXT
})
chatFactory.appendMessage(m)
chatFactory.sendMessage(m)
} catch (e) {
log('send() exception: ' + e.message)
return false
}
return true
}
function getContact(id) {
var contactFactory = WechatyBro.glue.contactFactory
......
......@@ -35,8 +35,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public abstract self(): Contact
public abstract send(message: Message | MediaMessage): Promise<void>
public abstract say(content: string): Promise<void>
public abstract send(message: Message | MediaMessage): Promise<boolean>
public abstract say(content: string): Promise<boolean>
public abstract reset(reason?: string): void
public abstract logout(): Promise<void>
......
......@@ -163,12 +163,12 @@ export class Room extends EventEmitter implements Sayable {
return this
}
public say(mediaMessage: MediaMessage): Promise<any>
public say(content: string): Promise<any>
public say(content: string, replyTo: Contact): Promise<void>
public say(content: string, replyTo: Contact[]): Promise<void>
public say(mediaMessage: MediaMessage)
public say(content: string)
public say(content: string, replyTo: Contact)
public say(content: string, replyTo: Contact[])
public say(textOrMedia: string | MediaMessage, replyTo?: Contact|Contact[]): Promise<void> {
public say(textOrMedia: string | MediaMessage, replyTo?: Contact|Contact[]): Promise<boolean> {
const content = textOrMedia instanceof MediaMessage ? textOrMedia.filename() : textOrMedia
log.verbose('Room', 'say(%s, %s)',
content,
......
......@@ -424,29 +424,27 @@ export class Wechaty extends EventEmitter implements Sayable {
/**
* @todo document me
*/
public async send(message: Message | MediaMessage): Promise<void> {
public async send(message: Message | MediaMessage): Promise<boolean> {
if (!this.puppet) {
throw new Error('no puppet')
}
await this.puppet.send(message)
.catch(e => {
log.error('Wechaty', 'send() exception: %s', e.message)
throw e
})
return
return await this.puppet.send(message)
.catch(e => {
log.error('Wechaty', 'send() exception: %s', e.message)
throw e
})
}
/**
* @todo document me
*/
public async say(content: string): Promise<void> {
public async say(content: string): Promise<boolean> {
log.verbose('Wechaty', 'say(%s)', content)
if (!this.puppet) {
throw new Error('no puppet')
}
this.puppet.say(content)
return
return await this.puppet.say(content)
}
/**
......
......@@ -19,6 +19,17 @@ fixture=test/fixture/docker
[ "$status" -ne 0 ]
}
@test "javascript es6 import should success" {
cd "$fixture"
run dockerRun es6-import.js
[ "$status" -eq 0 ] # should succ
}
@test "javascript es6 import with NODE_ENV=production should fail" {
cd "$fixture"
run dockerRun -e NODE_ENV=production es6-import.js
[ "$status" -ne 0 ] # should fail
}
@test "typescript bot" {
cd "$fixture"
......
import { Wechaty } from 'wechaty'
console.log(Wechaty.instance().version())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册