Skip to content

Commit

Permalink
[Feature] Bilibili 接入 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
luxuncang committed Feb 28, 2022
1 parent f6b814d commit 393a08b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Alice/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
from .github import GithubParse
from .music import cloudmusic
from .runCode import Language, runCode
from .ftp import ftp, ftp_file
from .ftp import ftp, ftp_file
from .bilibili import bil_search, bil_download
64 changes: 41 additions & 23 deletions Alice/event/AliceEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Source,
config
)
from ..utils import Thread
from ..utils import Thread, batch_forwardnode
from ..scope import (
MiraiBot,
AliceBuiltins,
Expand All @@ -35,28 +35,7 @@

)
from ..parse import AliceParse, ParseRusult, ElementMatch, ParseMatch, ArgumentMatch, time_completion
from ..api import (
qingyunke_chat,
oneYan,
getBaike,
translation,
AlphaZero,
getwiki,
getBlog,
getMusic,
cloudmusic,
getImage_seovx,
PlayExec,
Render,
baidu_ORC,
strtoAction,
ParamikoClient,
GithubParse,
runCode,
Language,
ftp,
ftp_file
)
from ..api import *
import asyncssh, asyncio, inspect, os
from datetime import datetime
from functools import lru_cache
Expand Down Expand Up @@ -790,6 +769,45 @@ async def sendftp():
async def callback(self):
...

class BilibiliEvent(AliceEvent, AsyncAdapterEvent):

__ParseMapper__ = AliceParse(
command = [ParseMatch('bili{command:>}')],
least = [([ParseMatch('bili -s{text:>}'), ParseMatch('bili -d{url:>}')], 1)],
)

__eventname__ = 'bili'

__help__ = '''Help:
command: `bili [-s, -d] {command}`
description: bilibili 查询, 下载
'''

async def funcevents(
self,
message: ParseRusult,
app: GraiaMiraiApplication,
context: Context,
EventChain: AliceEventChain,
):

async def search():
async with AliceSession(AliceParse([r'([\s\S]*)']), context, EventChain, 600) as session:
if getattr(message, 'text'):
res = await bil_search(message.text)
messages = [MessageChain.create(Plain(f"aid: {i[0]}\nbvid: {i[1]}\ntag: {i[3]}\nauthor: {i[4]}\ndescription: {i[5]}\nurl: {i[2]}"), Image(url = 'http:' + i[-1])) for i in res[:5]]
forward = batch_forwardnode(app.account, messages, "Alice for B站")
await session.send(MessageChain.create(forward), False)

elif getattr(message, 'url'):
path, vid = await bil_download(message.url)
await session.sendofdict({'Plain': f'上传中...', 'file': (open(path, 'rb'), f"{vid}.mp4")})
os.remove(path)
return [search]

async def callback(self):
...

class RetractEvent(AliceEvent, AsyncAdapterEvent):

__ParseMapper__ = AliceParse(command = [ParseMatch('撤回{num:>}')])
Expand Down

0 comments on commit 393a08b

Please sign in to comment.