11
11
"""
12
12
13
13
import os
14
- import re
14
+ import re # noqa: F401
15
15
import sys
16
16
import json
17
17
import time
18
18
import zlib
19
19
import struct
20
20
import asyncio
21
- from math import log
21
+ from math import log # noqa: F401
22
22
from functools import partial
23
23
from abc import abstractmethod
24
24
from collections import namedtuple
25
- from os .path import join , split , abspath , dirname
26
- from typing import TYPE_CHECKING , Any , Dict , NamedTuple
25
+ from os .path import join , split , abspath , dirname # noqa: F401
26
+ from typing import TYPE_CHECKING , Any , Dict , NamedTuple # noqa: F401
27
27
28
28
import qrcode
29
29
import aiohttp
30
30
from genericpath import exists
31
31
from aiohttp .client import ClientSession
32
32
33
- from iamai .utils import DataclassEncoder
33
+ from iamai .utils import DataclassEncoder # noqa: F401
34
34
from iamai .adapter .utils import WebSocketAdapter
35
35
from iamai .log import logger , error_or_exception
36
36
37
- from .event import *
38
- from .message import *
37
+ from .event import * # noqa: F403
38
+ from .message import * # noqa: F403
39
39
from .config import Config
40
40
from .event import get_event_class
41
41
42
42
if TYPE_CHECKING :
43
- from .message import T_BililiveMSG
43
+ from .message import T_BililiveMSG # noqa: F401
44
44
45
45
__all__ = ["BililiveAdapter" ]
46
46
80
80
user_cookies = aiohttp .cookiejar .CookieJar ()
81
81
82
82
83
- class BililiveAdapter (WebSocketAdapter [BililiveEvent , Config ]):
83
+ class BililiveAdapter (WebSocketAdapter [BililiveEvent , Config ]): # noqa: F405
84
84
"""bililive 协议适配器。"""
85
85
86
86
name : str = "bililive"
@@ -115,7 +115,7 @@ async def startup(self):
115
115
self .cookies = json .load (f )
116
116
user_cookies .update_cookies (self .cookies )
117
117
if self .config .login : # type: ignore
118
- logger .debug (f "Login enabled!" )
118
+ logger .debug ("Login enabled!" )
119
119
try :
120
120
# 尝试登陆
121
121
async with ClientSession (cookie_jar = user_cookies ) as self .session :
@@ -125,9 +125,9 @@ async def startup(self):
125
125
self ._uid = get_cookies ("DedeUserID" )
126
126
self .jct = get_cookies ("bili_jct" )
127
127
128
- if self ._uid == None or self .jct == None :
128
+ if self ._uid == None or self .jct == None : # noqa: E711
129
129
logger .error (
130
- f "Unable to get cookies, please check your cookies."
130
+ "Unable to get cookies, please check your cookies."
131
131
)
132
132
return
133
133
if not exists (_path ):
@@ -143,7 +143,7 @@ async def startup(self):
143
143
logger .error (e )
144
144
return
145
145
else :
146
- logger .debug (f "Login disabled!" )
146
+ logger .debug ("Login disabled!" )
147
147
await super ().startup ()
148
148
149
149
async def websocket_connect (self ):
@@ -183,7 +183,7 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
183
183
header = HeaderTuple (* HEADER_STRUCT .unpack_from (data , offset ))
184
184
except struct .error :
185
185
break
186
- if header .operation == Operation .HEARTBEAT_REPLY :
186
+ if header .operation == Operation .HEARTBEAT_REPLY : # noqa: F405
187
187
popularity = int .from_bytes (
188
188
data [
189
189
offset + HEADER_STRUCT .size : offset
@@ -193,7 +193,7 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
193
193
"big" ,
194
194
)
195
195
await self ._on_receive_popularity (popularity )
196
- elif header .operation == Operation .SEND_MSG_REPLY :
196
+ elif header .operation == Operation .SEND_MSG_REPLY : # noqa: F405
197
197
body = data [
198
198
offset + HEADER_STRUCT .size : offset + header .pack_len
199
199
]
@@ -219,9 +219,9 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
219
219
logger .debug (f"body: { body } " )
220
220
raise
221
221
222
- elif header .operation == Operation .AUTH_REPLY :
222
+ elif header .operation == Operation .AUTH_REPLY : # noqa: F405
223
223
await self .websocket .send_bytes (
224
- self ._make_packet ({}, Operation .HEARTBEAT )
224
+ self ._make_packet ({}, Operation .HEARTBEAT ) # noqa: F405
225
225
)
226
226
227
227
else :
@@ -270,7 +270,7 @@ async def _send_auth(self):
270
270
"clientver" : "1.14.3" ,
271
271
"type" : 2 ,
272
272
}
273
- await self .websocket .send_bytes (self ._make_packet (auth_params , Operation .AUTH ))
273
+ await self .websocket .send_bytes (self ._make_packet (auth_params , Operation .AUTH )) # noqa: F405
274
274
275
275
@staticmethod
276
276
def _make_packet (data , operation ):
@@ -291,7 +291,7 @@ async def _start_heartbeat(self) -> None:
291
291
if self .websocket .closed :
292
292
break
293
293
await self .websocket .send_bytes (bytes .fromhex (hb ))
294
- logger .debug (f "HeartBeat sent!" )
294
+ logger .debug ("HeartBeat sent!" )
295
295
await asyncio .sleep (29 )
296
296
except Exception as e :
297
297
logger .error (e )
@@ -327,7 +327,7 @@ async def send(
327
327
danmaku : str ,
328
328
fontsize : int = 25 ,
329
329
color : int = 0xFFFFFF ,
330
- pos : DanmakuPosition = DanmakuPosition .NORMAL ,
330
+ pos : DanmakuPosition = DanmakuPosition .NORMAL , # noqa: F405
331
331
) -> bool :
332
332
# don't know what the hell is bubble
333
333
return await self .send_danmu (
@@ -361,13 +361,13 @@ def rawData_to_jsonData(data: bytes):
361
361
try :
362
362
jd = json .loads (data [16 :].decode ("utf-8" , errors = "ignore" ))
363
363
return jd
364
- except Exception as e :
364
+ except Exception :
365
365
pass
366
366
367
367
368
368
async def login (session : ClientSession ) -> bool :
369
- if get_cookies ("bili_jct" ) != None :
370
- logger .info (f "Aleady login!" )
369
+ if get_cookies ("bili_jct" ) != None : # noqa: E711
370
+ logger .info ("Aleady login!" )
371
371
return True
372
372
try :
373
373
res = await _get (session , QRCODE_REQUEST_URL )
0 commit comments