File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -152,3 +152,27 @@ WXBot对象还含有一些可以利用的方法
152
152
| send_msg(name, word, isfile) | 向好友发送消息,name为好友的备注名或者好友微信号,isfile为False时word为消息,isfile为True时word为文件路径(此时向好友发送文件里的每一行) |
153
153
| is_contact(uid) | 判断id为uid的账号是否是本帐号的好友,返回True(是)或False(不是) |
154
154
| is_public(uid) | 判断id为uid的账号是否是本帐号所关注的公众号,返回True(是)或False(不是) |
155
+
156
+
157
+ ## 5 Example
158
+
159
+ bot.py 用 ** [ 图灵机器人] ( http://www.tuling123.com/ ) ** API 以及 ** wxBot** 实现了一个自动回复机器人.
160
+
161
+ 此机器人会回复来自联系人的消息,以及群里@此账号的消息。
162
+
163
+ 群聊时需要将对应的群保存到联系人列表。
164
+
165
+ 群聊实现效果:
166
+
167
+ ![ 群聊] ( img/group_chat.png )
168
+
169
+
170
+ bot.py的运行方法:
171
+ 1 . 在[ 图灵机器人官网] ( http://www.tuling123.com/ ) 注册账号,申请图灵key: [ 图灵key申请地址] ( http://www.tuling123.com/html/doc/apikey.html )
172
+ 2 . 在bot.py文件所在目录下新建conf.ini文件,内容为(key字段内容为申请到的图灵key):
173
+
174
+ ``` txt
175
+ [main]
176
+ key=1d2678900f734aa0a23734ace8aec5b1
177
+ ```
178
+ 3 . 运行bot.py
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ def handle_msg_all(self, msg):
45
45
elif msg ['msg_type_id' ] == 3 : # group message
46
46
if msg ['content' ]['data' ].find ('@' ) >= 0 : # someone @ another
47
47
my_names = self .get_group_member_name (msg ['user' ]['id' ], self .user ['UserName' ])
48
+ if my_names is None :
49
+ my_names = {}
48
50
if 'NickName' in self .user and len (self .user ['NickName' ]) > 0 :
49
51
my_names ['nickname2' ] = self .user ['NickName' ]
50
52
if 'RemarkName' in self .user and len (self .user ['RemarkName' ]) > 0 :
You can’t perform that action at this time.
0 commit comments