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

No girlfriend's obsession yet 2021-09-15 09:51:53
python mirai development qq robot


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

版权声明
本文为[No girlfriend's obsession yet]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/09/20210909145427630n.html

  1. 面对小白的pandas命令手册+练习题【三万字详解】
  2. 面對小白的pandas命令手册+練習題【三萬字詳解】
  3. Face au Manuel de commande pandas de Xiaobai + question d'exercice [30 000 mots pour plus de détails]
  4. Interprétation des questions d'entrevue de base Python | 100 couches d'entrevue Python | couche 1
  5. Python data structure and algorithm (17) -- merge sort
  6. Les fonctions intégrées Python exécutent des blocs de code de fonction à travers des chaînes, et les mécanismes de réflexion comme Java sont assez puissants!
  7. Python笔记-uiautomator2截图点击,OpenCV找图
  8. Python文档阅读笔记-OpenCV中Template Matching
  9. Python笔记-利用OpenCV的matchTemplate屏幕找图并使用pyautogui点击
  10. Python筆記-利用OpenCV的matchTemplate屏幕找圖並使用pyautogui點擊
  11. Notes python - utilisez l'écran matchtemplate d'OpenCV pour trouver des images et cliquez sur
  12. Notes de lecture de documents python - Matching de modèles dans OpenCV
  13. Notes python - capture d'écran de l'automate 2 Cliquez pour ouvrir la vue
  14. python链接云服务器的mysql8
  15. python鏈接雲服務器的mysql8
  16. Mysql8 pour les serveurs Cloud liés Python
  17. Python资源大集合,要的话可以拿走!
  18. ️万字【Python基础】保姆式教学️,小白快速入门Python!
  19. ️萬字【Python基礎】保姆式教學️,小白快速入門Python!
  20. Wanzi [base Python] Baby - sitting Teaching, Little White Quick Start Python!
  21. Realizing the function of sending e-mail automatically with Python
  22. Smtpauthenticationerror in Python: solution
  23. 8 steps to teach you how to solve Sudoku in Python! (including source code)
  24. Python change la vie | identifier facilement des centaines de numéros de livraison
  25. Python change life | utilisation de modèles reconnus par ocr
  26. Bibliothèques Python utiles et intéressantes - - psutil
  27. 3. Traitement des données pandas
  28. 【Python编程基础】控制流之链式比较运算符
  29. MFC uses Python scripting language
  30. 【Python編程基礎】控制流之鏈式比較運算符
  31. 【 base de programmation python】 opérateur de comparaison de chaîne pour le flux de contrôle
  32. Python game development, pyGame module, python implementation of Xiaole games
  33. Mise en œuvre du Code de vérification unique (OTP) avec le cadre de repos Django
  34. Python - eval ()
  35. Python - Programmation orientée objet - _Rapport()
  36. Différence entre python - rep (), Str ()
  37. Python - Programmation orientée objet - _Appel()
  38. Python calling matlab script
  39. Python - Programmation orientée objet - _Nouveau() et mode Singleton
  40. Python - Programmation orientée objet - méthode magique (méthode de double soulignement)
  41. Python - Programmation orientée objet - pratique (6)
  42. Python - Programmation orientée objet - réflexion hasattr, GetAttr, GetAttr, delattr
  43. Python - Programmation orientée objet - _Dict
  44. Python - pydantic (2) Modèle imbriqué
  45. Non-ASCII character ‘\xe5‘ in file kf1.py on line 4, but no encoding declared; see http://python.or
  46. python笔记(一)
  47. Non - ASCII character 'xe5' in file kf1.py on Line 4, but no Encoding declared;Voirhttp://python.or
  48. Notes Python (1)
  49. Talk about how JMeter executes Python scripts concurrently
  50. In Beijing, you can't see the moon in the Mid Autumn Festival. Draw a blood red moon in Python
  51. Un des pandas crée un objet
  52. Machine learning | unitary regression model Python practical case
  53. Draw a "Lollipop chart" with Excel and python
  54. Python uses scikit learn to calculate TF-IDF
  55. Getting started with Python Basics_ 3 conditional statements and iterative loops
  56. Python dynamic properties and features
  57. 云计算开发:Python内置函数-min()函数详解
  58. [Python skill] how to speed up loop operation and numpy array operation
  59. 雲計算開發:Python內置函數-min()函數詳解
  60. Développement de l'informatique en nuage: explication détaillée de la fonction intégrée python - min ()