summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-06-06 20:46:56 +0800
committerKyomotoi <[email protected]>2020-06-06 20:46:56 +0800
commitea46a07cdede40ca17fe84b8949b595dd44a3b9e (patch)
tree934de7a47587777c8fa6dedd784f98bbec991593
parentb6ee52b1e53cd44f43b588a59d590bb7cf02b6d5 (diff)
downloadATRI-ea46a07cdede40ca17fe84b8949b595dd44a3b9e.tar.gz
ATRI-ea46a07cdede40ca17fe84b8949b595dd44a3b9e.tar.bz2
ATRI-ea46a07cdede40ca17fe84b8949b595dd44a3b9e.zip
NEW FUNCTION H-B-O-O-K
-rw-r--r--AyaBot/plugins/__pycache__/hbook.cpython-37.pycbin0 -> 2466 bytes
-rw-r--r--AyaBot/plugins/__pycache__/weather.cpython-37.pycbin4221 -> 4253 bytes
-rw-r--r--AyaBot/plugins/hbook.py68
3 files changed, 68 insertions, 0 deletions
diff --git a/AyaBot/plugins/__pycache__/hbook.cpython-37.pyc b/AyaBot/plugins/__pycache__/hbook.cpython-37.pyc
new file mode 100644
index 0000000..9d3982b
--- /dev/null
+++ b/AyaBot/plugins/__pycache__/hbook.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/__pycache__/weather.cpython-37.pyc b/AyaBot/plugins/__pycache__/weather.cpython-37.pyc
index 733d83e..fab7f30 100644
--- a/AyaBot/plugins/__pycache__/weather.cpython-37.pyc
+++ b/AyaBot/plugins/__pycache__/weather.cpython-37.pyc
Binary files differ
diff --git a/AyaBot/plugins/hbook.py b/AyaBot/plugins/hbook.py
new file mode 100644
index 0000000..8ff3b88
--- /dev/null
+++ b/AyaBot/plugins/hbook.py
@@ -0,0 +1,68 @@
+import re
+import nonebot
+from aiohttp import ClientSession
+from nonebot import on_command, CommandSession
+
+
+async def post_bytes(url, headers=None,data=None):
+ async with ClientSession() as asyncsession:
+ async with asyncsession.post(url,headers=headers,data=data) as response:
+ b = await response.read()
+ return b
+
+
+hbook_switch = True
+@on_command('switch', aliases=['开启', '关闭'], only_to_me=False)
+async def _(session: CommandSession):
+ if session.ctx['user_id'] in session.bot.config.SUPERUSERS:
+ command = session.ctx['raw_message'].split(' ', 1)
+ swtich = command[0]
+ plugins = command[1]
+ global hbook_switch
+ if swtich == '开启':
+ if plugins == '本子':
+ hbook_switch = True
+ else:
+ await session.send('检查一下是否输错了呢')
+ else:
+ if plugins == '本子':
+ hbook_switch = False
+ else:
+ await session.send('检查一下是否输错了呢')
+ await session.send('完成')
+ else:
+ await session.send('恁哪位?')
+
+
+@on_command('hbook', aliases=['本子', '找本子', '本子查询'], only_to_me=False)
+async def _(session: CommandSession):
+ if hbook_switch:
+ h_msg = session.current_arg.strip()
+ if not h_msg:
+ h_msg = session.get('message', prompt='要冲了吗?速发关键词')
+ h_type = session.ctx['message_type']
+ h_qq = session.ctx['user_id']
+ header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'}
+ keyword = {'show':'title,titleen,tags','keyboard':h_msg}
+ responce = await post_bytes('https://b-upp.com/search/', headers=header, data=keyword)
+ responce = responce.decode()
+ if '没有搜索到相关的内容' in responce:
+ n_msg = '...似乎没有找到[{}]相关的本子呢'.format(h_msg)
+ await session.send(message=n_msg)
+ else:
+ p = '<a href="(.*?)" target="_blank" title="(.*?)">'
+ data = re.findall(p,responce)
+ n = len(data)
+ if h_type == 'group':
+ limit = 3
+ elif h_type == 'private':
+ limit = 10
+ if n > limit:
+ n = limit
+ msg = f'根据提供信息,已查询到{n}本关键词为[{h_msg}]的本子:'
+ if h_type == 'group':
+ msg = f'[CQ:at,qq={h_qq}]\n根据提供信息,已查询到{n}本关键词为[{h_msg}]的本子:'
+ for i in range(n):
+ msg0 = ('\n——————————\n本子链接:https://b-upp.com%s \n本子标题:%s '%(data[i]))
+ msg += msg0
+ await session.send(message=msg) \ No newline at end of file