Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
d470fdd1
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d470fdd1
编写于
10月 16, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
f5ca15f4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
81 deletion
+55
-81
example/room-bot.ts
example/room-bot.ts
+36
-55
index.ts
index.ts
+9
-9
src/brolog-env.ts
src/brolog-env.ts
+10
-6
src/config.ts
src/config.ts
+0
-11
未找到文件。
example/room-bot.ts
浏览文件 @
d470fdd1
...
...
@@ -11,13 +11,6 @@
* ' leaver: 艾静<img class="emoji emojiae" text="_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />JOY
* - BUG2: leave event not right: sometimes can not found member (any more, because they left)
*/
import
{
Config
,
Contact
,
Room
,
Wechaty
,
log
}
from
'
../
'
/**
*
...
...
@@ -31,6 +24,32 @@ import {
*/
const
HELPER_CONTACT_NAME
=
'
Bruce LEE
'
import
{
Config
,
Contact
,
Room
,
Wechaty
,
log
}
from
'
../
'
const
welcome
=
`
=============== Powered by Wechaty ===============
-------- https://github.com/wechaty/wechaty --------
...
...
@@ -72,10 +91,16 @@ bot
* do initialization inside this event.
* (better to set a timeout, for browser need time to download other data)
*/
.
on
(
'
login
'
,
user
=>
{
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logined`
)
.
on
(
'
login
'
,
function
(
this
,
user
)
{
let
msg
=
`
${
user
.
name
()}
logined`
log
.
info
(
'
Bot
'
,
msg
)
this
.
say
(
msg
)
msg
=
`setting to manageDingRoom() after 3 seconds ... `
log
.
info
(
'
Bot
'
,
msg
)
this
.
say
(
msg
)
log
.
info
(
'
Bot
'
,
`setting to manageDingRoom() after 3 seconds ... `
)
setTimeout
(
manageDingRoom
.
bind
(
this
),
3000
)
})
...
...
@@ -120,7 +145,7 @@ bot
/**
* Global Event: message
*/
.
on
(
'
message
'
,
(
message
)
=>
{
.
on
(
'
message
'
,
function
(
this
,
message
)
{
const
room
=
message
.
room
()
const
sender
=
message
.
from
()
const
content
=
message
.
content
()
...
...
@@ -287,15 +312,6 @@ function checkRoomJoin(room: Room, invitee: Contact|Contact[] , inviter: Contact
,
invitee
)
// const atList = invitee.map
// ? invitee.map(c => '@' + c.name()).join(' ')
// : '@' + invitee.name()
// sendMessage(bot, {
// room
// , content: `${atList} Please contact me: by send "ding" to me, I will re-send you a invitation. Now I will remove you out, sorry.`
// , to: invitee.map ? invitee[0].id : invitee.id
// })
room
.
topic
(
'
ding - warn
'
+
inviter
.
name
())
setTimeout
(
_
=>
{
...
...
@@ -308,11 +324,6 @@ function checkRoomJoin(room: Room, invitee: Contact|Contact[] , inviter: Contact
room
.
say
(
'
Welcome to my room! :)
'
)
// sendMessage(bot, {
// room
// , content: `@${invitee.name()} Welcome to my room! :)`
// , to: invitee.id
// })
let
welcomeTopic
if
(
Array
.
isArray
(
invitee
))
{
welcomeTopic
=
invitee
.
map
(
c
=>
c
.
name
()).
join
(
'
,
'
)
...
...
@@ -328,20 +339,6 @@ function checkRoomJoin(room: Room, invitee: Contact|Contact[] , inviter: Contact
}
// function sendMessage(bot, {
// content
// , to
// , room = null
// }) {
// log.info('Bot', 'sendMessage(%s, {content: %s, to: %s, room: %s})', bot, content, to, room)
// const msg = new Message()
// msg.content(content)
// msg.room(room)
// msg.to(to)
// bot.send(msg)
// }
function
putInRoom
(
contact
,
room
)
{
log
.
info
(
'
Bot
'
,
'
putInRoom(%s, %s)
'
,
contact
.
name
(),
room
.
topic
())
...
...
@@ -351,11 +348,6 @@ function putInRoom(contact, room) {
log
.
error
(
'
Bot
'
,
'
room.add() exception: %s
'
,
e
.
stack
)
})
setTimeout
(
_
=>
room
.
say
(
'
Welcome
'
,
contact
),
1000
)
// setTimeout(_ => sendMessage(bot, {
// content: 'Welcome ' + contact.name()
// , room
// , to: contact
// }), 1000)
}
catch
(
e
)
{
log
.
error
(
'
Bot
'
,
'
putInRoom() exception:
'
+
e
.
stack
)
}
...
...
@@ -365,11 +357,6 @@ function getOutRoom(contact: Contact, room: Room) {
log
.
info
(
'
Bot
'
,
'
getOutRoom(%s, %s)
'
,
contact
,
room
)
try
{
// sendMessage(bot, {
// content: `@${contact.name()} You said "ding" in my room, I will remove you out.`
// , room: room.id
// , to: contact.id
// })
room
.
say
(
'
You said "ding" in my room, I will remove you out.
'
)
room
.
del
(
contact
)
}
catch
(
e
)
{
...
...
@@ -405,13 +392,7 @@ function createDingRoom(contact) {
log
.
info
(
'
Bot
'
,
'
createDingRoom() new ding room created: %s
'
,
room
)
room
.
topic
(
'
ding - created
'
)
room
.
say
(
'
ding - created
'
)
// sendMessage(bot, {
// content: ''
// , to: room
// , room
// })
return
room
})
...
...
index.ts
浏览文件 @
d470fdd1
import
Config
from
'
./src/config
'
import
Contact
from
'
./src/contact
'
import
IoClient
from
'
./src/io-client
'
import
Message
from
'
./src/message
'
import
Puppet
from
'
./src/puppet
'
import
PuppetWeb
from
'
./src/puppet-web/
'
import
Room
from
'
./src/room
'
import
UtilLib
from
'
./src/util-lib
'
import
Wechaty
from
'
./src/wechaty
'
import
Config
from
'
./src/config
'
import
Contact
from
'
./src/contact
'
import
IoClient
from
'
./src/io-client
'
import
Message
from
'
./src/message
'
import
Puppet
from
'
./src/puppet
'
import
PuppetWeb
from
'
./src/puppet-web/
'
import
Room
from
'
./src/room
'
import
UtilLib
from
'
./src/util-lib
'
import
Wechaty
from
'
./src/wechaty
'
import
log
from
'
./src/brolog-env
'
...
...
src/brolog-env.ts
浏览文件 @
d470fdd1
...
...
@@ -5,19 +5,23 @@
*
*/
// const log = require('npmlog')
import
log
from
'
brolog
'
import
Bro
log
from
'
brolog
'
const
level
=
process
.
env
[
'
WECHATY_LOG
'
]
const
levelRegexStr
=
'
silly|verbose|info|warn|error|silent
'
const
levelRegex
=
new
RegExp
(
levelRegexStr
,
'
i
'
)
if
(
levelRegex
.
test
(
level
))
{
// log.level = level.toLowerCase()
log
.
level
(
level
)
log
.
verbose
(
'
Brolog
'
,
'
WECHATY_LOG set level to %s
'
,
level
)
Bro
log
.
level
(
level
)
Bro
log
.
verbose
(
'
Brolog
'
,
'
WECHATY_LOG set level to %s
'
,
level
)
}
else
if
(
level
)
{
log
.
warn
(
'
Brolog
'
,
'
env WECHATY_LOG(%s) must be one of silly|verbose|info|warn|error|silent
'
,
level
)
Bro
log
.
warn
(
'
Brolog
'
,
'
env WECHATY_LOG(%s) must be one of silly|verbose|info|warn|error|silent
'
,
level
)
}
// module.exports = log.default = log.log = log
export
default
log
export
{
Brolog
,
Brolog
as
log
}
export
default
Brolog
src/config.ts
浏览文件 @
d470fdd1
...
...
@@ -127,17 +127,6 @@ export type WatchdogFood = {
|
'
SCAN
'
}
export
type
WechatyEventName
=
'
error
'
|
'
friend
'
|
'
heartbeat
'
|
'
login
'
|
'
logout
'
|
'
message
'
|
'
room-join
'
|
'
room-leave
'
|
'
room-topic
'
|
'
scan
'
export
type
ScanInfo
=
{
url
:
string
code
:
number
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录