Python + Mirai development QQ robot starting tutorial (2021.9.9 test is valid)

No girlfriend's obsession yet 2021-09-15 09:51:53

Reference resources : Development mirai QQ Robot start tutorial _ Sigh -CSDN Blog _mirai python

This article refers to the above blog , The invalid content and version matching are supplemented and modified , The actual measurement can run successfully . See this blog for a screenshot of some steps , Please refer to each other .

0. To configure jdk, Version must be OpenJDK>=11

OracleJDK Untested , Normal operation is not guaranteed

1. download mirai-console-loader(mcl), Version must be 1.2.2

iTXTech/mirai-console-loader: modularization 、 Lightweight and fully customizable mirai loader . (github.com)

mcl See the following document for the command usage :mirai-console-loader/README.md at master · iTXTech/mirai-console-loader (github.com)

2. add to mirai-api-http(mah) plug-in unit , Version must be 1.12.0

project-mirai/mirai-api-http at 9628ab1767f088822f713c166eb127840a69de81 (github.com)

cd ./mcl-1.2.2
sh ./mcl --update-package net.mamoe:mirai-api-http --channel stable --type plugin --version 1.12.0
sh ./mcl --dry-run

If the automatic download appears corrupt Report errors , You can download it manually mirai-api-http-v1.12.0.mirai.jar, And put it in mcl-1.2.2/plugins In the folder

3. Ban mcl Of updater Script , Prevent automatic upgrades

sh ./mcl --disable-script updater

4. Check the version correspondence

here , Pay attention to inspection mcl-1.2.2/config.json The contents of the document shall be the same as the following , Special attention required :mirai-console、mirai-console-terminal、mirai-core-all The version is 2.7.*,mirai-api-http The version is 1.12.0,"disabled_scripts": ["updater"] !!

{
"js_optimization_level": -1,
"mirai_repo": "https://gitee.com/peratx/mirai-repo/raw/master",
"maven_repo": [
"https://maven.aliyun.com/repository/public"
],
"packages": [
{
"id": "org.bouncycastle:bcprov-jdk15on",
"channel": "stable",
"version": "1.64",
"type": "libs",
"versionLocked": false
},
{
"id": "org.itxtech:mcl-addon",
"channel": "c122",
"version": "1.2.2",
"type": "plugins",
"versionLocked": false
},
{
"id": "net.mamoe:mirai-console",
"channel": "stable",
"version": "2.7.0",
"type": "libs",
"versionLocked": false
},
{
"id": "net.mamoe:mirai-console-terminal",
"channel": "stable",
"version": "2.7.0",
"type": "libs",
"versionLocked": false
},
{
"id": "net.mamoe:mirai-core-all",
"channel": "stable",
"version": "2.7.0",
"type": "libs",
"versionLocked": false
},
{
"id": "net.mamoe:mirai-api-http",
"channel": "stable",
"version": "1.12.0",
"type": "plugins",
"versionLocked": false
}
],
"disabled_scripts": [
"updater"
],
"proxy": "",
"log_level": 1,
"script_props": {}
}

Check mcl-1.2.2/libs and mcl-1.2.2/plugins Medium jar The package exists and matches the version in the above file !!

Reference resources :mirai Update to 2.7M1 after mirai-api-http Plug in not available | MiraiForum (mamoe.net)

5. To configure mah, Must follow 1.x Configure the document

project-mirai/mirai-api-http at 9628ab1767f088822f713c166eb127840a69de81 (github.com)

modify mcl-1.2.2/config/net.mamoe.mirai-api-http/setting.yml file , The following configurations can be copied directly

