Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BillLi
ItChat
提交
7396ac5b
I
ItChat
项目概览
BillLi
/
ItChat
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
ItChat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7396ac5b
编写于
3月 11, 2016
作者:
L
LittleCoder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add different types of reply
上级
8ded04b5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
5 deletion
+58
-5
.gitignore
.gitignore
+2
-0
PluginTest.py
PluginTest.py
+16
-1
itchat/robot.py
itchat/robot.py
+17
-2
plugin/config/autoreply.db
plugin/config/autoreply.db
+0
-0
plugin/msgdealers/autoreply.py
plugin/msgdealers/autoreply.py
+23
-2
未找到文件。
.gitignore
浏览文件 @
7396ac5b
*.pyc
*.swp
log/*
storage/*
plugin/config/tuling.json
PluginTest.py
浏览文件 @
7396ac5b
...
...
@@ -63,6 +63,21 @@ if 'msgdealers.vote' in pluginList:
sys_print
(
'WARN'
,
'Vote plugin loaded failed, this is strange, you need to contact me'
)
traceback
.
print_exc
()
def
send_msg
(
msg
):
if
len
(
msg
)
>
5
:
if
msg
[:
5
]
==
'@fil@'
:
try
:
with
open
(
msg
[
5
:]):
pass
print
msg
[
5
:]
except
:
pass
elif
msg
[:
5
]
==
'@msg@'
:
print
msg
[
5
:]
else
:
print
msg
else
:
print
msg
[
5
:]
if
__name__
==
'__main__'
:
try
:
print
plugin_load_succeed
()
...
...
@@ -74,7 +89,7 @@ if __name__ == '__main__':
r
=
r
or
'
\n
'
.
join
(
tuling
.
get_response
(
msg
,
'ItChat'
))
if
not
r
:
r
=
'No plugin matched'
print
r
send_msg
(
r
)
except
:
print
'Exit'
traceback
.
print_exc
()
...
...
itchat/robot.py
浏览文件 @
7396ac5b
...
...
@@ -9,15 +9,30 @@ try:
except
:
TULING
=
False
def
send_msg
(
client
,
toUserName
,
msg
):
if
len
(
msg
)
>
5
:
if
msg
[:
5
]
==
'@fil@'
:
try
:
with
open
(
msg
[
5
:]):
pass
client
.
send_file
(
msg
[
5
:],
toUserName
)
except
:
pass
elif
msg
[:
5
]
==
'@msg@'
:
client
.
send_msg
(
toUserName
,
msg
[:
5
])
else
:
client
.
send_msg
(
toUserName
,
msg
)
else
:
client
.
send_msg
(
toUserName
,
msg
)
def
deal_with_msg
(
msg
,
s
,
client
):
if
msg
[
'MsgType'
]
==
'Text'
:
content
=
msg
[
'Content'
]
# test vote first
r
=
vote
(
client
.
storageClass
,
msg
[
'FromUserName'
],
content
)
if
r
!=
False
:
client
.
send_msg
(
msg
[
'FromUserName'
],
r
);
return
if
r
:
send_msg
(
client
,
msg
[
'FromUserName'
],
r
);
return
# test user's autoreply
r
=
autoreply
(
content
)
if
r
!=
False
:
client
.
send_msg
(
msg
[
'FromUserName'
],
r
);
return
if
r
:
send_msg
(
client
,
msg
[
'FromUserName'
],
r
);
return
# no plugin matched
client
.
send_msg
(
msg
[
'FromUserName'
],
'
\n
'
.
join
(
tuling
.
get_response
(
msg
[
'Content'
],
'ItChat'
))
if
TULING
else
'I received: %s'
%
msg
[
'Content'
])
...
...
plugin/config/autoreply.db
浏览文件 @
7396ac5b
无法预览此类型文件
plugin/msgdealers/autoreply.py
浏览文件 @
7396ac5b
...
...
@@ -3,10 +3,13 @@ import re, json, time, os
import
traceback
from
plugin.Sqlite3Client
import
Sqlite3Client
SQLITE_DIR
=
os
.
path
.
join
(
'plugin'
,
'config'
)
FILE_DIR
=
os
.
path
.
join
(
'storage'
,
'upload'
)
def
compileRegex
(
tableName
,
regexList
):
regex
=
''
try
:
with
Sqlite3Client
(
os
.
path
.
join
(
'plugin'
,
'config'
,
'autoreply.db'
))
as
s3c
:
with
Sqlite3Client
(
os
.
path
.
join
(
SQLITE_DIR
,
'autoreply.db'
))
as
s3c
:
for
qa
in
s3c
.
data_source
(
'select * from %s'
%
tableName
):
regex
=
qa
[
0
]
regexList
.
append
((
re
.
compile
(
qa
[
0
]),
qa
[
1
]))
...
...
@@ -14,10 +17,25 @@ def compileRegex(tableName, regexList):
raise
Exception
(
'Error occured when loading regex table %s: %s is not a correct regex'
%
(
tableName
,
regex
))
def
detectFiles
(
tableName
):
if
not
os
.
path
.
exists
(
FILE_DIR
):
os
.
makedirs
(
FILE_DIR
)
fileName
=
''
try
:
with
Sqlite3Client
(
os
.
path
.
join
(
SQLITE_DIR
,
'autoreply.db'
))
as
s3c
:
for
qa
in
s3c
.
data_source
(
'select * from %s'
%
tableName
):
if
qa
[:
5
]
==
'@fil@'
:
fileName
=
qa
[
5
:]
with
open
(
os
.
join
(
FILE_DIR
,
fileName
)):
pass
except
:
traceback
.
print_exc
()
raise
Exception
(
'Error occured when loading %s in table %s, it should be in storage/upload'
%
(
fileName
,
tableName
))
def
getreply
():
regexAnsList
=
[]
tableNameList
=
[
'default_reply'
]
for
tableName
in
tableNameList
:
detectFiles
(
tableName
)
compileRegex
(
tableName
,
regexAnsList
)
while
1
:
msg
=
(
yield
)
...
...
@@ -27,7 +45,10 @@ def getreply():
yield
r
getreplyiter
=
getreply
()
getreplyiter
.
next
()
def
autoreply
(
msg
):
r
=
getreplyiter
.
send
(
msg
)
if
r
and
r
[:
5
]
==
'@fil@'
:
r
=
'@fil@%s'
%
(
os
.
path
.
join
(
FILE_DIR
,
r
[
5
:]))
getreplyiter
.
next
()
return
getreplyiter
.
send
(
msg
)
return
r
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录