Python项目:实现微信聊天机器人

说明,以下内容有很多个版本,都可以使用。自己根据日期分割来看看
'''


from wxpy import *
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot("deepThought")# 用于回复消息的机器人
chatbot.set_trainer(ChatterBotCorpusTrainer)
chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库

bot = Bot(cache_path=True)# 用于接入微信的机器人
group_2 = bot.groups()[0]# 进行测试的群
group_2.send("大家好,我是机器人Jack")

@bot.register(group_2)
def reply_my_friend(msg):
   print(msg)
   return chatbot.get_response(msg.text).text# 使用机器人进行自动回复

# 堵塞线程,并进入 Python 命令行
embed()

#2018-01-28 17:54:15 January Sunday the 04 week, the 028 day SZ SSMR
from wxpy import *

# 实例化,并登录微信

bot = Bot(cache_path=True)

# 调用图灵机器人API,api_key需要在图灵机器人官网注册账号,然后就有了

tuling = Tuling(api_key='a1bbc12dd78b4837b22cd8e98d96e027')

# 查找到要使用机器人来聊天的好友

groups1 = ensure_one(bot.search(u'小明深圳交流群','我是海归·吃货俱乐部2','原始森林.de','fancy','侯杏','DE Sprachstammtisch 1'))
groups1.send("hello,我是逗比出气筒Jack,欢迎随时撩我")
# 使用图灵机器人自动与指定好友聊天groups
@bot.register(groups1)

def auto_reply(msg):

    tuling.do_reply(msg)

embed()



#2018-01-27 15:44:14 January Saturday the 04 week, the 027 day SZ SSMR
#与所有人聊天,并且不用二维码,直接在手机登陆网页版微信就行

from wxpy import *
apikey = 'a1bbc12dd78b4837b22cd8e98d96e027'
#微信登录
robot = Robot()
#信息注册
@robot.register()
def Reply(msg):
    reply = Tuling(api_key=api_key).reply_text(msg,to_member=True)
    return reply

#监听
robot.start()
#2018-01-28 18:26:31 January Sunday the 04 week, the 028 day SZ SSMR

#2018-01-27 16:48:33 January Saturday the 04 week, the 027 day SZ SSMR
#与所有人聊天,并且不用二维码,直接在手机登陆网页版微信就行

from wxpy import *

# 实例化,并登录微信

bot = Bot(cache_path=True)

# 调用图灵机器人API


tuling = Tuling(api_key='a1bbc12dd78b4837b22cd8e98d96e027')

@bot.register()

def auto_reply(msg):

    tuling.do_reply(msg)

embed()
'''

#2018-01-27 15:42:22 January Saturday the 04 week, the 027 day SZ SSMR
#只能和特定微信群聊天
from wxpy import *
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot("deepThought")# 用于回复消息的机器人
chatbot.set_trainer(ChatterBotCorpusTrainer)
chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库

bot = Bot(cache_path=True)# 用于接入微信的机器人
#group_2 = bot.groups()[0]# 进行测试的群
#group_2.send("大家好,我是机器人Jack")

@bot.register()
def reply_my_friend(msg):
   print(msg)
   return chatbot.get_response(msg.text).text# 使用机器人进行自动回复

# 堵塞线程,并进入 Python 命令行
embed()
'''

#2018-01-28 19:04:29 January Sunday the 04 week, the 028 day SZ SSMR

from wxpy import *
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot("deepThought")# 用于回复消息的机器人
chatbot.set_trainer(ChatterBotCorpusTrainer)
chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库
bot = Bot(cache_path=True)# 用于接入微信的机器人

group_2 = bot.groups("友谊是")[0]# 进行测试的群
group_2.send("hi")

@bot.register(group_2)

def reply_my_friend(msg):
   print(msg)
   return chatbot.get_response(msg.text).text# 使用机器人进行自动回复

# 堵塞线程,并进入 Python 命令行
embed()
'''
'''

#2018-01-27 15:38:18 January Saturday the 04 week, the 027 day SZ SSMR
#robot = Robot()这行有问题,无法识别Robot()

#2018-01-27 16:49:30 January Saturday the 04 week, the 027 day SZ SSMR
#二维码在黑板里,无法扫描
import itchat
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
deepThought = ChatBot("deepThought")
deepThought.set_trainer(ChatterBotCorpusTrainer)
# 使用中文语料库训练它
deepThought.train("chatterbot.corpus.chinese") 

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    response = deepThought.get_response(msg['Text'])
    print("from",msg['FromUserName'],msg['Text'])
    print("to",response)
    itchat.send(msg=str(response),toUserName=msg['FromUserName'])

itchat.auto_login(enableCmdQR=True)
itchat.run()


'''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值