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

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

项目:group-manager    作者:ai-chinade    | 项目源码 | 文件源码
def text_reply(msg):
    if is_at_me(msg.ToUserName):
        if users[msg.FromUserName] == FriendStatus.UNKNOWN:
            if check_trigger_words(msg.Content):
                users[msg.FromUserName] = FriendStatus.SELF_INTRO
                itchat.send_msg(msg=FIRST_REPLY % (msg.User.NickName, GROUP_NAME), toUserName=msg.FromUserName)
        elif users[msg.FromUserName] == FriendStatus.SELF_INTRO:
            if check_self_intro(msg.Content):
                users[msg.FromUserName] = FriendStatus.INVITE_SENT
                send_group_invitation(msg)
                intro_upcomming_member(msg.User.NickName, msg.Content)
                itchat.send_msg(msg=GOODBYE % (msg.User.NickName, GROUP_NAME), toUserName=msg.FromUserName)
            else:
                itchat.send_msg(msg=INTRO_FAILED, toUserName=msg.FromUserName)
        elif users[msg.FromUserName] == FriendStatus.INVITE_SENT and check_trigger_words(msg.Content):
            # the user sent trigger words again but the invitation already sent
            send_group_invitation(msg)
            itchat.send_msg(msg=GOODBYE % (msg.User.NickName, GROUP_NAME), toUserName=msg.FromUserName)
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def mainloop():
    global user
    global wefriendnc
    global weuser
    global role
    global wait
    global z
    global userlist
    #???[?????--?????--????????]
    #??????????????????
    #??????/???????????random?sleep
    #???????/????????????ending???120?????????????
    print(wefriendnc)
    for x in friendnc:
        print(x)
        itchat.send_msg(str(x)+"?"+friendnc[x],toUserName=groupchatmain)
        itchat.send_msg(str(x)+'?'+friendnc[x],toUserName=groupchatlangren)
    itchat.send_msg('???????????',toUserName=groupchatmain)
    itchat.send_msg('????????????????????id?',toUserName=groupchatlangren)
    wait='langren'
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def start(location=LOCATION, report_time=REPORT_TIME):

    if datetime.datetime.now().strftime('%H:%M') == report_time: #?? 03:25
        weather = ''
        count = 0
        while not weather:
            weather = get_weather(location)
            count += 1
            print('??????%d?' % count)
            time.sleep(1)
            if count >= 10:
                break
        if not weather:
            print('????????')
        else:
            #???????
            for USER_NAME in USER_NAME_LIST:
                num = itchat.search_friends(name = USER_NAME)[0]["UserName"]
                try:
                    itchat.send_msg(get_weather(location), num)
                except Exception as e:
                    print(e)
                #print(get_weather(location))
项目:loveliv    作者:xmcp    | 项目源码 | 文件源码
def send_msgs():
    with sqlite3.connect('events.db') as db:
        cur=db.cursor()
        cur.execute('select msgid,content from push_msgs')
        res=cur.fetchall()
        for msgid,content in res:
            if itchat.send_msg(content,toUserName=group_name):
                cur=db.cursor()
                cur.execute('delete from push_msgs where msgid=?',[msgid])
                db.commit()
                print(' -> sent msg:',content)
            else:
                if msgid not in logged_errors:
                    print('!!! send failed:',content)
                    log('error','?????????#%d??%s'%(msgid,content))
                    logged_errors.add(msgid)
            time.sleep(.5)
项目:group-manager    作者:ai-chinade    | 项目源码 | 文件源码
def intro_upcomming_member(user: str, intro: str) -> None:
    chatroom_id = itchat.search_chatrooms(name=GROUP_NAME)[0].UserName
    itchat.send_msg(msg=GROUP_INTRO % (user, intro), toUserName=chatroom_id)
项目:wbot    作者:PY-Learning    | 项目源码 | 文件源码
def send_msg(msg='Test Message', to_user_name=None):
        ''' send plain text message
            for options
                - msg: should be unicode if there's non-ascii words in msg
                - to_user_name: 'user_name' key of friend dict
            it is defined in components/messages.py
        '''
        return itchat.send_msg(msg, to_user_name)
项目:Neural-Headline-Generator-CN    作者:QuantumLiu    | 项目源码 | 文件源码
def send_text(text):
    #send text msgs to 'filehelper'
    #???????????
    try:
        itchat.send_msg(msg=text,toUserName='filehelper')
        return
    except (ConnectionError,NotImplementedError,KeyError):
        traceback.print_exc()
        print('\nConection error,failed to send the message!\n')
        return
    else:
        return
项目:Neural-Headline-Generator-CN    作者:QuantumLiu    | 项目源码 | 文件源码
def t_send(self,msg,toUserName='filehelper'):
        try:
            itchat.send_msg(msg=msg,toUserName=toUserName)
            return
        except (ConnectionError,NotImplementedError,KeyError):
            traceback.print_exc()
            print('\nConection error,failed to send the message!\n')
            return
        else:
            return
