0%

qq聊天机器人

mirai库

github仓库

不等不称赞这个qq机器人的库比之前的酷q强太多了,java本身极强的跨平台性,让整个环境的部署都快了很多

windows本地跑起来了,直接再丢到服务器上就好了

mirai-api-http

github仓库

注:当前版本/verify不能使得session 存活,注意使用一次就auth用完释放掉,见issue

python库

官方文档
github仓库

官方文档只给了自己的框架的结构

官方文档并不是特别的完善,很多功能需要自己去看源码,感觉还不如放弃使用这个python库

但是这个库从设计上有很多值得借鉴的地方

bug

typing 模块

明明说支持3.6-3.9

pip下来,结果使用了3.8的typing 模块

环境装不上

1
2
3
4
5
6
7
8
9
10
11
(qqbot39) C:\Users\lnd\Desktop\hdu\qqbot>pip install graia-application-mirai
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/graia-application-mirai/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/graia-application-mirai/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/graia-application-mirai/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/graia-application-mirai/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/graia-application-mirai/
Could not fetch URL https://pypi.org/simple/graia-application-mirai/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/graia-application-mirai/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))) - skipping
ERROR: Could not find a version that satisfies the requirement graia-application-mirai
ERROR: No matching distribution found for graia-application-mirai
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))) - skipping

解决

网上都说是因为pip版本的问题,使用命令curl https://bootstrap.pypa.io/get-pip.py | python更新pip

此时自己的pip版本

1
2
3
4
5
6
7
8
9
10
11
12
(qqbot39) C:\Users\lnd\Desktop\hdu\qqbot>pip show pip
Name: pip
Version: 21.0.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\users\lnd\anaconda3\envs\qqbot39\lib\site-packages
Requires:
Required-by:

但是还是装不上包

再看看错误,ssl证书错误,感觉是梯子有问题,把梯子关了问题就解决了

没有正确启动

参考文献

无法登录

参考文献

尚无法解决

bug详情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] 需要滑动验证码, 请按照以下链接的步骤完成滑动验证码, 然后输入获取到的 ticket
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] Slider captcha required. Please solve the captcha with following link. Type ticket here after completion.
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] @see https://github.com/project-mirai/mirai-login-solver-selenium
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] @see https://docs.mirai.mamoe.net/mirai-login-solver-selenium/
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] 或者输入 TxCaptchaHelper 来使用 TxCaptchaHelper 完成滑动验证码
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] Or type `TxCaptchaHelper` to resolve slider captcha with TxCaptchaHelper.apk
2021-09-02 18:27:39 I/Bot.473912645: [SliderCaptcha] Captcha link: https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?style=simple&aid=16&uin=473912645&sid=4281201927446898458&cap_cd=l9d2xZlLb85whtSiOcuT60o_CxsvKZF6Wao1IyubDep2sWqAz-KKaA**&clientype=1&apptype=2
18:27:39 LOGIN>
LOGIN> > t03HtfrXNteALDzWfeFxPf5TAXJHSZmPmtR0Rn1WLjeLnimM27aqST53YTrlewVy8Nu3gIYtuOON_dEcBdPgqVhmHJllsaMMgJcYdpXQt-5I2Z_l8p-qe0Wij-FgJcMlYXh
2021-09-02 18:28:25 I/Bot.473912645: [SliderCaptcha] 正在提交中...
2021-09-02 18:28:25 I/Bot.473912645: [SliderCaptcha] Submitting...
2021-09-02 18:28:26 E/main: net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(473912645), code=237, title=禁止登录, message=当前上网环境异常,请更换网络环境或在常用设备上登录或稍后再试。, errorInfo=), tips=若频繁出现, 请尝试开启设备锁
net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(473912645), code=237, title=禁止登录, message=当前上网环境异常,请更换网络环境或在常用设备上登录或稍后再试。, errorInfo=), tips=若频繁出现, 请尝试开启设备锁
at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl.doLogin(SsoProcessor.kt:265)
at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl$doLogin$1.invokeSuspend(SsoProcessor.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

BUG

JNI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
C:\Users\lnd\Desktop\hdu\qqbot>mcl.cmd
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/itxtech/mcl/Loader has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\Users\lnd\Desktop\hdu\qqbot>
C:\Users\lnd\Desktop\hdu\qqbot>mcl.cmd
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/itxtech/mcl/Loader has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\Users\lnd\Desktop\hdu\qqbot>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

C:\Users\lnd\Desktop\hdu\qqbot>javac -version
javac 1.8.0_201

C:\Users\lnd\Desktop\hdu\qqbot>

解决

查阅资料和Mirai安装脚本的库可知,必须使用java11以上的sdk来运行,而本地的java是1.8,去oracle官网下载java11并安装

参考文献

https://blog.csdn.net/xiang0731/article/details/87973131

编写自己的插件

参考文献

参考文献

mirai事件api

下载消息中的图片

参考文献

代码详情
1
2
3
4
5
6
val image: Image? = this.message.get(1).toMessageChain()[Image]

if (image != null) {
val url = image.queryUrl()
subject.sendMessage(url)
}

bug

Could not open init generic class cache for initialization script ‘C:\Users\lnd\AppData\Local\Temp\wrapper_init2.gradle’

改一下project的jvm

参考文献

找不到JavaPlugin

图片详情找不到图片(Image not found)