update mirai

This commit is contained in:
2021-05-10 21:04:50 +08:00
parent 5fa20bd1ea
commit 9f9feef2bd
3 changed files with 40 additions and 4 deletions

View File

@@ -63,9 +63,11 @@ rssbotLib=rssbot.dll
### miraiApiHTTPServer
可选参数。指定[mirai-api-http](https://github.com/project-mirai/mirai-api-http)服务器位置。例如`http://localhost:8081`。可用来发送QQ消息。设置后必须设置[`miraiApiHTTPAuthKey`](#miraiapihttpauthkey)和[`miraiApiQQ`](#miraiapiqq)
### miraiApiHTTPAuthKey
可选参数。指定mirai-api-http的[AuthKey](https://github.com/project-mirai/mirai-api-http#开始使用)。
可选参数。指定mirai-api-http的`[AuthKey]`(https://github.com/project-mirai/mirai-api-http#开始使用)(2.X版本为`VerifyKey`)
### miraiApiQQ
可选参数。已在mirai登录的QQ号。
### miraiApiHTTPVer
可选参数。指定mirai-api-http的版本,只有当获取版本失败时采用该值。
## 命令行参数
```text
--rebuild-hashlist 重建hashList

View File

@@ -32,6 +32,11 @@ class LoginRequiredError(Exception):
Exception.__init__(self, 'Login is needed.')
class AlreadyDepreated(Exception):
def __init__(self, name: str):
Exception.__init__(self, f'{name} is already depreated.')
def login_required(f):
@wraps(f)
def o(*l, **k):
@@ -66,6 +71,20 @@ def version_needed(v: List[int]):
return i
def depreated_at(v: List[int], raise_error: bool = True):
def i(f):
@wraps(f)
def o(*l, **k):
m: Mirai = l[0]
if m._version >= v:
if raise_error:
raise AlreadyDepreated(f.__name__)
return None
return f(*l, **k)
return o
return i
def admin_needed(ind=1):
"ind: 第i+1个参数是groupId"
def i(f):
@@ -100,14 +119,23 @@ class Mirai:
self._lastRequestTime = 0
self._logined = False
self._version = []
for i in self.about()['data']['version'].split('.'):
abt = self.about()
if abt is None or 'code' not in abt or abt['code'] != 0:
if self._m._setting.miraiApiHTTPVer is None:
raise ValueError('Unknown Version.')
ver = self._m._setting.miraiApiHTTPVer
else:
ver = abt['data']['version']
for i in ver.split('-')[0].split('.'):
self._version.append(int(i))
if self._version < [1, 10, 0]:
raise ValueError('mirai-api-http的版本至少为1.10.0')
self.login()
def _auth(self, authKey: str):
r = self._post("/auth", {"authKey": authKey})
path = "/auth" if self._version < [2, 0] else '/verify'
keyname = "authKey" if self._version < [2, 0] else 'verifyKey'
r = self._post(path, {keyname: authKey})
if r is None:
return None
return r.json()
@@ -288,7 +316,8 @@ class Mirai:
return r.json()
def _verify(self, sessionKey: str, qq: int):
r = self._post("/verify", {"sessionKey": sessionKey, "qq": qq})
path = "/verify" if self._version < [2, 0] else '/bind'
r = self._post(path, {"sessionKey": sessionKey, "qq": qq})
if r is None:
return None
return r.json()

View File

@@ -57,6 +57,7 @@ class settings:
self._miraiApiHTTPServer = d['miraiApiHTTPServer'] if 'miraiApiHTTPServer' in d and d['miraiApiHTTPServer'] != '' else None
self._miraiApiHTTPAuthKey = d['miraiApiHTTPAuthKey'] if 'miraiApiHTTPAuthKey' in d and d['miraiApiHTTPAuthKey'] != '' else None
self._miraiApiQQ = int(d['miraiApiQQ']) if 'miraiApiQQ' in d and d['miraiApiQQ'].isnumeric() else None
self._miraiApiHTTPVer = d['miraiApiHTTPVer'] if 'miraiApiHTTPVer' in d and d['miraiApiHTTPVer'] != '' else None
@property
def token(self) -> str:
@@ -118,6 +119,10 @@ class settings:
def miraiApiQQ(self) -> int:
return self._miraiApiQQ
@property
def miraiApiHTTPVer(self) -> str:
return self._miraiApiHTTPVer
class commandline:
def __init__(self, commandline: List[str] = None):