当前位置:网站首页>Set up a QQ robot for ordering songs, and watch beautiful women
Set up a QQ robot for ordering songs, and watch beautiful women
2022-06-23 10:22:00 【Skin kid LS】
Catalog
Preface
The complete project includes the framework 、 The code and detailed instructions can be downloaded from the link :
QQ Robot Basic Edition ( article 1-2 All functions )
QQ Robot multifunction version ( article 1-3 All functions )
After downloading, you only need to modify several places according to the instructions to build successfully !!
First article :QQ Robot detailed production tutorial ( From configuration to simple functions )
The second article : Building a QQ The robot chats with her girlfriend and wakes her up
The first two articles are on CSDN Comprehensive hot list , First of all Thanks for the official recommendation , Secondly, we need Thank you for your support ! I will continue to work hard ! We also look forward to your comments on this article One key, three links Oh .
This article adds the function of the robot , It is mainly realized through some interesting interfaces , Here are some screenshots :



To achieve the above functions are based on the first article , So if you haven't read the first article, go and have a look first .
First article :QQ Robot detailed production tutorial ( From configuration to simple functions )
Concrete realization
1、 Burst light
When people call our robot shots , What do I do ? Certainly. , Direct flash .
You can refer to Help document :
if ' Burst light ' in message:
qq = rev['sender']['user_id']
send_msg({
'msg_type': 'private', 'number': qq, 'msg': '[CQ:image,file={},type=flash,id=40004]'.format('https://c-ssl.duitang.com/uploads/blog/202012/16/20201216083017_6103b.thumb.1000_0.jpg')})
This picture address needs a network address , You can find one online .
I wrote a random picture function myself , You can refer to it .
website :https://www.duitang.com/search/?kw= beauty &type=feed( Of course, you can change the key words kw)
f12 Enter developer mode , Continue to slide down to load more pictures , You can see that there is an interface , There are several parameters .
python Code :
import json, requests
from bs4 import BeautifulSoup
import random
img_list = []
def get_img_random():
for j in [0,24,48,72]:
# Get website data
url = requests.get('https://www.duitang.com/search/?kw= beauty &type=feed&start={}'.format(j))
# url.encoding = 'utf-8' # If you need to use the Chinese characters in the page , You need to decode , Otherwise, Chinese will appear garbled
html = url.text
# Parse web pages
soup = BeautifulSoup(html, 'html.parser')
# Get all img label
movie = soup.find_all('div', class_='mbpho')
# print(movie)
# obtain src route
for i in movie:
imgsrc = i.find_all('img')[0].get('src')
img_list.append(imgsrc)
return img_list
i = random.randint(0, len(img_list))
print(get_img_random()[i])
Get a random picture address .
I wrote a web version based on this , Page entrance : Keywords random pictures
2、 Birthday Book
This needs to aggregate data API Interface , This has been introduced in the second article , You can go and have a look .
The second article : Building a QQ The robot chats with her girlfriend and wakes her up
Take a look at the returned data :

