liuwons / wxBot

Deprecated
Apache License 2.0
5.36k stars 1.63k forks source link

主动向群推送消息 #112

Closed cndlan closed 7 years ago

cndlan commented 8 years ago

问了问群主大神,方法很简单,给推送不了的人看 首先把群设为联系人 然后就能发送,用send_msg

Lvxuedan commented 8 years ago

@cndlan 对的,启一个线程执行一个专门群发的函数; 下面是在定时任务里面执行的。

                for m in self.group_list: 
                    if self.DEBUG:
                        if m['PYQuanPin'] == 'aa':
                            self.send_msg_by_uid(u"整点播报,,Ծ‸Ծ,,", m['UserName'])

最近新增一个指定管理员向机器人发送指令群发消息的功能,在接受群消息之后加判断:

        elif msg['msg_type_id'] == 4 and msg['content']['type'] == 0:  # text message from contact
            # auto batch send message by bot
            if msg['user']['name'].encode('utf-8') == self.batch_send_manager and  msg['content']['data'].find(u'群发') != -1  and msg['content']['type'] == 0: #
                if msg['content']['data'].index(u'群发') == 0 :
                    self.batch_send_Mmessage = msg['content']['data'].replace(u'群发', '', 1)
                    self.send_msg_by_uid(self.batch_send_Mmessage, msg['user']['id']) 
                else:
                    self.send_msg_by_uid(self.tuling_auto_reply(msg['user']['id'], msg['content']['data']), msg['user']['id'])

            elif msg['user']['name'].encode('utf-8') == self.batch_send_manager and  msg['content']['data'] == u'确认发送' and msg['content']['type'] == 0: #
                if self.batch_send_Mmessage:
                    self.send_msg_by_uid(self.batch_send_Mmessage, msg['user']['id']) 
                    message = self.batch_send_Mmessage.replace('<br/>','\n')
                    self.BatchSendMessage(message)
                else:
                    self.send_msg_by_uid(u'需要发送什么?发送“群发+消息”给我看看~', msg['user']['id']) 

            elif msg['user']['name'].encode('utf-8') == self.batch_send_manager and  msg['content']['data'] == u'清空' and msg['content']['type'] == 0: #
                self.batch_send_Mmessage = ''
                self.send_msg_by_uid(u'好的,群发的内容清空了哈~', msg['user']['id'])