Giter Site home page Giter Site logo

shuyangzhang / kyouka Goto Github PK

View Code? Open in Web Editor NEW
116.0 7.0 35.0 184 KB

Kyouka is a simple and powerful music bot for KOOK(AKA KaiHeiLa), it is easy to use and develop.

License: MIT License

Python 99.37% Dockerfile 0.63%
bot kaiheila kaiheila-bot music-bot python kook kook-bot

kyouka's Introduction

Kyouka 镜华 点歌机器人

GitHub last commit Release MIT license khl server github stars

Kyouka is a simple and powerful music bot for KOOK, it is easy to use and develop.

Multilingual README

English | 中文

Contents

Statement

This repository is created just for learning python(Commercial prohibition).
All the apis used in this repository are from public network. So, if you wanna to listen the paid songs,
please open a paid member on corresponding music platform by yourself (respect the music copyright please).
Finally, if there are any infringements, please contact me to delete this repository.

Features

  • Multi platform
  • All async
  • Container as a service

Dependencies

  • Docker, whether you are deploying based on docker or binaries.
  • Python >= 3.9, if you wanna to deploy it based on source code.

Installation and Deployment

Deploy based on docker service

I highly recommend you to deploy based on docker because it is easy to configure.

  1. if you havn't install docker, please follow these instructions.
  1. check if your docker is ready.
docker version
  1. pull the Kyouka bot image and khl-voice image.

Kyouka bot image provides multi-architecture support for linux/amd64 and linux/arm64.
khl-voice image only support for linux/amd64 arch.

If you are using Windows/x86_64, macos/amd64, macos/arm64, don't worry about that, you can also run images targeted for a different architecture on Docker Desktop.

docker pull shuyangzhang/kyouka
docker pull shuyangzhang/khl-voice
  1. copy the .env.template file from this repository or clone this repository, then rename it to .env.
git clone https://github.com/shuyangzhang/Kyouka.git
cd Kyouka
mv .env.template .env
  1. configure the .env file.

WARN: Do not insert any useless characters (including spaces, comments) at the end of the lines of configuration items, otherwise it will cause json parsing failure.

# your bot token
TOKEN=1/MECxOTk=/zCX2VjWr6p+AmD84jL9asQ==

# default voice channel
CHANNEL=2559449076697969

# the name of khl-voice sdk container, it should be different with your manager(bot) container name
CONTAINER_NAME=kyouka-runner

# the admin user id list
ADMIN_USERS=["693543263"]

# the file_logger switch
FILE_LOGGER=false
  1. create container for Kyouka bot.
docker run --name kyouka-manager --env-file .env -v /var/run/docker.sock:/var/run/docker.sock --restart always -d shuyangzhang/kyouka
  1. now the bot in running, send a /ping command in your channel, if Kyouka reply you, that means your deployment is completed, enjoy!

WARN: make sure that you have granted your bot read & send permissions.

Deploy based on source code

if you are using Win10/Win11, I highly recommend you to run these scripts in WSL2.

How to Install Linux on Windows with WSL

  1. same to step 1 of deploy based on docker service, install docker and check if it is ready.
docker version

make sure that you can run docker command without sudo. seeing Manage Docker as a non-root user

  1. pull the khl-voice image
docker pull shuyangzhang/khl-voice
  1. make sure you have installed Python, and its version >= 3.9

Download Python for your os

python -V
  1. clone this repository, then rename .env.template file to .env.
git clone https://github.com/shuyangzhang/Kyouka.git
cd Kyouka
mv .env.template .env
  1. configure the .env file.

WARN: Do not insert any useless characters (including spaces, comments) at the end of the lines of configuration items, otherwise it will cause json parsing failure.

# your bot token
TOKEN=1/MECxOTk=/zCX2VjWr6p+AmD84jL9asQ==

# default voice channel
CHANNEL=2559449076697969