Go straight to the code ( You need to go to the official website to apply for this interface to obtain the request key):
import requests
def birthday_book(birthday,key):
url = "http://apis.juhe.cn/fapig/birthdayBook/query?" + 'keyword={}&key= You apply for api Request key'.format(birthday)
# send out get request
r = requests.get(url)
# Get the returned json data
result = r.json()['result'][key].replace('<p>','').replace('</p>','')
return result
dict={
' character ':'nature',' love ':'love',' Fortune ':'money',' career ':'business',' health ':'health',' Lucky Numbers ':'lucky_num',' Suitable love object ':'in_love',' Suitable friends ':'friend'}
word=' Suitable love object '
print(birthday_book('08-14',str(dict[word])))
3、 Get lyrics and share music
Reference article : Netease cloud music is commonly used API( Search for , The lyrics ,mp3 download )
(1) Get the lyrics
URL:http://music.163.com/api/search/pc
submission :POST
Parameters :
s: The name of the song
offset: Offset
limit: Get the number of songs
type: type ( song :1、 Album :10、 singer :100、 song sheet :1000、 user :1002、mv:1004)
python Code :
import requests
import json
def get_lyric(song):
url = "http://music.163.com/api/search/pc"
pyload = {
"s": song, "offset": 0, "limit": 1, 'type': 1}
response = requests.post(url, data=pyload).json()
artists = response['result']['songs'][0]['artists']
name = ''
for i in artists:
name = name + '/' + i['name']
id = response['result']['songs'][0]['id']
url = 'http://music.163.com/api/song/media?id=' + str(id)
r = requests.get(url)
try:
if len(r.json()['lyric']) <= 1:
return ' No lyrics '
else:
return ' singer :' + name + '\n' + str(r.json()['lyric'])
except:
return ' absolute music , No lyrics '
print(get_lyric(' Your eyes are like stars '))
Return results :
To build a robot, you need to obtain a parameter , Song key words ( You can take the author )
(2) Share music
First, you need to get the of the song id, Then through the of the robot frame cqcode To share . At present, it seems that only group chat sending is supported , Private chat didn't respond .
Document address :http://docs.go-cqhttp.org/cqcode/# Music sharing 
Get music id function :
def get_id(song):
url = "http://music.163.com/api/search/pc"
pyload = {
"s": song, "offset": 0, "limit": 1, 'type': 1}
response = requests.post(url, data=pyload).json()
id = response['result']['songs'][0]['id']
return id
To build a robot, you need to obtain a parameter , Song key words ( You can take the author )
Full project download address ( Configured with python Environmental Science )
The complete project includes the framework 、 The code and detailed instructions can be downloaded from the link :
QQ Robot Basic Edition ( article 1-2 All functions )
QQ Robot multifunction version ( article 1-3 All functions )
After downloading, you only need to modify several places according to the instructions to build successfully !!

Full project download address ( Computers don't have python Environmental Science )
Computers don't have python Environment or feel that the configuration is too troublesome, you can buy it directly exe edition , As long as there is a computer, it can run !!
QQ Robot Basic Edition exe
QQ Robot multifunction version exe
Similarly, there are instructions for use , Configuration is more convenient ( Strongly recommend )!!
But there is also a disadvantage , It's not programmable , The function has been fixed , Perfect for novices !!
Personal home page ( Including web version robot 、 Lick dog quotes online generation and keyword random pictures and other functions ): Skin children's personal site
边栏推荐
- XML related interview questions
- Distributed common interview questions
- Shengshihaotong enables high-quality development with industrial Digitalization
- Go unit test
- Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
- Bioinformatics | effective drug target correlation prediction based on interacting neural network
- 实现领域驱动设计 - 使用ABP框架 - 通用准则
- Nuxt.js spa与ssr的区别
- 同花顺推荐么?手机开户安全么?
- STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
猜你喜欢

Golang quick start (1)

Three implementation methods of distributed lock

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing

Confessing with Snake games (with source code)

AI system frontier dynamics issue 38: Google has abandoned tensorflow?; Four GPU parallel strategies for training large models; Father of llvm: modular design determines AI future

MySQL基础-笔记
![[software and system security] heap overflow](/img/ca/1b98bcdf006f90cabf3e90e416f7f2.png)
[software and system security] heap overflow

Golang 快速上手 (1)

Go语言JSON 处理

Mathematical analysis_ Notes_ Chapter 2: real and plural numbers
随机推荐
太无奈!微软停售 AI 情绪识别等技术,直言:“法律跟不上 AI 的发展”
I have been promoted. How can I get along with my former colleagues at the same level?
2021-05-12接口的定义与实现
RPC kernel details you must know (worth collecting)!!!
2021-05-12 interface definition and Implementation
[day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
What is JSX in the JS tutorial? Why do we need it?
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
高性能算力中心 — InfiniBand — Overview
Golang 快速上手 (2)
2021-05-11 instanceof and type conversion
Numerical calculation method
实现领域驱动设计 - 使用ABP框架 - 通用准则
Distributed common interview questions
2021-04-16递归
基于STM32设计的宠物投喂器
Go language JSON processing
Jump game of leetcode topic analysis
2021-04-12 the first implementation of linked list!!!