直接上代码吧,里面比较简单。很容易实现
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from wxpy import *
import requests
# 图灵机器人 - 中文语境下智能度最高的机器人大脑
def tuling(info):
params = {
'key': 'db0b623ae0dd4e9ca28a89174abe156c',
'info': info,
}
try:
response = requests.get('http://www.tuling123.com/openapi/api', params = params, timeout = 10)
return response.json()['text'] + '〖自动回复〗'
except Exception as e:
pass
# 手机微信扫码登陆
bot = Bot(cache_path = True)
# 加自己为好友
bot.self.add()
bot.self.accept()
# 给自己发消息
bot.self.send('能收到吗?')
# 我的群组
my_groups = bot.groups().search('群组名称')[0]
# 我的妻子
my_wife = bot.friends().search('你老婆名称')[0]
# 测试消息发送功能
my_wife.send('我们分手吧')
my_wife.send('哈哈哈哈,这是机器人发的。')
# 自动打印剩余消息
@bot.register()
def print_others(msg):
print(msg)
# 自动回复群组消息
@bot.register(my_groups)
def reply_my_groups(msg):
if msg.type == 'Text':
content = msg.text
return tuling(content)
# 自动回复妻子消息
@bot.register(my_wife)
def reply_my_wife(msg):
if msg.type == 'Text':
content = msg.text
return tuling(content)
# 自动接受好友请求
@bot.register(msg_types = FRIENDS)
def auto_accept_friends(msg):
# 接受请求
new_friend = msg.card.accept()
# 发送消息
new_friend.send('哈哈,我自动接受了你的好友请求!')
# 进入 Python 命令行,程序在后台保持运行
embed()