summaryrefslogtreecommitdiff
path: root/ATRI/plugins/rich
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-07-31 16:21:23 +0800
committerKyomotoi <[email protected]>2021-07-31 16:21:23 +0800
commit1d54ec291f2c25cc01f24d0d0163d0bf889457fd (patch)
tree251004df3f659f79b96b9abce59cc1140e24498c /ATRI/plugins/rich
parentbeb16b60fe4d8586436f5ada5fdabb6db23f5a29 (diff)
parent36d26d1dc61c36b4601aaf75e148060c5bcb98a7 (diff)
downloadATRI-1d54ec291f2c25cc01f24d0d0163d0bf889457fd.tar.gz
ATRI-1d54ec291f2c25cc01f24d0d0163d0bf889457fd.tar.bz2
ATRI-1d54ec291f2c25cc01f24d0d0163d0bf889457fd.zip
Merge branch 'main' of https://github.com/Kyomotoi/ATRI into main
Diffstat (limited to 'ATRI/plugins/rich')
-rw-r--r--ATRI/plugins/rich/__init__.py3
-rw-r--r--ATRI/plugins/rich/data_source.py18
2 files changed, 10 insertions, 11 deletions
diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py
index 87a2b02..4c5b624 100644
--- a/ATRI/plugins/rich/__init__.py
+++ b/ATRI/plugins/rich/__init__.py
@@ -9,12 +9,13 @@ _rich_flmt = FreqLimiter(2)
bili_rich = Rich().on_message("小程序爪巴", block=False)
+
@bili_rich.handle()
async def _fk_bili(bot: Bot, event: MessageEvent):
user_id = event.get_user_id()
if not _rich_flmt.check(user_id):
return
-
+
msg = str(event.message)
try:
result, is_ok = await Rich().fk_bili(msg)
diff --git a/ATRI/plugins/rich/data_source.py b/ATRI/plugins/rich/data_source.py
index a59c922..96f77cf 100644
--- a/ATRI/plugins/rich/data_source.py
+++ b/ATRI/plugins/rich/data_source.py
@@ -25,10 +25,9 @@ __doc__ = """
class Rich(Service):
-
def __init__(self):
Service.__init__(self, "小程序处理", __doc__, rule=is_in_service("小程序处理"))
-
+
@staticmethod
def _bv_dec(x) -> str:
r = 0
@@ -36,7 +35,7 @@ class Rich(Service):
r += tr[x[s[i]]] * 58 ** i
result = "av" + str((r - add) ^ xor)
return result
-
+
@staticmethod
def _bv_enc(x) -> str:
x = (x ^ xor) + add
@@ -44,7 +43,7 @@ class Rich(Service):
for i in range(6):
r[s[i]] = table[x // 58 ** i % 58]
return "".join(r)
-
+
@classmethod
async def fk_bili(cls, text: str) -> tuple:
"""
@@ -53,7 +52,7 @@ class Rich(Service):
"""
msg = text.replace("\\", "")
bv = False
-
+
if "qqdocurl" not in msg:
if "av" in msg:
av = re.findall(r"(av\d+)", msg)
@@ -71,7 +70,7 @@ class Rich(Service):
if not bv_url:
return "Get value (bv url) failed!", False
bv_url = bv_url[3]
-
+
try:
res = await request.get(bv_url)
except RequestError:
@@ -80,7 +79,7 @@ class Rich(Service):
if not bv:
return "Get value (bv) failed!", False
av = cls._bv_dec(bv[0])
-
+
if not bv:
if "av" in msg:
av = re.findall(r"(av\d+)", msg)
@@ -89,7 +88,7 @@ class Rich(Service):
av = av[0].replace("av", "")
else:
return "Not found av", False
-
+
url = URL + av
try:
res = await request.get(url)
@@ -97,11 +96,10 @@ class Rich(Service):
return "Request failed!", False
res_data = await res.json()
data = res_data["data"]
-
+
result = (
f"{data['bvid']} INFO:\n"
f"Title: {data['title']}\n"
f"Link: {data['short_link']}"
)
return result, True
- \ No newline at end of file