Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
2bbf7da8
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 接近 3 年
通知
298
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,体验更适合开发者的 AI 搜索 >>
提交
2bbf7da8
编写于
6月 17, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
658b2030
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
37 deletion
+40
-37
examples/busy-bot.ts
examples/busy-bot.ts
+1
-1
src/io.ts
src/io.ts
+35
-32
src/message.ts
src/message.ts
+3
-3
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+1
-1
未找到文件。
examples/busy-bot.ts
浏览文件 @
2bbf7da8
...
...
@@ -65,7 +65,7 @@ if (token) {
bot
.
on
(
'
scan
'
,
(
qrcode
,
status
)
=>
{
generate
(
qrcode
,
{
small
:
true
})
console
.
log
(
`
${
status
}
\n[
${
qrcode
}
]
Scan QR Code of the url to login:`
)
console
.
log
(
`
${
status
}
:
${
qrcode
}
-
Scan QR Code of the url to login:`
)
})
.
on
(
'
logout
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logouted`
))
.
on
(
'
error
'
,
e
=>
log
.
info
(
'
Bot
'
,
'
error: %s
'
,
e
))
...
...
src/io.ts
浏览文件 @
2bbf7da8
...
...
@@ -16,8 +16,8 @@
* limitations under the License.
*
*/
import
WebSocket
from
'
ws
'
import
StateSwitch
from
'
state-switch
'
import
WebSocket
from
'
ws
'
import
{
StateSwitch
}
from
'
state-switch
'
import
{
Message
,
...
...
@@ -43,27 +43,34 @@ export interface IoOptions {
}
export
const
IO_EVENT_DICT
=
{
botie
:
'
tbw
'
,
error
:
'
tbw
'
,
heartbeat
:
'
tbw
'
,
login
:
'
tbw
'
,
logout
:
'
tbw
'
,
message
:
'
tbw
'
,
update
:
'
tbw
'
,
raw
:
'
tbw
'
,
reset
:
'
tbw
'
,
scan
:
'
tbw
'
,
sys
:
'
tbw
'
,
shutdown
:
'
tbw
'
,
botie
:
'
tbw
'
,
error
:
'
tbw
'
,
heartbeat
:
'
tbw
'
,
login
:
'
tbw
'
,
logout
:
'
tbw
'
,
message
:
'
tbw
'
,
update
:
'
tbw
'
,
raw
:
'
tbw
'
,
reset
:
'
tbw
'
,
scan
:
'
tbw
'
,
sys
:
'
tbw
'
,
shutdown
:
'
tbw
'
,
}
type
IoEventName
=
keyof
typeof
IO_EVENT_DICT
interface
IoEvent
{
interface
IoEventScan
{
name
:
'
scan
'
,
paylaod
:
PuppetScanEvent
,
}
interface
IoEventAny
{
name
:
IoEventName
,
payload
:
any
,
}
type
IoEvent
=
IoEventScan
|
IoEventAny
export
class
Io
{
private
readonly
cuid
:
string
private
readonly
protocol
:
string
...
...
@@ -113,10 +120,11 @@ export class Io {
await
this
.
initEventHook
()
this
.
ws
=
this
.
initWebSocket
()
this
.
options
.
wechaty
.
on
(
'
scan
'
,
(
qrcode
,
status
)
=>
{
this
.
scanPayload
=
Object
.
assign
(
this
.
scanPayload
||
{},
{
this
.
scanPayload
=
{
...
this
.
scanPayload
,
qrcode
,
status
,
}
)
}
})
this
.
state
.
on
(
true
)
...
...
@@ -300,21 +308,16 @@ export class Io {
case
'
update
'
:
log
.
verbose
(
'
Io
'
,
'
on(update): %s
'
,
ioEvent
.
payload
)
try
{
const
userId
=
this
.
options
.
wechaty
.
puppet
.
selfId
()
if
(
userId
)
{
const
loginEvent
:
IoEvent
=
{
name
:
'
login
'
,
payload
:
{
id
:
userId
,
name
:
this
.
options
.
wechaty
.
Contact
.
load
(
userId
).
name
(),
},
}
await
this
.
send
(
loginEvent
)
const
wechaty
=
this
.
options
.
wechaty
if
(
wechaty
.
logonoff
())
{
const
loginEvent
:
IoEvent
=
{
name
:
'
login
'
,
payload
:
{
id
:
wechaty
.
userSelf
().
id
,
name
:
wechaty
.
userSelf
().
name
(),
},
}
}
catch
(
e
)
{
// not login
await
this
.
send
(
loginEvent
)
}
if
(
this
.
scanPayload
)
{
...
...
@@ -406,7 +409,7 @@ export class Io {
const
ws
=
this
.
ws
if
(
ioEvent
)
{
log
.
silly
(
'
Io
'
,
'
send(%s
: %s)
'
,
ioEvent
.
name
,
ioEvent
.
payload
)
log
.
silly
(
'
Io
'
,
'
send(%s
)
'
,
JSON
.
stringify
(
ioEvent
)
)
this
.
eventBuffer
.
push
(
ioEvent
)
}
else
{
log
.
silly
(
'
Io
'
,
'
send()
'
)
}
...
...
src/message.ts
浏览文件 @
2bbf7da8
...
...
@@ -365,11 +365,11 @@ export class Message extends Accessory implements Sayable {
* @deprecated use toFile() instead
*/
public
async
file
():
Promise
<
FileBox
>
{
log
.
warn
(
'
Message
'
,
'
file() DEPRECATED. use toFile() instead.
'
)
return
this
.
toFile
()
log
.
warn
(
'
Message
'
,
'
file() DEPRECATED. use toFile
Box
() instead.
'
)
return
this
.
toFile
Box
()
}
public
async
toFile
():
Promise
<
FileBox
>
{
public
async
toFile
Box
():
Promise
<
FileBox
>
{
if
(
this
.
type
()
===
Message
.
Type
.
Text
)
{
throw
new
Error
(
'
text message no file
'
)
}
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
2bbf7da8
...
...
@@ -218,7 +218,7 @@ export class PuppetPadchat extends Puppet {
manager
.
on
(
'
logout
'
,
()
=>
this
.
logout
())
manager
.
on
(
'
reset
'
,
async
reason
=>
{
log
.
warn
(
'
PuppetPadchat
'
,
'
startManager() manager.on(
destroy
) for %s. Restarting PuppetPadchat ...
'
,
reason
)
log
.
warn
(
'
PuppetPadchat
'
,
'
startManager() manager.on(
reset
) for %s. Restarting PuppetPadchat ...
'
,
reason
)
await
this
.
reset
(
reason
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录