客户端模块改名
This commit is contained in:
parent
b5fc26c3e8
commit
fd9fdae6ef
@ -1,4 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .models import *
|
from .models import *
|
||||||
from .handlers import *
|
from .handlers import *
|
||||||
from .blivedm import *
|
from .client import *
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import *
|
from typing import *
|
||||||
|
|
||||||
from . import blivedm
|
from . import client as client_
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -45,7 +45,7 @@ class HandlerInterface:
|
|||||||
直播消息处理器接口
|
直播消息处理器接口
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def handle(self, client: blivedm.BLiveClient, command: dict):
|
async def handle(self, client: client_.BLiveClient, command: dict):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@ -54,29 +54,29 @@ class BaseHandler(HandlerInterface):
|
|||||||
一个简单的消息处理器实现,带消息分发和消息类型转换。继承并重写_on_xxx方法即可实现自己的处理器
|
一个简单的消息处理器实现,带消息分发和消息类型转换。继承并重写_on_xxx方法即可实现自己的处理器
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __heartbeat_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __heartbeat_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_popularity(client, models.HeartbeatMessage.from_command(command['data']))
|
return self._on_popularity(client, models.HeartbeatMessage.from_command(command['data']))
|
||||||
|
|
||||||
def __danmu_msg_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __danmu_msg_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_danmaku(client, models.DanmakuMessage.from_command(command['info']))
|
return self._on_danmaku(client, models.DanmakuMessage.from_command(command['info']))
|
||||||
|
|
||||||
def __send_gift_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __send_gift_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_gift(client, models.GiftMessage.from_command(command['data']))
|
return self._on_gift(client, models.GiftMessage.from_command(command['data']))
|
||||||
|
|
||||||
def __guard_buy_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __guard_buy_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_buy_guard(client, models.GuardBuyMessage.from_command(command['data']))
|
return self._on_buy_guard(client, models.GuardBuyMessage.from_command(command['data']))
|
||||||
|
|
||||||
def __super_chat_message_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __super_chat_message_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_super_chat(client, models.SuperChatMessage.from_command(command['data']))
|
return self._on_super_chat(client, models.SuperChatMessage.from_command(command['data']))
|
||||||
|
|
||||||
def __super_chat_message_delete_callback(self, client: blivedm.BLiveClient, command: dict):
|
def __super_chat_message_delete_callback(self, client: client_.BLiveClient, command: dict):
|
||||||
return self._on_super_chat_delete(client, models.SuperChatDeleteMessage.from_command(command['data']))
|
return self._on_super_chat_delete(client, models.SuperChatDeleteMessage.from_command(command['data']))
|
||||||
|
|
||||||
# cmd -> 处理回调
|
# cmd -> 处理回调
|
||||||
_CMD_CALLBACK_DICT: Dict[
|
_CMD_CALLBACK_DICT: Dict[
|
||||||
str,
|
str,
|
||||||
Optional[Callable[
|
Optional[Callable[
|
||||||
['BaseHandler', blivedm.BLiveClient, dict],
|
['BaseHandler', client_.BLiveClient, dict],
|
||||||
Awaitable
|
Awaitable
|
||||||
]]
|
]]
|
||||||
] = {
|
] = {
|
||||||
@ -99,7 +99,7 @@ class BaseHandler(HandlerInterface):
|
|||||||
_CMD_CALLBACK_DICT[cmd] = None
|
_CMD_CALLBACK_DICT[cmd] = None
|
||||||
del cmd
|
del cmd
|
||||||
|
|
||||||
async def handle(self, client: blivedm.BLiveClient, command: dict):
|
async def handle(self, client: client_.BLiveClient, command: dict):
|
||||||
cmd = command.get('cmd', '')
|
cmd = command.get('cmd', '')
|
||||||
pos = cmd.find(':') # 2019-5-29 B站弹幕升级新增了参数
|
pos = cmd.find(':') # 2019-5-29 B站弹幕升级新增了参数
|
||||||
if pos != -1:
|
if pos != -1:
|
||||||
@ -116,32 +116,32 @@ class BaseHandler(HandlerInterface):
|
|||||||
if callback is not None:
|
if callback is not None:
|
||||||
await callback(self, client, command)
|
await callback(self, client, command)
|
||||||
|
|
||||||
async def _on_popularity(self, client: blivedm.BLiveClient, message: models.HeartbeatMessage):
|
async def _on_popularity(self, client: client_.BLiveClient, message: models.HeartbeatMessage):
|
||||||
"""
|
"""
|
||||||
收到人气值
|
收到人气值
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _on_danmaku(self, client: blivedm.BLiveClient, message: models.DanmakuMessage):
|
async def _on_danmaku(self, client: client_.BLiveClient, message: models.DanmakuMessage):
|
||||||
"""
|
"""
|
||||||
收到弹幕
|
收到弹幕
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _on_gift(self, client: blivedm.BLiveClient, message: models.GiftMessage):
|
async def _on_gift(self, client: client_.BLiveClient, message: models.GiftMessage):
|
||||||
"""
|
"""
|
||||||
收到礼物
|
收到礼物
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _on_buy_guard(self, client: blivedm.BLiveClient, message: models.GuardBuyMessage):
|
async def _on_buy_guard(self, client: client_.BLiveClient, message: models.GuardBuyMessage):
|
||||||
"""
|
"""
|
||||||
有人上舰
|
有人上舰
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _on_super_chat(self, client: blivedm.BLiveClient, message: models.SuperChatMessage):
|
async def _on_super_chat(self, client: client_.BLiveClient, message: models.SuperChatMessage):
|
||||||
"""
|
"""
|
||||||
醒目留言
|
醒目留言
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _on_super_chat_delete(self, client: blivedm.BLiveClient, message: models.SuperChatDeleteMessage):
|
async def _on_super_chat_delete(self, client: client_.BLiveClient, message: models.SuperChatDeleteMessage):
|
||||||
"""
|
"""
|
||||||
删除醒目留言
|
删除醒目留言
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user