Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
7848022b
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
305
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7848022b
编写于
10月 16, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add `implements Sayable`
上级
d3c163df
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
71 addition
and
114 deletion
+71
-114
README.md
README.md
+25
-73
src/contact.ts
src/contact.ts
+26
-25
src/message.ts
src/message.ts
+2
-1
src/puppet-web/wechaty-bro.js
src/puppet-web/wechaty-bro.js
+1
-0
src/puppet.ts
src/puppet.ts
+13
-7
src/room.ts
src/room.ts
+1
-1
src/wechaty.ts
src/wechaty.ts
+3
-7
未找到文件。
README.md
浏览文件 @
7848022b
...
...
@@ -261,12 +261,13 @@ $ export WECHATY_LOG=verbose
Win32:
```
shell
```
bat
set
WECHATY_LOG
=
verbose
```
Tips: You may want to have more scroll buffer size in your CMD window in windows.
```
shell
```
bat
mode
con
lines
=
32766
```
> http://stackoverflow.com/a/8775884/1123955
...
...
@@ -274,7 +275,7 @@ mode con lines=32766
### NpmLog with Timestamp ###
Here's a quick and dirty patch, to npmlog/log.js
```
java
script
```
type
script
m
.
message
.
split
(
/
\r?\n
/
).
forEach
(
function
(
line
)
{
var
date
=
new
Date
();
...
...
@@ -362,7 +363,7 @@ wechaty.on('scan', (this: Sayable, url: string, code: number) => {
### 2. Event: `login`
After the bot login full successful, the event
`login`
will be emitted, with a
[
Contact
](
#class-contact
)
of current logined user.
```
java
script
```
type
script
wechaty
.
on
(
'
login
'
,
(
this
:
Sayable
,
user
:
Contact
)
=>
{
console
.
log
(
`user
${
user
}
login`
)
})
...
...
@@ -372,7 +373,7 @@ wechaty.on('login', (this: Sayable, user: Contact) => {
`logout`
will be emitted when bot detected it is logout, with a
[
Contact
](
#class-contact
)
of current logined user.
```
java
script
```
type
script
wechaty
.
on
(
'
logout
'
,
(
this
:
Sayable
,
user
:
Contact
)
=>
{
console
.
log
(
`user
${
user
}
logout`
)
})
...
...
@@ -382,7 +383,7 @@ wechaty.on('logout', (this: Sayable, user: Contact) => {
Emit when there's a new message.
```
java
script
```
type
script
wechaty
.
on
(
'
message
'
,
(
this
:
Sayable
,
message
:
Message
)
=>
{
console
.
log
(
'
message ${message} received
'
)
})
...
...
@@ -392,7 +393,7 @@ wechaty.on('message', (this: Sayable, message: Message) => {
Emit when there's a error occoured.
```
java
script
```
type
script
wechaty
.
on
(
'
error
'
,
(
this
:
Sayable
,
err
:
Error
)
=>
{
console
.
log
(
'
error ${err.message} received
'
)
})
...
...
@@ -404,7 +405,7 @@ The `message` here is a [Message](#class-message).
Fired when we got new friend request, or confirm a friend ship.
```
t
ypescript
```
t
s
wechaty
.
on
(
'
friend
'
,
(
this
:
Sayable
,
contact
:
Contact
,
request
:
FriendRequest
)
=>
{
if
(
request
)
{
// 1. request to be friend from new contact
request
.
accept
()
...
...
@@ -417,7 +418,7 @@ wechaty.on('friend', (this: Sayable, contact: Contact, request: FriendRequest) =
### 7. Event: `room-join`
```
t
ypescript
```
t
s
wechaty
.
on
(
'
room-join
'
,
(
this
:
Sayable
,
room
:
Room
,
invitee
:
Contact
,
inviter
:
Contact
)
=>
{
console
.
log
(
`Room
${
room
}
got new member
${
invitee
}
, invited by
${
inviter
}
`
)
})
...
...
@@ -442,7 +443,7 @@ wechaty.on('room-topic', (this: Sayable, room: Room, topic: string, oldTopic: st
## Wechaty Class
Main bot class.
```
java
script
```
type
script
const
bot
=
Wechaty
.
instance
({
profile
})
...
...
@@ -455,7 +456,7 @@ const bot = Wechaty.instance({
### Wechaty.init(): Wechaty
Initialize the bot, return Promise.
```
java
script
```
type
script
wechaty
.
init
()
.
then
(()
=>
{
// do other staff with bot here
...
...
@@ -467,7 +468,7 @@ Check if message is send by self.
Return
`true`
for send from self,
`false`
for send from others.
```
java
script
```
type
script
if
(
wechaty
.
self
(
message
))
{
console
.
log
(
'
this message is sent by myself!
'
)
}
...
...
@@ -476,7 +477,7 @@ if (wechaty.self(message)) {
### Wechaty.send(message: Message): Wechaty
send a
`message`
```
java
script
```
type
script
const
msg
=
new
Message
()
msg
.
to
(
'
filehelper
'
)
msg
.
content
(
'
hello
'
)
...
...
@@ -484,15 +485,6 @@ msg.content('hello')
wechaty
.
send
(
msg
)
```
### @deprecated Wechaty.reply(message: Message, reply: String): Wechaty
Reply a
`message`
with
`reply`
.
That means: the
`to`
field of the reply message is the
`from`
of origin message.
```
javascript
wechaty
.
reply
(
message
,
'
roger
'
)
```
## Message Class
All wechat messages will be encaped as a Message.
...
...
@@ -520,43 +512,21 @@ A message may be not fully initialized yet. Call `ready()` to confirm we get all
Return a Promise, will be resolved when all data is ready.
```
java
script
```
type
script
message
.
ready
()
.
then
(()
=>
{
// Here we can be sure all the data is ready for use.
})
```
### @deprecated Message.get(prop): String|Contact|Room|Date
Get prop from a message.
Supported prop list:
1.
`id`
:String
1.
`from`
:Contact
1.
`to`
:Contact
1.
`content`
:String
1.
`room`
:Room
1.
`date`
:Date
```
javascript
message
.
get
(
'
content
'
)
```
### @deprecated Message.set(prop, value): Message
Set prop to value for a message.
Supported prop list: the same as
`get(prop)`
```
javascript
message
.
set
(
'
content
'
,
'
Hello, World!
'
)
```
## Contact Class
`Contact`
is
`Sayable`
### Contact.id: string
Uniq id
### Contact.name(): string
### Contact.ready(): Contact
...
...
@@ -564,35 +534,17 @@ A Contact may be not fully initialized yet. Call `ready()` to confirm we get all
Return a Promise, will be resolved when all data is ready.
```
java
script
```
type
script
contact
.
ready
()
.
then
(()
=>
{
// Here we can be sure all the data is ready for use.
})
```
### Contact.say(content: string)
### Contact.say(content: string)
: Promise<void>
say
`content`
to Contact
### @deprecated Contact.get(prop): String|Number
Get prop from a contact.
Supported prop list:
1.
`id`
:String
1.
`weixin`
:String
1.
`name`
:String
1.
`remark`
:String
1.
`sex`
:Number
1.
`province`
:String
1.
`city`
:String
1.
`signature`
:String
```
javascript
contact
.
get
(
'
name
'
)
```
## Class Room
`Room`
is
`Sayable`
...
...
@@ -611,7 +563,7 @@ A room may be not fully initialized yet. Call `ready()` to confirm we get all th
Return a Promise, will be resolved when all data is ready.
```
java
script
```
type
script
room
.
ready
()
.
then
(()
=>
{
// Here we can be sure all the data is ready for use.
...
...
@@ -630,7 +582,7 @@ which means there will be a `this.say()` method inside listener call, you can us
#### Event: `join`
```
java
script
```
type
script
Room
.
on
(
'
join
'
,
(
invitee
,
inviter
)
=>
void
)
```
...
...
@@ -670,7 +622,7 @@ Room.findAll(query : Query) : Room[]
### Room.add(contact: Contact): Promise<any>
```
java
script
```
type
script
const
friend
=
message
.
get
(
'
from
'
)
const
room
=
Room
.
find
({
name
:
'
Group Name
'
})
if
(
room
)
{
...
...
@@ -706,7 +658,7 @@ Supported prop list:
1.
`contact`
:Contact
1.
`name`
:String
```
java
script
```
type
script
room
.
get
(
'
members
'
).
length
```
...
...
src/contact.ts
浏览文件 @
7848022b
...
...
@@ -6,47 +6,50 @@
* https://github.com/zixia/wechaty
*
*/
import
Config
from
'
./config
'
import
{
Config
,
Sayable
}
from
'
./config
'
import
Message
from
'
./message
'
import
UtilLib
from
'
./util-lib
'
import
Wechaty
from
'
./wechaty
'
import
log
from
'
./brolog-env
'
type
ContactObj
=
{
id
:
string
uin
:
string
name
:
string
remark
:
string
weixin
:
string
sex
:
string
province
:
string
city
:
string
signature
:
string
address
:
string
stranger
:
boolean
star
:
boolean
city
:
string
id
:
string
name
:
string
province
:
string
remark
:
string
sex
:
string
signature
:
string
star
:
boolean
stranger
:
boolean
uin
:
string
weixin
:
string
}
type
ContactRawObj
=
{
UserName
:
string
Uin
:
string
export
type
ContactRawObj
=
{
Alias
:
string
RemarkName
:
string
Sex
:
string
Province
:
string
City
:
string
NickName
:
string
StarFriend
:
string
stranger
:
string
Province
:
string
RemarkName
:
string
Sex
:
string
Signature
:
string
StarFriend
:
string
Uin
:
string
UserName
:
string
stranger
:
string
// assign by injectio.js
}
type
ContactQueryFilter
=
{
export
type
ContactQueryFilter
=
{
name
:
string
|
RegExp
}
class
Contact
{
export
class
Contact
implements
Sayable
{
private
static
pool
=
new
Map
<
string
,
Contact
>
()
private
obj
:
ContactObj
...
...
@@ -223,6 +226,4 @@ class Contact {
// return []
// }
// module.exports = Contact.default = Contact.Contact = Contact
export
default
Contact
src/message.ts
浏览文件 @
7848022b
...
...
@@ -9,6 +9,7 @@
import
{
Config
,
RecommendInfo
,
Sayable
}
from
'
./config
'
import
Contact
from
'
./contact
'
...
...
@@ -48,7 +49,7 @@ export type MessageType = {
[
index
:
string
]:
number
|
string
}
export
class
Message
{
export
class
Message
implements
Sayable
{
public
static
counter
=
0
private
_counter
:
number
...
...
src/puppet-web/wechaty-bro.js
浏览文件 @
7848022b
...
...
@@ -431,6 +431,7 @@
if
(
c
)
{
if
(
c
.
isContact
)
{
// extend rawObj to identify `stranger`
c
.
stranger
=
!
(
c
.
isContact
())
}
...
...
src/puppet.ts
浏览文件 @
7848022b
...
...
@@ -12,6 +12,9 @@
import
{
EventEmitter
}
from
'
events
'
import
{
Sayable
}
from
'
./config
'
import
Contact
from
'
./contact
'
import
Message
from
'
./message
'
import
Room
from
'
./room
'
...
...
@@ -21,7 +24,7 @@ import log from './brolog-env'
// (id: string): Promise<any>
// }
abstract
class
Puppet
extends
EventEmitter
{
export
abstract
class
Puppet
extends
EventEmitter
implements
Sayable
{
public
userId
:
string
public
user
:
Contact
public
abstract
getContact
(
id
:
string
):
Promise
<
any
>
...
...
@@ -81,22 +84,25 @@ abstract class Puppet extends EventEmitter {
public
abstract
quit
():
Promise
<
any
>
public
abstract
ding
(
data
?:
string
):
Promise
<
any
>
/**
* FriendRequest
*/
public
abstract
friendRequestSend
(
contact
:
Contact
,
hello
?:
string
):
Promise
<
any
>
public
abstract
friendRequestAccept
(
contact
:
Contact
,
ticket
:
string
):
Promise
<
any
>
/**
* Room
*/
public
abstract
roomAdd
(
room
:
Room
,
contact
:
Contact
):
Promise
<
number
>
public
abstract
roomDel
(
room
:
Room
,
contact
:
Contact
):
Promise
<
number
>
public
abstract
roomTopic
(
room
:
Room
,
topic
:
string
):
Promise
<
string
>
public
abstract
roomCreate
(
contactList
:
Contact
[],
topic
?:
string
):
Promise
<
Room
>
public
abstract
roomFind
(
filterFunc
:
string
):
Promise
<
Room
[]
>
/**
* Contact
*/
public
abstract
contactFind
(
filterFunc
:
string
):
Promise
<
Contact
[]
>
}
export
default
Puppet
export
{
Contact
,
Message
,
Puppet
,
Room
}
src/room.ts
浏览文件 @
7848022b
...
...
@@ -49,7 +49,7 @@ export type RoomQueryFilter = {
topic
:
string
|
RegExp
}
export
class
Room
extends
EventEmitter
{
export
class
Room
extends
EventEmitter
implements
Sayable
{
private
static
pool
=
new
Map
<
string
,
Room
>
()
private
dirtyObj
:
RoomObj
// when refresh, use this to save dirty data for query
...
...
src/wechaty.ts
浏览文件 @
7848022b
/**
*
* wechaty: Wechat for ChatBots.
* Wechaty: Wechat for ChatBots.
* Connect ChatBots
*
* Class Wechaty
*
...
...
@@ -33,7 +34,6 @@ export type WechatySetting = {
profile
?:
string
head
?:
HeadType
type
?:
PuppetType
// port?: number
}
type
WechatyEventName
=
'
error
'
...
...
@@ -48,7 +48,7 @@ type WechatyEventName = 'error'
|
'
scan
'
|
'
EVENT_PARAM_ERROR
'
export
class
Wechaty
extends
EventEmitter
{
export
class
Wechaty
extends
EventEmitter
implements
Sayable
{
private
static
_instance
:
Wechaty
public
puppet
:
Puppet
...
...
@@ -309,8 +309,4 @@ export class Wechaty extends EventEmitter {
}
}
/**
* Expose `Wechaty`.
*/
// module.exports = Wechaty.default = Wechaty.Wechaty = Wechaty
export
default
Wechaty
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录