forked from stefantasy/ros_itchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWXgroupROS.py
More file actions
executable file
·83 lines (69 loc) · 2.51 KB
/
WXgroupROS.py
File metadata and controls
executable file
·83 lines (69 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#coding=utf8
# license removed for brevity
import requests
import itchat
import rospy
roskey = u'ROS'
group_name = u'政校企合作业务部'
group_id = u''
flag = 0
from std_msgs.msg import String
from itchat.content import *
@itchat.msg_register(TEXT,isGroupChat=True)
def wcMsg(msg):
global roskey
global group_name
global group_id
global flag
tts = rospy.Publisher('/voice_system/tts_topic', String, queue_size=10)
nlu = rospy.Publisher('/voice_system/nlu_topic', String, queue_size=10)
rospy.init_node('weChat2ROS', anonymous=True)
rate = rospy.Rate(10) # 10hz
if flag == 0:
group = itchat.get_chatrooms(update=True)
for g in group:
if g['NickName'] == group_name:#从群中找到指定的群聊
group_id = g['UserName']
flag+=1
break
msg0 = u''
if msg['FromUserName'] == group_id:
msg0 = msg['Text']
if msg0[0:10] == u'chchatroom':
group_name = msg0[10:]
flag = 0
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], u'控制群聊名已修改为'+group_name), group_id)
if msg0[0:8] == u'chroskey':
roskey = msg0[8:]
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], u'控制关键词已修改为'+roskey), group_id)
if msg0[0:6] == u'roskey':
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], u'当前控制关键词为'+roskey), group_id)
l = len(roskey)
msg1 = msg0[0:l]
msg2 = u''
if msg1 == roskey:
msg2 = msg0[l:]
if msg2 != u'':
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], u'您的指令“'+msg2+u'”已发送成功'), group_id)
if msg1 != roskey:
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], u'请输入"'+roskey+u' 指令"和卡丁互动'), group_id)
if msg2== u'前进' and msg1 == roskey:
itchat.send(u'ROS机器人-前进中', 'filehelper')
if msg2== u'后退' and msg1 == roskey:
itchat.send(u'ROS机器人-后退中', 'filehelper')
if msg2 == u'右转' and msg1 == roskey:
itchat.send(u'ROS机器人-右转中', 'filehelper')
if msg2 == u'左转' and msg1 == roskey:
itchat.send(u'ROS机器人-左转中', 'filehelper')
if msg2== u'停' and msg1 == roskey:
itchat.send(u'ROS机器人-不走了', 'filehelper')
if msg1 == roskey:
tts.publish(msg2)
nlu.publish(msg2)
rate.sleep()
msg0 = u''
return
if __name__ == '__main__':
itchat.auto_login(True)
itchat.run()