{"id":19965357,"url":"https://github.com/eric2788/bililivebot","last_synced_at":"2025-05-03T23:30:44.188Z","repository":{"id":45828526,"uuid":"427730096","full_name":"eric2788/BiliLiveBot","owner":"eric2788","description":"插件化式管理的B站直播互动/房管机器人","archived":false,"fork":false,"pushed_at":"2024-11-05T01:45:51.000Z","size":27,"stargazers_count":29,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T23:05:06.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eric2788.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-13T17:30:20.000Z","updated_at":"2025-04-06T13:29:40.000Z","dependencies_parsed_at":"2024-11-13T06:02:32.295Z","dependency_job_id":null,"html_url":"https://github.com/eric2788/BiliLiveBot","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2FBiliLiveBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2FBiliLiveBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2FBiliLiveBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2FBiliLiveBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eric2788","download_url":"https://codeload.github.com/eric2788/BiliLiveBot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252269026,"owners_count":21721239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T02:28:27.955Z","updated_at":"2025-05-03T23:30:43.436Z","avatar_url":"https://github.com/eric2788.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!IMPORTANT]\n\u003e 本项目目前因为B站直播改版已经作废，如果希望启动重写项目，可以[点击这里](https://github.com/eric2788/BiliLiveBot/discussions/6)\n\n---\n\n## BiliLiveBot\n\n可插件化管理的B站直播间机器人\n\n目前机器人可以执行\n- 发送弹幕\n- 禁言用户 (需要房管权限)\n- 全局禁言 (需要房管权限)\n- 新增屏蔽字 (需要房管权限)\n- 删除屏蔽字 (需要房管权限)\n\n\n__WebSocket 库:  [xfgryujk/blivedm](https://github.com/xfgryujk/blivedm)__\n\n\n### 运行\n\n目前有三种方式运行\n\n#### 1. 直接使用 python 指令运行\n此运行方式将包含范例插件在内\n\n1. 建置 python 環境\n2. 下載源碼\n3. 輸入 python main.py 運行\n\n#### 2. 到 releases 下载 exe 运行\n此运行方式无需要python环境\n\n1. 到 releases 下载最新版zip\n2. 提取你的环境的档案 (.exe 为 windows, binary 为 linux)\n3. 打开程序直接运行\n\n#### 3. 使用 Docker 运行\n此运行方式需要熟悉Docker环境\n\n1. 下载源码\n2. 使用 docker build 建置 image\n3. 使用 docker run 运行\n\n你可能需要预先扫描二维码並复制 data/session.json 以略过在 docker container 内扫描\n\n### 新增插件\n\n插件需要放在 ``plugins/`` 文件夹底下\n\n#### 步骤\n1. 在 ``plugins/`` 文件夹下新增一个新的 ``.py`` 档案\n2. 在 py 档案中，新增一个 class 並继承 ``plugins.BotPlugin``\n3. 在 class 中实作 ``async def on_command_received(self, cmd, data) `` 方法\n4. 完成，使用 ``python main.py`` 指令运行程序\n\n__如需要使用设定, 可调用 ``plugins.load_config(yml, 默認設定)`` 来获取 在 config 目录下的 yaml 设定__\n\n#### 范例\n\n以下所有范例档案均在 ``plugins/`` 文件夹底下。\n\n1# 透过關鍵字触发时间显示\n\n```py\n# plugins/time.py\nfrom plugin import BotPlugin, DanmakuMessage\nfrom datetime import datetime\n\nclass TimeChecker(BotPlugin):\n    async def on_command_received(self, cmd, data):\n        if cmd != 'DANMU_MSG':\n            return\n        danmu = DanmakuMessage.from_command(data['info'])\n        if danmu.msg != '!时间':\n            return\n        now = datetime.now()\n        show = now.strftime('%Y{y}%m{m}%d{d}').format(y='年', m='月', d='日')\n        await self.send_message(f'现在的时间为: {show}')\n```\n\n2# 从 yaml 设定提取禁言弹幕列表 (需要有房管权限)\n\n```yaml\n# config/mute.yml\nbad_danmaku:\n  - '主播是个大伞兵'\n  - '主播你寄吧谁啊'\n  - '主播NMSL'\n```\n\n```py\n# plugins/mute.py\nfrom plugin import BotPlugin, DanmakuMessage, load_config\n\n# 默認設定\nDEFAULT_CONTENT = {\n    'bad_danmaku': [\n        '主播是个大伞兵',\n        '主播你寄吧谁啊',\n        '主播NMSL'\n    ]\n}\n\n\nclass MuteUser(BotPlugin):\n\n    def __init__(self) -\u003e None:\n        super().__init__()\n        # 使用 load_config 从 config/ 目录加载 mute.yml\n        # 如果 找不到 mute.yml 則使用 默認設定 生成一個 yml 並保存\n        data = load_config('mute.yml', DEFAULT_CONTENT) \n        self.bad_danmaku = data['bad_danmaku'] if data != None else []\n        print(f'禁言弹幕: {self.bad_danmaku}')\n\n    async def on_command_received(self, cmd, data):\n        if cmd != 'DANMU_MSG':\n            return\n        danmu = DanmakuMessage.from_command(data['info'])\n        if danmu.msg not in self.bad_danmaku:\n            return\n        uid = danmu.uid\n        # 需要管理员权限进行禁言\n        if await self.mute_user(uid):\n            await self.send_message(f'{danmu.uname}, 你已被禁言!')\n        else:\n            print('禁言失败，可能没有权限')\n```\n\n3# 感谢礼物\n\n```py\n# plugins/thanks_gift.py\nclass ThanksGift(BotPlugin):\n\n    async def on_command_received(self, cmd, data):\n        if cmd != 'SEND_GIFT':\n            return\n\n        gift = GiftMessage.from_command(data['data'])\n        await self.send_message(f'感谢 {gift.uname} 送出的 {gift.gift_name} x{gift.num}')\n```\n\n### 参考\n\n```py\nclass BotPlugin:\n\n    def __init__(self) -\u003e None:\n        self.botid = -1 # bot 的 uid, 可以在收到指令时使用\n\n    \"\"\"\n    收到指令时\n    \"\"\"\n    @abstractmethod\n    async def on_command_received(self, cmd, data):\n        pass\n\n    \"\"\"\n    收到人气时\n    \"\"\"\n    @abstractmethod\n    async def on_receive_popularity(self, popularity: int):\n        pass\n\n    \"\"\"\n    发送弹幕\n    \"\"\"\n    async def send_message(self,\n                        danmaku: str, \n                        fontsize: int = 25, \n                        color: int = 0xffffff, \n                        pos: DanmakuPosition = DanmakuPosition.NORMAL\n                    ) -\u003e bool:\n        pass\n\n    \"\"\"\n    以下所有操作全部需要房管权限\n\n    \"\"\"\n    \"\"\"\n    禁言用户\n    \"\"\"\n    async def mute_user(self, uid: int) -\u003e bool:\n        pass\n\n    \"\"\"\n    全局禁言\n    \"\"\"\n    # \"level\" | \"medal\" | \"member\"\n    async def room_slient_on(self, slientType: str, minute: int, level: int) -\u003e bool:\n        pass\n\n    \"\"\"\n    全局禁言关闭\n    \"\"\"\n    async def room_slient_off(self) -\u003e bool:\n        pass\n\n    \"\"\"\n    新增屏蔽字\n    \"\"\"\n    async def add_badword(self, badword: str) -\u003e bool:\n        pass\n\n    \"\"\"\n    删除屏蔽字\n    \"\"\"\n    async def remove_badword(self, badword: str) -\u003e bool:\n        pass\n```\n\n除此之外，你也可以使用 [xfgryujk/blivedm](https://github.com/xfgryujk/blivedm) 的 API来让WS数据物件化:\n\n```py\nasync def on_command_received(self, cmd, command):\n    if cmd == 'DANMU_MSG': # 弹幕数据物件化\n        DanmakuMessage.from_command(command['info'])\n    elif cmd == 'SEND_GIFT': # 礼物数据物件化\n        GiftMessage.from_command(command['data'])\n    elif cmd == 'GUARD_BUY': # 舰长数据物件化\n        GuardBuyMessage.from_command(command['data'])\n    elif cmd == 'SUPER_CHAT_MESSAGE': # SC数据物件化\n        SuperChatMessage.from_command(command['data'])\n    elif cmd == 'SUPER_CHAT_MESSAGE_DELETE': # SC删除数据物件化\n        SuperChatDeleteMessage.from_command(command['data'])\n```\n\n[__视频演示__](https://www.bilibili.com/video/BV1LT4y1R7Xk)\n\n### 鸣谢\n\n- [blivedm](https://github.com/xfgryujk/blivedm)\n- [bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric2788%2Fbililivebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feric2788%2Fbililivebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric2788%2Fbililivebot/lists"}