summaryrefslogtreecommitdiff
path: root/AyaBot/plugins
diff options
context:
space:
mode:
做了些小改动
以话慢慢补全功能 目前能用的 只有other
Diffstat (limited to 'AyaBot/plugins')
13 files changed, 259 insertions, 11 deletions
diff --git a/AyaBot/plugins/__pycache__/other.cpython-37.pyc b/AyaBot/plugins/__pycache__/other.cpython-37.pyc
new file mode 100644
index 0000000..5962b9f
--- /dev/null
+++ b/AyaBot/plugins/__pycache__/other.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/aio/__init__.py b/AyaBot/plugins/aio/__init__.py
new file mode 100644
index 0000000..3cc81f0
--- /dev/null
+++ b/AyaBot/plugins/aio/__init__.py
@@ -0,0 +1,8 @@
+import asyncio
+from functools import partial
+from typing import Any
+
+
+async def run_sync_func(func, *args, **kwargs) -> Any:
+ return await asyncio.get_event_loop().run_in_executor(
+ None, partial(func, *args, **kwargs))
diff --git a/AyaBot/plugins/aio/__pycache__/__init__.cpython-37.pyc b/AyaBot/plugins/aio/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..416e999
--- /dev/null
+++ b/AyaBot/plugins/aio/__pycache__/__init__.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/aio/requests.py b/AyaBot/plugins/aio/requests.py
new file mode 100644
index 0000000..4f7b9d3
--- /dev/null
+++ b/AyaBot/plugins/aio/requests.py
@@ -0,0 +1,71 @@
+from typing import Optional, Any
+
+import requests
+from requests import *
+
+from . import run_sync_func
+
+
+class AsyncResponse:
+ def __init__(self, response: requests.Response):
+ self.raw_response = response
+
+ @property
+ def ok(self) -> bool:
+ return self.raw_response.ok
+
+ def __repr__(self):
+ return '<AsyncResponse [%s]>' % self.raw_response.status_code
+
+ def __bool__(self):
+ return self.ok
+
+ @property
+ async def content(self) -> Optional[bytes]:
+ return await run_sync_func(lambda: self.raw_response.content)
+
+ @property
+ async def text(self) -> str:
+ return await run_sync_func(lambda: self.raw_response.text)
+
+ async def json(self, **kwargs) -> Any:
+ return await run_sync_func(self.raw_response.json, **kwargs)
+
+
+async def request(method, url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.request,
+ method=method, url=url, **kwargs))
+
+
+async def get(url, params=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.get, url=url, params=params, **kwargs))
+
+
+async def options(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.options, url=url, **kwargs))
+
+
+async def head(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.head, url=url, **kwargs))
+
+
+async def post(url, data=None, json=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.post, url=url,
+ data=data, json=json, **kwargs))
+
+
+async def put(url, data=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.put, url=url, data=data, **kwargs))
+
+
+async def patch(url, data=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.patch, url=url, data=data, **kwargs))
+
+
+async def delete(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.delete, url=url, **kwargs))
diff --git a/AyaBot/plugins/bilibili.py b/AyaBot/plugins/bilibili.pytest
index fa4554b..fa4554b 100644
--- a/AyaBot/plugins/bilibili.py
+++ b/AyaBot/plugins/bilibili.pytest
diff --git a/AyaBot/plugins/bilibilitest/__init__.py b/AyaBot/plugins/bilibilitest/__init__.py
new file mode 100644
index 0000000..05f2855
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/__init__.py
@@ -0,0 +1,5 @@
+from nonebot import CommandGroup
+
+__plugin_name__ = 'BiliBili搜番'
+
+from . import index \ No newline at end of file
diff --git a/AyaBot/plugins/bilibilitest/__pycache__/__init__.cpython-37.pyc b/AyaBot/plugins/bilibilitest/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..d409765
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/__pycache__/__init__.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/bilibilitest/__pycache__/index.cpython-37.pyc b/AyaBot/plugins/bilibilitest/__pycache__/index.cpython-37.pyc
new file mode 100644
index 0000000..6ba7b16
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/__pycache__/index.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/bilibilitest/aio/__init__.py b/AyaBot/plugins/bilibilitest/aio/__init__.py
new file mode 100644
index 0000000..3cc81f0
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/aio/__init__.py
@@ -0,0 +1,8 @@
+import asyncio
+from functools import partial
+from typing import Any
+
+
+async def run_sync_func(func, *args, **kwargs) -> Any:
+ return await asyncio.get_event_loop().run_in_executor(
+ None, partial(func, *args, **kwargs))
diff --git a/AyaBot/plugins/bilibilitest/aio/__pycache__/__init__.cpython-37.pyc b/AyaBot/plugins/bilibilitest/aio/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..b379548
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/aio/__pycache__/__init__.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/bilibilitest/aio/requests.py b/AyaBot/plugins/bilibilitest/aio/requests.py
new file mode 100644
index 0000000..4f7b9d3
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/aio/requests.py
@@ -0,0 +1,71 @@
+from typing import Optional, Any
+
+import requests
+from requests import *
+
+from . import run_sync_func
+
+
+class AsyncResponse:
+ def __init__(self, response: requests.Response):
+ self.raw_response = response
+
+ @property
+ def ok(self) -> bool:
+ return self.raw_response.ok
+
+ def __repr__(self):
+ return '<AsyncResponse [%s]>' % self.raw_response.status_code
+
+ def __bool__(self):
+ return self.ok
+
+ @property
+ async def content(self) -> Optional[bytes]:
+ return await run_sync_func(lambda: self.raw_response.content)
+
+ @property
+ async def text(self) -> str:
+ return await run_sync_func(lambda: self.raw_response.text)
+
+ async def json(self, **kwargs) -> Any:
+ return await run_sync_func(self.raw_response.json, **kwargs)
+
+
+async def request(method, url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.request,
+ method=method, url=url, **kwargs))
+
+
+async def get(url, params=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.get, url=url, params=params, **kwargs))
+
+
+async def options(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.options, url=url, **kwargs))
+
+
+async def head(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.head, url=url, **kwargs))
+
+
+async def post(url, data=None, json=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.post, url=url,
+ data=data, json=json, **kwargs))
+
+
+async def put(url, data=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.put, url=url, data=data, **kwargs))
+
+
+async def patch(url, data=None, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.patch, url=url, data=data, **kwargs))
+
+
+async def delete(url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(
+ await run_sync_func(requests.delete, url=url, **kwargs))
diff --git a/AyaBot/plugins/bilibilitest/index.py b/AyaBot/plugins/bilibilitest/index.py
new file mode 100644
index 0000000..144ff7e
--- /dev/null
+++ b/AyaBot/plugins/bilibilitest/index.py
@@ -0,0 +1,91 @@
+import math
+import re
+import requests
+from typing import Optional, List, Any, Dict
+from nonebot import CommandSession, CommandGroup
+from aiocache import cached
+
+from datetime import datetime
+import pytz
+from pandas import Timestamp
+
+# from .aio import *
+
+#get TIME
+CST = 'Asia/Shanghai'
+
+def beijing_time_now(freq: Optional[str] = None) -> datetime:
+ now = datetime.now(pytz.timezone(CST))
+ if freq is not None:
+ now = Timestamp(now).round(freq)
+ return now
+
+
+def beijing_from_timestamp(timestamp: int) -> datetime:
+ return datetime.fromtimestamp(timestamp, pytz.timezone(CST))
+
+
+
+cg = CommandGroup('bilibili_anime')
+
+API_URL = 'https://bangumi.bilibili.com/media/web_api/search/result?season_version=-1&area=-1&is_finish=-1&copyright=-1&season_status=-1&season_month={month}&pub_date={year}&style_id=-1&order=3&st=1&sort=0&page=1&season_type=1&pagesize=20'
+WEB_URL = 'https://www.bilibili.com/anime/index/#season_version=-1&area=-1&is_finish=-1&copyright=-1&season_status=-1&season_month={month}&pub_date={year}&style_id=-1&order=3&st=1&sort=0&page=1'
+
+
+@cached(ttl= 5 * 60)
+async def get_anime_list(year: int, month: int) -> Optional[List[Dict[str, Any]]]:
+ api_url = API_URL.format(year=year, month=month)
+ res = await requests.get(api_url)
+ payload = await res.json()
+
+ if not payload or payload.get('code') != 0:
+ return None
+
+ return payload['result']['data']
+
+
+@cg.command('fan', aliases=['新番', '番剧索引', '番剧'], only_to_me=False)
+async def fan(session: CommandSession):
+ now = beijing_time_now()
+ year = session.state.get('year', now.year)
+ month = session.state.get('month', now.month)
+ month = math.ceil(month / 3) * 3 - 3 + 1
+
+ anime_list = await get_anime_list(year, month)
+ if not anime_list:
+ session.finish('并没有找到相关的番剧...再试一次..?')
+
+ reply = f'{year}/{month}番剧\n按照热度进行排序,前20部如下: \n'
+ for anime in anime_list:
+ title = anime.get('title')
+ index_show = anime.get('index_show', 'Error')
+ if not title:
+ continue
+ reply += f'{title} {index_show}\n'
+
+ web_url = WEB_URL.format(year=year, month=month)
+ reply += f'\n详细请见官网 {web_url}'
+ session.finish(reply)
+
+
+@fan.args_parser
+async def _(session: CommandSession):
+ arg = session.current_arg_text.split()
+
+ year = None
+ month = None
+ if len(arg) == 2 and re.fullmatch(r'(?:20)?\d{2}', arg[0]) and re.fullmatch(r'\d{1,2}', arg[1]):
+ year = int(arg[0]) if len(arg[0]) > 2 else 2000 + int (arg[0])
+ month = int(arg[1])
+ elif len(arg) == 1 and re.fullmatch(r'\d{1,2}', arg[0]):
+ month = int(arg[0])
+ elif len(arg) == 1 and re.fullmatch(r'(?:20)?\d{2}-\d{1,2}', arg[0]):
+ year, month = [int(x) for x in arg[0].split('-')]
+ year = 2000 + year if year < 1000 else year
+ elif len(arg):
+ await session.send('脑子变奇怪了...无法识别master的信息,先给份本季的番8...')
+
+ if year is not None:
+ session.state['year'] = year
+ if month is not None:
+ session.state['month'] = month \ No newline at end of file
diff --git a/AyaBot/plugins/awsl.py b/AyaBot/plugins/other.py
index d2f976a..2b2cac1 100644
--- a/AyaBot/plugins/awsl.py
+++ b/AyaBot/plugins/other.py
@@ -8,18 +8,16 @@ import pytz
from pandas import Timestamp
-CST_TIMEZONE = 'Asia/Shanghai'
+CST = 'Asia/Shanghai'
-
-def beijing_now(freq: Optional[str] = None) -> datetime:
- now = datetime.now(pytz.timezone(CST_TIMEZONE))
+def get_beijing_time(freq: Optional[str] = None) -> datetime:
+ now = datetime.now(pytz.timezone(CST))
if freq is not None:
now = Timestamp(now).round(freq)
return now
-
def beijing_from_timestamp(timestamp: int) -> datetime:
- return datetime.fromtimestamp(timestamp, pytz.timezone(CST_TIMEZONE))
+ return datetime.fromtimestamp(timestamp, pytz.timezone(CST))
@on_command('阿这', only_to_me=False)
@@ -56,8 +54,4 @@ async def _(session: CommandSession):
await session.send('获取数据时出问题,请重试')
return
- await session.send(f'本群目前共有{len(seach_group_member)}人')
-
-
-
- \ No newline at end of file
+ await session.send(f'本群目前共有{len(seach_group_member)}人') \ No newline at end of file