本帖最后由 安逸丫 于 2022-9-1 18:24 编辑
我使用Django运行QQ机器人本想着让机器人发送图片5秒钟后自己撤回想着time.sllep可以进行睡眠,
结果睡眠是睡眠了可竟然进入了循环,有没有什么解决的办法?
[Python] 纯文本查看 复制代码 from django.shortcuts import HttpResponse
import json
from Model import muen
# Create your views here.
def index(request):
#判断请求方式
if request.method == 'POST':
poatBody = request.body
data = poatBody.decode('utf-8')
json_data = json.loads(data)
try:
message_type = json_data['message_type']
if message_type == 'group':
group_id = json_data['group_id']
user_id = json_data['user_id']
message = json_data['message']
if group_id == 312945002:
muen.muen(group_id, user_id,message)
else:
user_id = json_data['user_id']
message = json_data['message']
except:
pass
return HttpResponse('POST')
else:
return HttpResponse(404)
[Python] 纯文本查看 复制代码 import re
from Model import Dsp,music,se,submit
#菜单
def muen(group_id,user_id,message):
if message == '功能':
message = '=====功能菜单=====\n' \
'1. \t视频解析\n' \
'2. \t点歌系统\n' \
'3. \t涩涩系统\n' \
'==============='
id = submit.message(group_id,message)
if message == '视频解析':
message = '=====视频解析=====\n' \
'使用方法:平台名称+解析+视频链接\n' \
'例:皮皮虾解析https://h5.pipix.com/s/2s3XjaF/\n' \
'支持平台:\n' \
'1.皮皮虾 \t\t2.皮皮搞笑\t3.抖音 \n' \
'4.快手 \t\t5.最右 \t\t6.微视\n' \
'7.微博 \t\t8.火山 \t\t10.西瓜视频\n' \
'10.今日头条 \t11.全民K歌\t12.虎牙\n' \
'==============='
submit.message(group_id, message)
if message == '点歌系统':
message = '=====点歌系统=====\n' \
'使用方法:平台名称+点歌+歌名\n' \
'例:网易云点歌生日快乐\n' \
'支持平台:\n' \
'1.网易云\t2.QQ\n' \
'3.酷狗 \t4.咪咕\n' \
'5.酷我\n' \
'==============='
submit.message(group_id, message)
if message == '涩涩系统':
message = '=====涩涩系统=====\n' \
'使用方法:发送关键词\n' \
'1.cos\t2.二次元\n' \
'==============='
submit.message(group_id, message)
return Mod(group_id,user_id,message)
#功能调用
def Mod(group_id,user_id,message):
#视频解析
if '皮皮虾解析' in message:
url = re.findall(r'http.*/', message)[0]
message = Dsp.ppx(group_id,url)
if '皮皮搞笑解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.ppgx(group_id,url)
if '抖音解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.douyin(group_id,url)
if '快手解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.kuaishou(group_id,url)
if '最右解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.zuiyou(group_id,url)
if '微视解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.weishi(url)
if '微博解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.weibo(group_id,url)
if '火山解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.huoshan(group_id,url)
if '西瓜视频解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.xigua(url)
if '今日头条解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.toutiao(group_id,url)
if '全民K歌解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.qmkg(group_id,url)
if '虎牙解析' in message:
url = re.findall(r'http.*', message)[0]
message = Dsp.huya(group_id,url)
#点歌系统
if '网易云点歌' in message:
song = re.findall(r'网易云点歌(.*)', message)[0]
message = music.wyy(group_id,song)
if 'QQ点歌' in message:
song = re.findall(r'QQ点歌(.*)', message)[0]
message = music.qq(group_id,song)
if '酷狗点歌' in message:
song = re.findall(r'酷狗点歌(.*)', message)[0]
message = music.kugou(group_id,song)
if '咪咕点歌' in message:
song = re.findall(r'咪咕点歌(.*)', message)[0]
message = music.migu(group_id,song)
if '酷我点歌' in message:
song = re.findall(r'酷我点歌(.*)', message)[0]
message = music.kuwo(group_id,song)
#涩涩系统
if message == 'cos':
message = se.cos(group_id)
if message == '二次元':
message = se.ecy(group_id)
#其他
if message =='把爱留在CSGO':
music_url = 'https://a.uoll.cn/%E6%8A%8A%E7%88%B1%E7%95%99%E5%9C%A8csgo.mp4'
message = f'[CQ:video,file={music_url}]'
[Python] 纯文本查看 复制代码 import random
import requests
import time
from bs4 import BeautifulSoup
from Model import submit
def cos(group):
num = random.randint(1, 10)
if num == 1:
data = requests.get('https://ganyu.la/acg/cosplay').text
else:
url = 'https://ganyu.la/acg/cosplay/page/' + str(num)
data = requests.get(url).text
soup = BeautifulSoup(data, 'html.parser')
data = soup.select(
'img[class="inn-archive__item__thumbnail__img inn-card_post-thumbnail__item__thumbnail__img inn__thumbnail__img"]')
lens = len(data)
num = random.randint(0, lens - 1)
url = data[num].get('src')
message = f'[CQ:image,file={url}]'
#发送消息
id = submit.message(group, message)
time.sleep(5)
#撤回消息
submit.delete_msg(id)
|