小番茄机器人是一个脚本系统,它可以实现好友聊天,和群聊的一些基本功能,对话简单。
主要功能:
自动通过好友请求
好友聊天
群聊天(需要先拉进群,然后艾特才可以对话)
自动检测广告(不是很完善)
自动检测红包
聊天功能:
输入【指令】就会回复你具体玩法
业余时间,随手写的,功能简单,仅供学习交流。
开始安装:
准备一台电脑,一个微信号
1.下载python 3.0,然后安装。
2.运行cmd,执行 python 文件名字.py 即可弹出二维码,用准备好的微信扫码登录即可成为一个机器人。
3.以下是代码文件
#coding=utf8
from xml.etree import ElementTree as ET
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests
import itchat
import random
import os, time, io, re
import time
KEY = '去申请'
def get_response(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : msg,
'userid' : 'wechat-robot',
}
try:
r = requests.post(apiUrl, data=data).json()
return r
except:
return '呜呜呜,我的大脑出问题了,请赶紧找番茄大神来帮我修修吧...'
@itchat.msg_register(itchat.content.FRIENDS)
def add_friend(msg):
itchat.add_friend(**msg['Text'])
if msg['RecommendInfo']['Sex']==1 :
defaultReply = "您好!小帅哥 " + msg['RecommendInfo']['NickName']
else:
defaultReply = "您好!小美女 " + msg['RecommendInfo']['NickName']
defaultReply = defaultReply+',很高兴认识您,我除了陪您聊天,还可以查天气,查快递,讲笑话,查菜谱,查公交线路还有很多您慢慢发现吧...还可以拉我去您的群里面玩噢,群聊需要艾特我,我才会讲话,不懂的可以咨询开发者微信号:chaituan'
time.sleep(2)
itchat.send_msg(defaultReply.encode("utf-8"), msg['RecommendInfo']['UserName'])
# 欢迎新人消息
@itchat.msg_register(itchat.content.NOTE, isGroupChat=True)
def note_reply(msg):
text = msg['Text'].encode('utf-8')
print(text)
try :
hbindex = text.index('到红包,请在手机上查看')
except:
hbindex = 0
if hbindex > 0 :
time.sleep(2)
return '哇!老板又发红包了,大家赶紧来抢,我是不会和你们抢的o(∩_∩)o ...'.encode("utf-8")
else:
con_1 = re.compile('(.*?)邀请(.*?)加入了群聊').findall(text)
con_2 = re.compile('(.*?)通过扫描(.*?)分享的二维码加入群聊').findall(text)
if len(con_1)!= 0:
time.sleep(2)
return '@{}'.format(con_1[0][1].replace('"',''))+' 欢迎加入我们,来先爆个照,发个红包吧!'
if len(con_2)!= 0:
time.sleep(2)
return '@{}'.format(con_2[0][0].replace('"',''))+' 欢迎加入我们,来先爆个照,发个红包吧!'
return
@itchat.msg_register(itchat.content.TEXT,isFriendChat = True)
def text_reply(msg):
reply = ''
defaultReply = '呜呜呜,我的大脑出问题了,请赶紧找番茄大神来帮我修修吧...'
result = get_response(msg['Text'])
reply = result.get('text')
if 'url' in result:
reply = reply+result.get('url')
if 'list' in result:
if result['code']==308000 :
reply = reply+'---->'+result['list'][0]['name']+'---->'+result['list'][0]['info']+'---->'+result['list'][0]['detailurl']
elif result['code']==302000 :
reply = reply+'---->'+result['list'][0]['article']+'---->'+result['list'][0]['detailurl']
else :
reply = reply+'---->'+result['list'][0]['detailurl']
time.sleep(2)
return reply or defaultReply.encode("utf-8")
@itchat.msg_register(itchat.content.TEXT,isGroupChat = True)
def group_reply(msg):
reply = ''
defaultReply = '呜呜呜,我的大脑出问题了,请赶紧找番茄大神来帮我修修吧...'
if msg['isAt']:
ss = msg['Text'].replace('@'+msg['User']['Self']['NickName'],'')
s = ss.replace('@'+msg['User']['Self']['DisplayName'],'')
result = get_response(s)
reply = result.get('text')
if 'url' in result:
reply = reply+result.get('url')
if 'list' in result:
if result['code']==308000 :
reply = reply+'---->'+result['list'][0]['name']+'---->'+result['list'][0]['info']+'---->'+result['list'][0]['detailurl']
elif result['code']==302000 :
reply = reply+'---->'+result['list'][0]['article']+'---->'+result['list'][0]['detailurl']
else :
reply = reply+'---->'+result['list'][0]['detailurl']
reply = u'@%s\u2005 %s' % (msg['ActualNickName'], reply)
else:
return
time.sleep(2)
return reply or defaultReply.encode("utf-8")
itchat.auto_login(hotReload=True,enableCmdQR=2)
itchat.run()
演示机器人(有时候不在线,有时候在线)
版权声明:《 小番茄机器人的安装说明 》为Allen原创文章,转载请注明出处!
最后编辑:2019-8-5 10:08:04


提示:本文章评论功能已关闭