项目:assistant    作者:algorithmdaybyday    | 项目源码 | 文件源码
def add_friend(msg):
    if msg['RecommendInfo']['Content'] == 'Algorithm':
        msg.user.verify()
        itchat.send_msg('?????????????', msg['RecommendInfo']['UserName'])
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def ending(winner):
    global user
    global weuser
    global role
    global userlist
    global groupchatlangren
    global groupchatmain
    itchat.send_msg('?????????%s\n?????????'%winner,toUserName=groupchatmain)
    itchat.send_msg('?????????%s\n?????????'%winner,toUserName=groupchatlangren)
    userDict = []
    #???
    global idnow
    global roles
    global ifgame
    global langrenamout
    global cunminamout
    global yuyanjia
    global cunmin
    global langren
    global nvwu
    idnow=0
    ifgame=False
    user={}
    weuser={}
    role={}
    userlist=[]
    ifchosen=False
    groupchatmain=''
    groupchatlangren=''
    langren=[]
    cunmin=[]
    nvwu=''
    yuyanjia=''
    roles=['langren','nvwu','yuyanjia','cunmin']
    #??????+?????
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def goon():
    itchat.send_msg('??????????????????',toUserName=groupchatmain)
    if int(nvwu) in dead:
        time.sleep(10)
        itchat.send_msg('???????????10????',toUserName=user[nvwu])
    else:
        wait='nvwu'
        itchat.send_msg('????%s??????id???????/??',toUserName=user[nvwu])
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def nvwugoon():
    itchat.send_msg('????????????',toUserName=groupchatmain)
    itchat.send_msg('??????',toUserName=groupchatmain)
    if int(yuyanjia) in dead:
        time.sleep(10)
        itchat.send_msg('????????',toUserName=user[yuyanjia])
    else:
        wait='yuyanjia'
        itchat.send_msg('????????id?',toUserName=user[yuyanjia])
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def yuyanjiagoon():
    wait=''
    itchat.send_msg('????????????????',toUserName=groupchatmain)
    if save=='':
        save='???'
    if die=='':
        die='???'
    itchat.send_msg('??%s????%s??'%die,save)
    if save!='???':
        itchat.send_msg('??180????????????????????',toUserName=groupchatmain)
        wait='toupiao'
        time.sleep(180)
        wait=''
        toupiaoed=[]
        x=get_mode(toupiao)
        if x==None:
            itchat.send_msg('??????????????????',toUserName=groupchatmain)
        elif len(x)>1:
            y=random.choice(x)
            dead.append(y)
            itchat.send_msg('%s???'%y,toUserName=groupchatmain)
        elif len(x)==1:
            itchat.send_msg('%s???'%x[0],toUserName=groupchatmain)
            dead.append(x[0])
    dlr=0
    for lr in langren:
        if lr in dead:
            dlr=dlr+1
    if dlr==len(langren):
        ending('??')
    for cm in cunmin:
        if cm in dead:
            dcm=dcm+1
    if nvwu in dead:
        dcm=dcm+1
    if yuyanjia in dead:
        dcm=dcm+1
    if dcm==len(cunmin)+2:
        ending('??')
    mainloop()
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def sendmsg(msg,name):
        itchat.send_msg(msg,toUserName=Name2Wx[name])
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def group(people=None):
        if people==None:
            print('Err')
            return False
        global groupchatmain
        userDict=[]
        for userlist in people:
            userDict.append({"UserName":userlist})
            gctmp=itchat.create_chatroom(userDict, '???Beta')
            groupchatmain=gctmp['ChatRoomName']
            itchat.send_msg('???????',toUserName=groupchatmain)
            time.sleep(0.1)
            itchat.send_msg('??????????...',toUserName=groupchatmain)
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def langrengroup(people=None):
        global groupchatlangren
        if people==None:
            print('Err')
            return False
        userDict=[]
        for userlist in people:
            userDict.append({"UserName":userlist})
            gctmp=itchat.create_chatroom(userDict, '???-???Beta')
            groupchatlangren=gctmp['ChatRoomName']
            itchat.send_msg('????????,???????????\n???????????????????.',toUserName=groupchatmain)
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def send2group(msg):
        itchat.send_msg(msg,toUserName=groupchatmain)
项目:langrensha    作者:weilantian    | 项目源码 | 文件源码
def send2langren(msg):
        itchat.send_msg(msg,toUserName=groupchatlangren)
项目:Python-Learner    作者:fire717    | 项目源码 | 文件源码
def add_friend(msg, status=3):
    itchat.add_friend(**msg['Text']) # ????????????????????????
    time.sleep(5)
    itchat.send_msg(u'????????', msg['RecommendInfo']['UserName'])
项目:turing-chat    作者:CosmoGao    | 项目源码 | 文件源码
def fri_reply(msg):
    itchat.add_friend(**msg['Text'])
    itchat.send_msg('??????????', msg['RecommendInfo']['UserName'])
项目:Easy-wechat-script    作者:awefight    | 项目源码 | 文件源码
def  task_remind():
    for task in task_list:
        task_time = task[0]
        task_content = task[1]
        if datetime.datetime.now().strftime("%H:%M") == task_time:
            #name=????
            receiver = itchat.search_friends(name=u"Hoder")[0]["UserName"]
            itchat.send_msg(task_content, receiver)
项目:loveliv    作者:xmcp    | 项目源码 | 文件源码
def custom_push(msg):
    cmd,_,content=msg['Content'].partition(' ')
    if cmd.lower()=='send':
        return '??' if itchat.send_msg(content,toUserName=group_name) else '??'
项目:wbot    作者:ciknight    | 项目源码 | 文件源码
def add_friend(msg):
    logging.info('add friend {}, message {}'.format(msg['RecommendInfo']['UserName'], msg['Text']))
    itchat.add_friend(**msg['Text'])
    itchat.send_msg(faq.replay_welcome(), msg['RecommendInfo']['UserName'])
项目:WechatAutoReply    作者:raomuyang    | 项目源码 | 文件源码
def auto_reply_map(msg):
    try:
        loc = msg["Content"].split(":")
        if loc is not None:
            loc = loc[0]
            itchat.send_msg(msg="????????%s????" % loc, toUserName=msg['FromUserName'])
            resp = api.ask(loc + "???")
            if resp is not None:
                itchat.send_msg(msg=resp['text'], toUserName=msg['FromUserName'])
            else:
                return "???????"
    except Exception as e:
        print(str(e))