Python itchat 模块,msg_register() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用itchat.msg_register()

项目:WerewolvesWechatBot    作者:LouYu2015    | 项目源码 | 文件源码
def __init__(self, game_controller):
        super().__init__(game_controller)

        self.username_to_user = {} # Map Wechat user name to WechatUser object
        self.send_msg_queue = queue.Queue() # Avoid sending messages too fast by buffering

        # Start listening Wechat messages
        itchat.auto_login()
        threading.Thread(target = itchat.run).start()

        # Send messages in another thread
        threading.Thread(target = self.send_messages_in_queue).start()

        # Accept new messages from players
        @itchat.msg_register(itchat.content.TEXT)
        def listen_wechat_message(message_info):
            username = message_info['User']['UserName'] # User name of the Wechat user
            text = message_info['Text'] # Content of the message
            self.got_message(username, text)
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def note():  
    @itchat.msg_register(['Sharing'],isGroupChat=True)
    def collect_links(msg):
        try:
            received_date = datetime.datetime.now()
            title = msg['FileName']
            url = msg['Url']
            sharer = msg['ActualNickName']
            text = find_text(content=msg['Content'])
            print(title, sharer, text, url, received_date)
            store(received_date=received_date,
                title=title,
                url=url,
                sharer=sharer,
                text=text)
            print('data stored done')
        except Exception as e:
            print(e)
项目:WxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
def send_raw_msg(self, msgType, content, toUserName):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:WxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
def msg_register(self, msgType,
            isFriendChat=False, isGroupChat=False, isMpChat=False):
        ''' a decorator constructor
            return a specific decorator based on information given
        '''
        raise NotImplementedError()
项目:RasWxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
def send_raw_msg(self, msgType, content, toUserName):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:RasWxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
def msg_register(self, msgType,
            isFriendChat=False, isGroupChat=False, isMpChat=False):
        ''' a decorator constructor
            return a specific decorator based on information given
        '''
        raise NotImplementedError()
项目:wbot    作者:PY-Learning    | 项目源码 | 文件源码
def bind(self):
        all_type_list = [i for i in MessageType.__members__]
        itchat.msg_register(all_type_list, isFriendChat=True)(self._handle_friends)
        itchat.msg_register(all_type_list, isGroupChat=True)(self._handle_group)
        itchat.msg_register(all_type_list, isMpChat=True)(self._handle_mp)
项目:wbot    作者:PY-Learning    | 项目源码 | 文件源码
def send_raw_msg(msg_type, content, to_user_name):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['msg_type'], msg['Content'], msg['Fromuser_name'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def note():
    @itchat.msg_register(NOTE, isGroupChat=True)
    def deal_note(msg):
        try:
            pattern = r'??"(.*?)"?????'
            r = re.compile(pattern)
            result = r.findall(msg['Content'])[0]
            return(u"""
                    @%s
                    ??????
                    """ % result)
        except Exception as e:
            print(e)
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def run():
    @itchat.msg_register(TEXT)
    def open(msg):
        if u'??' in msg['Text']:
            open_txt()
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def note():
    @itchat.msg_register(NOTE, isGroupChat=True)
    def deal_note(msg):
        try:
            pattern = r'??"(.*?)"?????'
            r = re.compile(pattern)
            result = r.findall(msg['Content'])[0]
            return(u"""
                    @%s
                    ??????
                    """ % result)
        except Exception as e:
            print(e)
项目:ItChat    作者:littlecodersh    | 项目源码 | 文件源码
def send_raw_msg(self, msgType, content, toUserName):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:ItChat    作者:littlecodersh    | 项目源码 | 文件源码
def msg_register(self, msgType,
            isFriendChat=False, isGroupChat=False, isMpChat=False):
        ''' a decorator constructor
            return a specific decorator based on information given
        '''
        raise NotImplementedError()
项目:Soda    作者:linuxb    | 项目源码 | 文件源码
def send_raw_msg(self, msgType, content, toUserName):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:Soda    作者:linuxb    | 项目源码 | 文件源码
def msg_register(self, msgType,
            isFriendChat=False, isGroupChat=False, isMpChat=False):
        ''' a decorator constructor
            return a specific decorator based on information given
        '''
        raise NotImplementedError()
项目:WechatRobot    作者:TaceyWong    | 项目源码 | 文件源码
def send_raw_msg(self, msgType, content, toUserName):
        ''' many messages are sent in a common way
            for demo
                .. code:: python

                    @itchat.msg_register(itchat.content.CARD)
                    def reply(msg):
                        itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])

            there are some little tricks here, you may discover them yourself
            but remember they are tricks
            it is defined in components/messages.py
        '''
        raise NotImplementedError()
项目:WechatRobot    作者:TaceyWong    | 项目源码 | 文件源码
def msg_register(self, msgType,
            isFriendChat=False, isGroupChat=False, isMpChat=False):
        ''' a decorator constructor
            return a specific decorator based on information given
        '''
        raise NotImplementedError()
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def note():
    @itchat.msg_register(NOTE, isGroupChat=True)
    def deal_note(msg):
        try:
            pattern = r'??"(.*?)"?????'
            r = re.compile(pattern)
            result = r.findall(msg['Content'])[0]
            return(u"""
                    @%s
                    ??????
                    ??????
                    ?????????????,
                    ????? ???? ?? ?? 
                    ????? 14? ?? ?????
                    ps: ??????sharing.zhuojiayuan.com""" % result)
        except Exception as e:
            print(e)


    @itchat.msg_register(['Sharing'],isGroupChat=True)
    def collect_links(msg):
        try:

            received_date = datetime.datetime.now()
            title = msg['FileName']
            url = msg['Url']
            sharer = msg['ActualNickName']
            text = find_text(content=msg['Content'])
            print(title, sharer, text, url, received_date)
            store(received_date=received_date,
                title=title,
                url=url,
                sharer=sharer,
                text=text)
            print('data stored done')

            #????????flask????????????????
            #????controller/glinks.py?new??
            r = requests.get('http://www.zhuojiayuan.com:66/glinks/new')
            print(r.status_code)
        except Exception as e:
            print(e)