## This configuration is global , For all Session It works
# Optional , The default value is 0.0.0.0
host: '0.0.0.0'
# Optional , The default value is 8080
port: 8080
# Optional , By default, it is randomly generated when the plug-in is first started , It is recommended to specify
authKey: 1234567890
# Optional , Cache size , Default 4096. Too small cache will cause reference reply and recall messages to fail
cacheSize: 4096
# Optional , Open or not websocket, Off by default , Recommended by Session Configuration settings for the scope
enableWebsocket: true
# Optional , To configure CORS Cross domain , The default is *, That is, all domain names are allowed
cors:
- '*'
## Report the news
report:
# Function master switch
enable: false
# Group message reporting
groupMessage:
report: false
# Friend message reporting
friendMessage:
report: false
# Temporary message reporting
tempMessage:
report: false
# Report the incident
eventMessage:
report: false
# Report URL
destinations: []
# Additional when reporting Header
extraHeaders: {}
## heartbeat
heartbeat:
# Function master switch
enable: false
# Start delay
delay: 1000
# Heartbeat interval
period: 15000
# Heartbeat report URL
destinations: []
# Additional information when reporting
extraBody: {}
# The extra amount at the time of reporting
extraHeaders: {}

6. install MiraiAndroid

mirai-login-solver-selenium and TxCaptchaHelper Can't work properly (2021.9.9)!

Reference resources : Unable to log in temporary processing scheme | MiraiForum (mamoe.net)

github:mzdluo123/MiraiAndroid: QQ robot /( experimental ) stay Android Up operation Mirai-console, Support plug-ins (github.com)

download :https://install.appcenter.ms/users/mzdluo123/apps/miraiandroid/distribution_groups/release

Environmental preparation before use :

stay mirai Add... To the runtime JVM attribute mirai.slider.captcha.supported ( Add parameter -Dmirai.slider.captcha.supported) To confirm that the sliding verification is completed manually

It doesn't matter if you don't understand the above , Look directly at the following steps : about mirai-console-loader, open mcl(Linux) or mcl.bat(Windows), stay java ..... -jar .... In the command -jar Add parameters before -Dmirai.slider.captcha.supported,Linux The revised result is as follows :

#!/usr/bin/env sh
export JAVA_BINARY=java
$JAVA_BINARY -Dmirai.slider.captcha.supported -jar mcl.jar $*
  • If it runs on mirai-console, Need to be in plugins Delete inside mirai-login-solver-selenium plug-in unit
  • If it's based directly on mirai-core Development , You need to remove mirai-login-solver-selenium rely on

Usage method :

Download and install it on your phone , And finish logging in ; The login method is set in the automatic login in the upper right corner of the main screen , Verification is required during login. Please click notification in the notification column to complete verification .

After successful login, go to the left menu to find advanced functions ( Tools ), Choose your account ( Select a bot) Then export the device file (device.json) Send to PC , And overwrite the computer version of the file (Linux The next path is mcl-1.2.2/bots/qq Number /device.json).

Run again mcl Script

cd ./mcl-1.2.2
sh ./mcl

wait for mcl After opening, enter the following command to successfully log in :

> login qq Number qq password

7. install graia-application-mirai, Note that you need to downgrade the version to work properly

Reference configuration : Install and configure the development environment | Graia Document (graia-document.vercel.app)

GraiaProject/Application: An exquisitely designed , The protocol implements complete , be based on mirai-api-http Automation framework of instant chat software . (github.com)

cannot import name 'BaseDispatcher' · Issue #161 · GraiaProject/Application (github.com)

pip install graia-application-mirai==0.18.4

establish bot.py file , modify bot.py Medium host、authKey And mirai-api-http The configuration of is the same , modify account,websocket Change it to true

from graia.broadcast import Broadcast
from graia.application import GraiaMiraiApplication, Session
from graia.application.message.chain import MessageChain
import asyncio
from graia.application.message.elements.internal import Plain
from graia.application.friend import Friend
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
broadcast=bcc,
connect_info=Session(
host="http://localhost:8080", # fill httpapi The address where the service runs
authKey="graia-mirai-api-http-authkey", # fill authKey
account=****, # Your robot qq Number
websocket=True # Graia The normal operation of the message receiving part can be guaranteed according to the configured message receiving mode .
)
)
@bcc.receiver("FriendMessage")
async def friend_message_listener(app: GraiaMiraiApplication, friend: Friend):
await app.sendFriendMessage(friend, MessageChain.create([
Plain("Hello, World!")
]))
app.launch_blocking()

function bot.py

python bot.py

Then tell your QQ robot , Just send a message , If it replies to you Hello, World!, Is a success

Please bring the original link to reprint ,thank
Similar articles

2021-09-15

2021-09-15