# the name of khl-voice sdk container, it should be different with your manager(bot) container name
CONTAINER_NAME=kyouka-runner

# the admin user id list
ADMIN_USERS=["693543263"]

# the file_logger switch
FILE_LOGGER=false
  1. install python dependencies.
# install vritualenv and initialize a venv for your bot
pip install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple
virtualenv venv

# activate venv
source venv/bin/activate

# install dependencies
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. run the Kyouka bot.
python startup.py
  1. now the bot in running, send a /ping command in your channel, if Kyouka reply you, that means your deployment is completed, enjoy!

WARN: make sure that you have granted your bot read & send permissions.

Usage

Quick Start

send a /help command in you channel, Kyouka will teach you how to use.

Commands

  • /ping: check whether Kyouka is alive.
  • /help: get usage from Kyouka.
  • /debug: (only for admin) the debug switch.
  • /comehere: bind the voice channel you are in.
  • /channel {channel_id}: bind the voice channel with id.
  • /play {music_name}: add a music to play list.
  • /search {keyword}: search music by keyword from netease cloud music.
  • /msearch {keyword}: search music by keyword from migu music.
  • /qsearch {keyword}: search music by keyword from qq muisc.
  • /osearch {keyword}: search music by keyword from game osu!.
  • /select {search_list_id}: select a music from search result, then add it to play list.
  • /bilibili {bilibili_video_url}: add a video from Bilibili to play list.
  • /list: check the play list.
  • /cut: play the next music in play list.
  • /playlist {playlist_url}: import a netease cloud music play list to Kyouka.
  • /radio {radio_url}: import a netease cloud music radio list to Kyouka.
  • /album {album_url}: import a netease cloud music album to Kyouka.
  • /remove {list_id}: remove a music from play list.
  • /top {list_id}: place a music at the top of play list.

Development

Contributing

  • using the issue tracker
    Use the issue tracker to suggest feature requests, report bugs, and ask questions. This is also a great way to connect with the developers of the project as well as others who are interested in this solution.

  • changing the code base
    Generally speaking, you should fork this repository, make changes in your own fork, and then submit a pull request. All commit messages should satisfy Conventional Commits

License

This project is licensed under the terms of the MIT license.

Community

If you need help, have any comments and suggestions, or want to develop Kyouka together, feel free to join our official community: https://kaihei.co/oHRMIL

Credits

This project is all based on khl.py

kyouka's People

Contributors

diaossama avatar froyorab avatar lucunji avatar nick-haoran avatar omoidesu avatar shuyangzhang avatar snwcreations avatar tamakotuan avatar tripleint avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kyouka's Issues

机器人无法在线

按照步骤在阿里云上部署成功了 但是kook里机器人还是离线状态 我猜想是不是端口的问题 请问相关端口有什么需要开放的嘛

切换歌曲时会播放进场提示音

机器人在切换歌曲时会自动退出语言频道并重进,导致在切歌时会有进场提示音,破坏使用体验。

系统:CentOS
部署方式:docker
日志:false

部署好以后点歌没声音

如果点来源网易云的歌曲后台报错显示解码失败,如果点Q音的歌曲则后台正常显示正在播放,但机器人进频道以后没有声音并且绿色麦克风不亮,疑似没有声音输入
(并且每隔一段时间机器人都会掉线 需要在docker重启manager才会恢复)
QQ图片20240225214303

部署时出现了一个问题,我这边是查看docker的日志看见的

2023-07-16 11:19:02.615 | ERROR    | app.task.interval_tasks:keep_bproxy_alive:97 - bproxy is not available, error msg: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://bproxy.shuyangzhang.repl.co/'), traceback: Traceback (most recent call last):
  File "/Kyouka/app/task/interval_tasks.py", line 93, in keep_bproxy_alive
    resp_json = await r.json()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://bproxy.shuyangzhang.repl.co/')

