微信自动问答脚本

去年年初写的微信问答工具,现在版本是否支持不清楚,这里只是做一下记录

源代码

import threading # 导入模块 3.7自带 threading 无需安装。 from ks import * #导入已经在文件夹的ks.pyd 模块 ks 无需insatll import urllib.request import time import random import ssl # from apscheduler.schedulers.background import BackgroundScheduler # 引入定时模块 ssl._create_default_https_context = ssl._create_unverified_context # 接口自签名验证抛错 取消证书验证 # url = 'http://api.tianapi.com/txapi/caihongpi/index?key=APIKEY' chp_url = 'https://chp.shadiao.app/api.php' # 彩虹屁接口 zu_an_url = 'https://zuanbot.com/api.php?level=min&lang=zh_cn' # 祖安语录 chp_send_count=1 # 一次发送的彩虹屁消息个数 game_power='开始游戏' # 游戏口令 players=[] # 所有玩家的信息 total_count= 5 # 总共需要答题数 questions_bank=[{title:'周郎计策安天下',answer:'赔了夫人又折兵'},{title:'九台压路机压坏了一台',answer:'八个压路'},{title:'江东的百姓好脾气',answer:'吴人能急'}] # player=[{ # id:'', # correct:0, # lastA:'' # error:0, # total:0 # }] # 玩家信息 # 请求方法 def requestText(_url): time.sleep(0.5) # 休眠0.5s req = urllib.request.Request(_url) resp = urllib.request.urlopen(req) content = resp.read() contentece=content.decode('utf-8') # 编码输出 if(contentece): print(contentece) return contentece return 0 # questions_bank=[question,question] # question:{ title:'题目',answer:'答案'} def question(character):# 生成问题 id =character.get('id') # 玩家id count = character.get('count') # 所答对的问题数 total = character.get('total')+1 # 所答题目总数 character['total']=total r=random.randint(0,len(questions_bank)-1) # 随机生成题目 question="第"+total+"道" +". "+ questions_bank[r].get('title')+" 下一句是?" print(question) # 输出 发送题目 fxx(id, question) # 发送题目 character['lastA'] =questions_bank[r].get('answer') # 将题目答案保存在玩家信息中 def judgeExist(single){ for i in range(len(players)): if players[i].get("id") == single: print("角色已存在") return i return -1 # 角色不存在 } def msgdata(): #监听消息实例 通过消息来判断 print("kaishi") msger = jtxx() #回调内部方法。如pycharm报红色字体。可以忽视。照样运行 for data in msger: #打印方法 print(data) #这里回调所有消息。可以直接使用 if data[0]=="msgdp": #消息内容 if data[5]=="0": #1代表发送消息 0代表收到消息 if data[2].find("@chatroom") == -1 and data[2][0:3].find("gh_") == -1: #排除 群里发的消息 公众号收到的消息 global players print("私人消息") seq = judgeExist(data[2]) # 判断玩家是否存在,存在则返回下标,不存在则返回-1 if (data[6] == game_power) and (seq == -1): pl = { 'id':data[2],'correct':0,'lastA':'','error':0,'total':0} # 创建角色信息 players.append(pl) # 添加到游戏中 question(pl) # 生成问题 if(seq !=-1): if players[seq].get('lastA') ==data[6]: # 回答成功 players[seq]['correct']=players[seq].get('correct') +1 str1 = '回答正确' print(str1) fxx(data[2],str1) else: # 回答错误 骂人 players[seq]['error']=players[seq].get('error') +1 str2 = '回答错误,正确答案为'+players[seq].get('lastA') print(str2) status = requestText(zu_an_url) print("消息是 ",status) if status !=0: try: fxx(data[2], status)#发送消息 data[2]=微信id text[0:100]=请求后的消息 except: # print("你真棒!") fxx(data[2], "这都是送分题啊!") else: fxx(data[2], '网络请求失败') total = players[seq].get('correct') + players[seq].get('error') if total == total_count: # 需要解答的题目已经解答完成 if players[seq].get('error') == 0 # 没有答错 print("赞美1次") status = requestText(chp_url) print("消息是 ",status) if status !=0: try: fxx(data[2], status)#发送消息 data[2]=微信id text[0:100]=请求后的消息 except: # print("你真棒!") fxx(data[2], "你真棒!") else: fxx(data[2], '网络请求失败') fxx(data[2], "五道题目全部正确!") fxx(data[2],"答题结束") players.pop(seq) # 游戏结束 删除角色 else: # 解答完成 但存在答错的题目 c = players[seq].get('error') for i in range(c): status = requestText(zu_an_url) print("消息是 ",status) if status !=0: try: fxx(data[2], status)#发送消息 data[2]=微信id text[0:100]=请求后的消息 except: # print("你真棒!") fxx(data[2], "这都是送分题啊!") else: fxx(data[2], '网络请求失败') fxx(data[2], "五道题目全部完成") fxx(data[2],"答题结束") players.pop(seq) else: # 继续生成题目 question(players[seq]) threading.Thread(target=msgdata).start()#多线程收消息 处理 input("启动微信")

PS: 代码逻辑好像没写完,懒得写了。

最后

相关链接:
微信自动回复彩虹屁或祖安语录

原作者github项目地址为:
wechat-pc-hook3.0.0.57


__EOF__

本文作者damarkday知识库
本文链接https://www.cnblogs.com/GoodMemoryBlog/p/15889871.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   DAmarkday  阅读(1028)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示