日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

itchat群机器人的自动画实现

發(fā)布時間:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 itchat群机器人的自动画实现 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

總體功能或思想
1、根據(jù) itchat文檔 實現(xiàn)簡單的聊天回復(fù)功能
2、添加敏感詞匯過濾、添加一些日常對話的回答
3、獲取群成員信息,收到消息后,如果是女同胞發(fā)言,則給出提示
4、接入圖靈機器人,提升日常會話能力

軟件安裝:
pip install itchat
pip install itchat_uos

import itchat import requests import json from itchat.content import *tuling = 1 daily_count = 32 flag = 0roomslist = [] ChatRoom = {}# 你要管理的群的列表 groupList = [ "tee22", "ARM-Trustzone-TEE-ATF", "None123" ]def auto_chat(text):data = {"perception": {"inputText": {"text": text}},"userInfo": {"apiKey": "xxxxxxxxxxxxxxx", ## 你的圖靈機器人KEY"userId": '123',}}req = json.dumps(data).encode('utf8')r = requests.post('http://openapi.tuling123.com/openapi/api/v2', data=req).textprint(r)r=json.loads(r)['results']for resutl in r:return resutl['values']['text']def lc():global ChatRoomprint('機器人HH在線')group = itchat.get_chatrooms(update=True)for g in group:print(g['NickName'])if g['NickName'] in groupList:itchat.send("[機器人HH上線] -- Hello,我是進化版HH,你有什么問題,可以直接問我, 但記得要艾特我哦!", g['UserName'])for i in getchatrooms():roomslist.append(i['NickName'])for n in roomslist:if(n=="ARM-Trustzone-TEE-ATF"):#填你想要分析的群名字ChatRoom = itchat.update_chatroom(getroom_message(n), detailedMember=True)breakdef ec():print('機器人HH在線退出')def getroom_message(n):#獲取群的username,對群成員進行分析需要用到itchat.dump_login_status() # 顯示所有的群聊信息,默認是返回保存到通訊錄中的群聊RoomList = itchat.search_chatrooms(name=n)if RoomList is None:print("%s group is not found!" % (name))else:return RoomList[0]['UserName']def getchatrooms():#獲取群聊列表roomslist = itchat.get_chatrooms()return roomslistdef check_sensitive(message):global flagreplay = ""flag = 1if u'逼' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'臥槽' in message:replay = u'含有敏感詞匯,請注意言辭'elif 'SB' in message:replay = u'含有敏感詞匯,請注意言辭'elif 'sb' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'傻' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'草' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'媽' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'MD' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'辣雞' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'垃圾' in message:replay = u'含有敏感詞匯,請注意言辭'else:flag = 0return replay@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING, PICTURE, RECORDING, ATTACHMENT, VIDEO], isGroupChat=True) def group_reply_text(msg):global flagglobal ChatRoomglobal tulingglobal daily_countprint("group_reply_text enter")message = msg['Text'] for i in ChatRoom['MemberList']:if msg['ActualNickName'] == i['NickName']:if i['Sex'] == 2:print("There's a girl")itchat.send("Hint : There is a girl appearing", msg['FromUserName'])replay = check_sensitive(message)if flag == 1:itchat.send(replay, msg['FromUserName'])returnif 'HH_rebot' not in message:returnif tuling == 1:replay = auto_chat(msg['Content'])# 用api得到回復(fù)內(nèi)容itchat.send(replay, msg['FromUserName'])daily_count = daily_count +1if daily_count >= 99:itchat.send("[進化版HH 下線了] -- Sorry, 我今天聊的太多了,要去休息了!", g['UserName'])itchat.send("[機器人HH上線] -- Hello,進化版HH哥哥去睡覺了,接下來你有什么問題,我可以幫著回答, 但記得要艾特我哦!!", g['UserName'])tuling = 0;returnflag = 0if u'干什么' in message:replay = u'在忙呢'elif u'生氣' in message:replay = u'生氣對身體不好'elif u'?' in message:replay = u'哈哈,我也不知道'elif u'不理你' in message:replay = u'乖,忙完給你買糖吃'elif u'濤' in message:replay = u'他是我主人'elif u'厲害' in message:replay = u'不不不,辣雞一個'elif u'你好' in message:replay = u'你好哇'elif u'好吧' in message:replay = u'再見'elif u'博客' in message:replay = u'您是想看群主博客嗎,可參考鏈接:\n https://blog.csdn.net/weixin_42135087/article/details/107037145'elif u'視頻' in message:replay = u'您是想看群主嗶哩嗶哩嗎,可參考鏈接:\n https://space.bilibili.com/482877928'elif u'你是誰' in message:replay = u'我是我們?nèi)旱臋C器人啊'elif u'名字' in message:replay = u'你不會點開我的頭像查看嗎'elif u'叫什么' in message:replay = u'我叫HH_rebot'elif u'歲' in message:replay = u'年齡是我的隱私,不要調(diào)戲人家好不'else:flag = 1if flag == 1:replay = u'對不起,我還不能理解您說的什么。正在進化中....'itchat.send(replay, msg['FromUserName'])@itchat.msg_register('Text') def text_reply(msg):message = msg['Text']print("11111111111111111111111:" + msg['FromUserName'])replay = u'[機器人自動回復(fù)]呵呵,您繼續(xù)吹!'if u'干什么' in message:replay = u'在忙呢'elif u'逼' in message:replay = u'含有敏感詞匯,請注意言辭'elif u'生氣' in message:replay = u'生氣對身體不好'elif u'?' in message:replay = u'哈哈,我也不知道'elif u'不理你' in message:replay = u'乖,忙完給你買糖吃'elif u'濤' in message:replay = u'他是我主人'elif u'厲害' in message:replay = u'不不不,辣雞一個'elif u'你好' in message:replay = u'你好哇'elif u'好吧' in message:replay = u'再見'#itchat.send("test",toUserName=msg['FromUserName'])return replayitchat.auto_login(loginCallback=lc, exitCallback=ec) itchat.run()

參考
1、使用圖靈機器人和itchat實現(xiàn)微信自動回復(fù)

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的itchat群机器人的自动画实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。