2023-07-16 11:19:02.615 | ERROR    | app.task.interval_tasks:keep_bproxy_alive:98 - bproxy is not alive now

如何解决?

部署两个机器人

我有多个KOOK语音服务器,我想给每个服务器都配置一个专用的镜华机器人,我应该怎么做?docker容器应该可以部署很多个,但是下载的git文件中的.env我可以反复修改吗?

每首歌播放到后半段后都会没有声音

试了很多歌,大约播放到1/2-2/3时就会没有声音,用/list查看显示还有剩余时间,到下一首歌时又会恢复声音,然后到后半段声音又会消失,播放网易云qq音乐和咪咕音乐的歌曲都有这样的问题

[问题反馈]Docker镜像启动失败

Docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  compose: Docker Compose (Docker Inc.)
    Version:  2.16.0
    Path:     /usr/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 2
 Server Version: 23.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640.m
 runc version: 
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.12-x64v1-xanmod1-1
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.38GiB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

相关信息:
Docker更新了以后,舍去了原来的Storage Driver,我手动配置更换了Storage Driver以后重新pull容器启动出现如下错误信息。

Error Message:

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: unable to apply apparmor profile: apparmor failed to apply profile: write /proc/self/attr/apparmor/exec: no such file or directory: unknown.

[BUG反馈]一首歌播完以后自动切歌无声音

问题描述

连续点了几首歌,播完第一首以后,机器人自动退出再加入语音频道,但是没有声音

后台logs

