Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BillLi
ItChat
提交
8ded04b5
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 搜索 >>
提交
8ded04b5
编写于
3月 10, 2016
作者:
L
LittleCoder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add PluginTest
上级
f7069467
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
100 addition
and
5 deletion
+100
-5
ItChat.py
ItChat.py
+4
-1
PluginTest.py
PluginTest.py
+83
-0
plugin/msgdealers/autoreply.py
plugin/msgdealers/autoreply.py
+6
-3
plugin/tuling.py
plugin/tuling.py
+1
-1
pluginlist.json
pluginlist.json
+6
-0
未找到文件。
ItChat.py
浏览文件 @
8ded04b5
#coding=utf8
import
time
import
time
,
sys
import
itchat.storage
,
itchat
.
out
,
itchat
.
argparser
,
itchat
.
robot
from
itchat.client
import
WeChatClient
from
plugin.ChatLikeCMD
import
ChatLikeCMD
...
...
@@ -14,6 +14,9 @@ def demo_robot(s, msgList, client): # ONLY FOR DEMO
if
s
.
find_nickname
(
msg
[
'FromUserName'
]):
itchat
.
robot
.
deal_with_msg
(
msg
,
s
,
client
)
time
.
sleep
(.
1
)
if
__name__
==
'__main__'
:
from
PluginTest
import
plugin_load_succeed
if
not
plugin_load_succeed
():
print
'Try to fix the plugins and test them with PluginTest.py'
;
sys
.
exit
()
client_s
=
itchat
.
storage
.
Storage
()
if
ROBOT
:
client
=
WeChatClient
(
client_s
,
robot
=
True
)
...
...
PluginTest.py
0 → 100644
浏览文件 @
8ded04b5
#coding=utf8
import
json
import
sys
,
traceback
,
os
succeed
=
True
def
plugin_load_succeed
():
return
succeed
def
sys_print
(
level
,
msg
):
if
level
==
'SUCC'
:
msg
+=
' plugin loaded'
if
level
==
'WARN'
:
global
succeed
;
succeed
=
False
print
'[%s] %s'
%
(
level
,
msg
)
# load plugin list
try
:
pluginListDir
=
'pluginlist.json'
with
open
(
pluginListDir
)
as
f
:
pluginList
=
json
.
loads
(
f
.
read
())
except
:
pluginList
=
[]
sys_print
(
'WARN'
,
'There is something wrong with the format of your pluginlist.json'
)
# Test tuling.py
if
'tuling'
in
pluginList
:
try
:
pluginList
.
remove
(
'tuling'
)
import
plugin.tuling
as
tuling
try
:
tuling
.
get_response
(
'Hi'
,
'LittleCoder'
)
pluginList
.
append
(
'tuling'
)
sys_print
(
'SUCC'
,
'Tuling'
)
except
:
sys_print
(
'WARN'
,
'Your key for tuling robot can
\'
t be used now, change one in plugin/config/tuling.json'
)
sys_print
(
'~~~~'
,
'You can get it from http://www.tuling123.com/'
)
except
:
sys_print
(
'WARN'
,
'There is something wrong with the format of your plugin/config/tuling.json'
)
# Test QRCode.py
if
'QRCode'
in
pluginList
:
try
:
import
plugin.QRCode
as
QRCode
sys_print
(
'SUCC'
,
'Command line QRCode'
)
except
:
sys_print
(
'INFO'
,
'Command line QRCode loaded failed, if you want to use this, you need to run `pip install Image`'
)
# Test msgdealers.autoreply
if
'msgdealers.autoreply'
in
pluginList
:
try
:
pluginList
.
remove
(
'msgdealers.autoreply'
)
from
plugin.msgdealers.autoreply
import
autoreply
pluginList
.
append
(
'msgdealers.autoreply'
)
sys_print
(
'SUCC'
,
'msgdealers.autoreply'
)
except
Exception
,
e
:
sys_print
(
'WARN'
,
str
(
e
))
# Test msgdealers.vote
if
'msgdealers.vote'
in
pluginList
:
try
:
from
plugin.msgdealers.vote
import
vote
sys_print
(
'SUCC'
,
'msgdealers.vote'
)
sys_print
(
'INFO'
,
'But whether it can be properly used need to be tested online'
)
except
:
sys_print
(
'WARN'
,
'Vote plugin loaded failed, this is strange, you need to contact me'
)
traceback
.
print_exc
()
if
__name__
==
'__main__'
:
try
:
print
plugin_load_succeed
()
while
True
:
msg
=
raw_input
(
'>'
).
decode
(
sys
.
stdin
.
encoding
)
if
'msgdealers.autoreply'
in
pluginList
:
r
=
autoreply
(
msg
)
if
'tuling'
in
pluginList
:
r
=
r
or
'
\n
'
.
join
(
tuling
.
get_response
(
msg
,
'ItChat'
))
if
not
r
:
r
=
'No plugin matched'
print
r
except
:
print
'Exit'
traceback
.
print_exc
()
else
:
sys_print
(
'INFO'
,
'Plugin loading finished'
)
plugin/msgdealers/autoreply.py
浏览文件 @
8ded04b5
...
...
@@ -4,18 +4,21 @@ import traceback
from
plugin.Sqlite3Client
import
Sqlite3Client
def
compileRegex
(
tableName
,
regexList
):
regex
=
''
try
:
with
Sqlite3Client
(
os
.
path
.
join
(
'plugin'
,
'config'
,
'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
]))
except
:
print
'Error occured when loading regex table %s'
%
tableName
traceback
.
print_exc
(
)
raise
Exception
(
'Error occured when loading regex table %s: %s is not a correct regex'
%
(
tableName
,
regex
)
)
def
getreply
():
regexAnsList
=
[]
tableNameList
=
[
'default_reply'
]
for
tableName
in
tableNameList
:
compileRegex
(
tableName
,
regexAnsList
)
for
tableName
in
tableNameList
:
compileRegex
(
tableName
,
regexAnsList
)
while
1
:
msg
=
(
yield
)
r
=
False
...
...
plugin/tuling.py
浏览文件 @
8ded04b5
...
...
@@ -6,7 +6,7 @@ from ChatLikeCMD import ChatLikeCMD
try
:
with
open
(
os
.
path
.
join
(
'plugin'
,
'config'
,
'tuling.json'
))
as
f
:
key
=
json
.
loads
(
f
.
read
())[
'key'
]
except
:
raise
Exception
(
'
You need to have a correct tuling.json file
'
)
raise
Exception
(
'
There is something wrong with the format of you plugin/config/tuling.json
'
)
def
get_response
(
msg
,
userid
):
url
=
'http://www.tuling123.com/openapi/api'
...
...
pluginlist.json
0 → 100644
浏览文件 @
8ded04b5
[
"QRCode"
,
"tuling"
,
"msgdealers.autoreply"
,
"msgdealers.vote"
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录