import re import socket import json from Private import private_msg from SendMessage import send_message import schedule import time ListenSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ListenSocket.bind(('127.0.0.1', 5701)) ListenSocket.listen(100) HttpResponseHeader = '''HTTP/1.1 200 OK Content-Type: text/html ''' def daily_work(): schedule.every().day.at("12:30").do(send_message,'private',2945340446, '樱花FRP签到:https://www.natfrp.com/user/') # schedule.every(10).seconds.do(send_message,'private',2945340446,'test') def request_to_json(msg): for i in range(len(msg)): if msg[i]=="{" and msg[-1]=="\n": return json.loads(msg[i:]) return None #需要循环执行,返回值为json格式 def rev_msg():# json or None Client, Address = ListenSocket.accept() Request = Client.recv(1024).decode(encoding='utf-8') rev_json=request_to_json(Request) Client.sendall((HttpResponseHeader).encode(encoding='utf-8')) Client.close() return rev_json def const_rev(): print("start to receive!") msg_id_lst = [0 for i in range(51)] pointer = 1 daily_work() while 1: rev = rev_msg() schedule.run_pending() # print(rev) if rev["post_type"] == "message" and (rev['message_id'] not in msg_id_lst): msg_id_lst[pointer] = rev['message_id'] pointer = (pointer + 1) % 50 if rev["message_type"] == "private": # 私聊 private_msg(rev) elif rev["message_type"] == "group": # 群聊 group = rev['group_id'] qq = rev['sender']['user_id'] print(type(group)) if "[CQ:at,qq=2962298249]" in rev["raw_message"]: if rev['raw_message'].split(' ')[1] == '在吗': send_message('group', group, '[CQ:poke,qq={}]'.format(qq)) else: send_message('group', group, '[CQ:at,qq={}]???咋了'.format(qq)) else: continue else: # rev["post_type"]=="meta_event": continue