2023-01-03 14:28:02.616 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:17 - LOCK: False
2023-01-03 14:28:07.616 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:15 - PLAYED: 220000
2023-01-03 14:28:07.616 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:16 - Q: ['Music(40140636, 习惯失恋 (Live In Hong Kong / 2015), 容祖儿, http://music.163.com/song/media/outer/url?id=40140636.mp3, 240195, 1672727311704, Joey Yung X Hacken Lee Concert 2015, http://p2.music.126.net/wGhf8z-_BYki8uPBHmWgZA==/109951163463758536.jpg?param=130y130, netease)']
2023-01-03 14:28:07.616 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:17 - LOCK: False
2023-01-03 14:28:12.617 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:15 - PLAYED: 225000
2023-01-03 14:28:12.617 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:16 - Q: ['Music(40140636, 习惯失恋 (Live In Hong Kong / 2015), 容祖儿, http://music.163.com/song/media/outer/url?id=40140636.mp3, 240195, 1672727311704, Joey Yung X Hacken Lee Concert 2015, http://p2.music.126.net/wGhf8z-_BYki8uPBHmWgZA==/109951163463758536.jpg?param=130y130, netease)']
2023-01-03 14:28:12.617 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:17 - LOCK: False
2023-01-03 14:28:13.051 | INFO     | app.utils.log_utils:wrapped_function:12 - user: onlyblacktea user_id: 1241400812 in guild_id: 8600713264337142 used command playlist with args ('2237551001',) and {}, log_id: 4df79080-904a-4eb8-975d-e2fdf1476e93
2023-01-03 14:28:13.960 | DEBUG    | app.music.netease.playlist:fetch_music_list_by_id:32 - [<app.music.music.Music object at 0x7f025b81ec10>, <app.music.music.Music object at 0x7f025b81ed00>, <app.music.music.Music object at 0x7f025b8468b0>, <app.music.music.Music object at 0x7f025b846cd0>, <app.music.music.Music object at 0x7f025b846460>, <app.music.music.Music object at 0x7f025b846430>, <app.music.music.Music object at 0x7f025b5de610>, <app.music.music.Music object at 0x7f025b5de190>, <app.music.music.Music object at 0x7f025b5de640>, <app.music.music.Music object at 0x7f025b5de130>]
2023-01-03 14:28:16.914 | INFO     | app.utils.log_utils:wrapped_function:12 - user: onlyblacktea user_id: 1241400812 in guild_id: 8600713264337142 used command list with args () and {}, log_id: 615ae505-26a7-438b-a14f-711a55c35174
2023-01-03 14:28:17.613 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:15 - PLAYED: 230000
2023-01-03 14:28:17.613 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:16 - Q: ['Music(40140636, 习惯失恋 (Live In Hong Kong / 2015), 容祖儿, http://music.163.com/song/media/outer/url?id=40140636.mp3, 240195, 1672727311704, Joey Yung X Hacken Lee Concert 2015, http://p2.music.126.net/wGhf8z-_BYki8uPBHmWgZA==/109951163463758536.jpg?param=130y130, netease)', 'Music(347230, 海阔天空, Beyond, http://music.163.com/song/media/outer/url?id=347230.mp3, 326000, -1, 海阔天空, http://p2.music.126.net/8y8KJC1eCSO_vUKf2MyZwA==/109951165796899183.jpg?param=130y130, netease)', 'Music(186436, 玻璃之情, 张国荣, http://music.163.com/song/media/outer/url?id=186436.mp3, 283147, -1, I Am What I Am, http://p2.music.126.net/bqq6DITA5nj_yd_i6dsiTA==/109951166225429773.jpg?param=130y130, netease)', 'Music(191232, 遥远的她, 张学友, http://music.163.com/song/media/outer/url?id=191232.mp3, 259000, -1, 遥远的她·Amour, http://p2.music.126.net/0lu24itIeyu1wqw1VBsAPA==/109951167226024985.jpg?param=130y130, netease)', 'Music(212233, 千千阕歌, 陈慧娴, http://music.163.com/song/media/outer/url?id=212233.mp3, 299106, -1, 千千阙歌, http://p2.music.126.net/tzmGFZ0-DPOulXS97H5rmA==/18712588395102549.jpg?param=130y130, netease)', 'Music(2011083595, Soygu Uqun, Hanzohra-Ahat, http://music.163.com/song/media/outer/url?id=2011083595.mp3, 212688, -1, Soygu Uqun, http://p2.music.126.net/mEU5VqAtvVtcM3kAlt-2rQ==/109951168199404516.jpg?param=130y130, netease)', 'Music(5271858, 难念的经, 周华健, http://music.163.com/song/media/outer/url?id=5271858.mp3, 288853, -1, 电视剧歌曲大全, http://p2.music.126.net/kwahKngiu5K4s2hktASbsw==/109951165792137374.jpg?param=130y130, netease)', 'Music(317868, 情人知己, 叶蒨文, http://music.163.com/song/media/outer/url?id=317868.mp3, 275332, -1, 一辈子 华纳精选34首, http://p2.music.126.net/PjEW1r30J115ISbSX2PtHg==/119846767442616.jpg?param=130y130, netease)', 'Music(28838055, 再见悲哀, 林忆莲, http://music.163.com/song/media/outer/url?id=28838055.mp3, 220450, -1, 我最喜爱的Eric Kwok作品展, http://p2.music.126.net/2H-eACt_dLeK-DmOjZAFRg==/5862595999612392.jpg?param=130y130, netease)', 'Music(156846, 不浪漫罪名, 王杰, http://music.163.com/song/media/outer/url?id=156846.mp3, 287495, -1, **2001 新曲+精选, http://p2.music.126.net/Wi2OW9TnEODyLDYH6gpcdg==/109951166656499933.jpg?param=130y130, netease)', 'Music(229285, 漫步人生路, 邓丽君, http://music.163.com/song/media/outer/url?id=229285.mp3, 222746, -1, 漫步人生路, http://p1.music.126.net/pr1xkan9NAb_xw9VGN_C-w==/109951167379869503.jpg?param=130y130, netease)']
2023-01-03 14:28:17.613 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:17 - LOCK: False
2023-01-03 14:28:22.614 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:15 - PLAYED: 235000
2023-01-03 14:28:22.614 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:16 - Q: ['Music(40140636, 习惯失恋 (Live In Hong Kong / 2015), 容祖儿, http://music.163.com/song/media/outer/url?id=40140636.mp3, 240195, 1672727311704, Joey Yung X Hacken Lee Concert 2015, http://p2.music.126.net/wGhf8z-_BYki8uPBHmWgZA==/109951163463758536.jpg?param=130y130, netease)', 'Music(347230, 海阔天空, Beyond, http://music.163.com/song/media/outer/url?id=347230.mp3, 326000, -1, 海阔天空, http://p2.music.126.net/8y8KJC1eCSO_vUKf2MyZwA==/109951165796899183.jpg?param=130y130, netease)', 'Music(186436, 玻璃之情, 张国荣, http://music.163.com/song/media/outer/url?id=186436.mp3, 283147, -1, I Am What I Am, http://p2.music.126.net/bqq6DITA5nj_yd_i6dsiTA==/109951166225429773.jpg?param=130y130, netease)', 'Music(191232, 遥远的她, 张学友, http://music.163.com/song/media/outer/url?id=191232.mp3, 259000, -1, 遥远的她·Amour, http://p2.music.126.net/0lu24itIeyu1wqw1VBsAPA==/109951167226024985.jpg?param=130y130, netease)', 'Music(212233, 千千阕歌, 陈慧娴, http://music.163.com/song/media/outer/url?id=212233.mp3, 299106, -1, 千千阙歌, http://p2.music.126.net/tzmGFZ0-DPOulXS97H5rmA==/18712588395102549.jpg?param=130y130, netease)', 'Music(2011083595, Soygu Uqun, Hanzohra-Ahat, http://music.163.com/song/media/outer/url?id=2011083595.mp3, 212688, -1, Soygu Uqun, http://p2.music.126.net/mEU5VqAtvVtcM3kAlt-2rQ==/109951168199404516.jpg?param=130y130, netease)', 'Music(5271858, 难念的经, 周华健, http://music.163.com/song/media/outer/url?id=5271858.mp3, 288853, -1, 电视剧歌曲大全, http://p2.music.126.net/kwahKngiu5K4s2hktASbsw==/109951165792137374.jpg?param=130y130, netease)', 'Music(317868, 情人知己, 叶蒨文, http://music.163.com/song/media/outer/url?id=317868.mp3, 275332, -1, 一辈子 华纳精选34首, http://p2.music.126.net/PjEW1r30J115ISbSX2PtHg==/119846767442616.jpg?param=130y130, netease)', 'Music(28838055, 再见悲哀, 林忆莲, http://music.163.com/song/media/outer/url?id=28838055.mp3, 220450, -1, 我最喜爱的Eric Kwok作品展, http://p2.music.126.net/2H-eACt_dLeK-DmOjZAFRg==/5862595999612392.jpg?param=130y130, netease)', 'Music(156846, 不浪漫罪名, 王杰, http://music.163.com/song/media/outer/url?id=156846.mp3, 287495, -1, **2001 新曲+精选, http://p2.music.126.net/Wi2OW9TnEODyLDYH6gpcdg==/109951166656499933.jpg?param=130y130, netease)', 'Music(229285, 漫步人生路, 邓丽君, http://music.163.com/song/media/outer/url?id=229285.mp3, 222746, -1, 漫步人生路, http://p1.music.126.net/pr1xkan9NAb_xw9VGN_C-w==/109951167379869503.jpg?param=130y130, netease)']
2023-01-03 14:28:22.614 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:17 - LOCK: False
2023-01-03 14:28:27.617 | DEBUG    | app.task.interval_tasks:update_played_time_and_change_music:15 - PLAYED: 240000

...

应用环境
Archlinux Kernel 6.1.1-x64v1-xanmod1-1
Docker镜像:shuyangzhang/kyouka:latest 426b83097665

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.