Skip to content

Commit

Permalink
Merge pull request #327 from SK-415/dev
Browse files Browse the repository at this point in the history
Release v1.5.3
  • Loading branch information
SK-415 authored Feb 6, 2023
2 parents 76191b2 + 058bd95 commit 8c4fb62
Show file tree
Hide file tree
Showing 30 changed files with 1,564 additions and 1,649 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project ignored
*.sqlite3
.pdm.toml

docs/.yarn
data/
Expand Down
19 changes: 5 additions & 14 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nonebot
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter
from nonebot.log import default_format, logger

logger.add(
Expand All @@ -12,23 +12,14 @@
encoding="utf-8",
)


nonebot.init()
app = nonebot.get_asgi()

driver = nonebot.get_driver()
driver.register_adapter(OneBotV11Adapter)

nonebot.load_from_toml("pyproject.toml")
driver.register_adapter(ONEBOT_V11Adapter)

# Modify some config / config depends on loaded configs
#
# config = driver.config
# do something...

nonebot.load_from_toml("pyproject.toml")

if __name__ == "__main__":
nonebot.logger.warning(
"Always use `nb run` to start the bot instead of manually running!"
)

nonebot.run(app="__mp_main__:app")
nonebot.run()
52 changes: 42 additions & 10 deletions docs/usage/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ HARUKA_DIR="./data/"
Haruka_TO_ME=False
```

## HARUKA_GUILD_ADMIN_ROLES

默认值:["管理员", "频道主"]

在频道里使用命令的身份组,可以写入多个身份组

```json
HARUKA_GUILD_ADMIN_ROLES=["Haruka", "频道主"]
```

## HARUKA_LIVE_OFF_NOTIFY

默认值:False
Expand Down Expand Up @@ -126,3 +116,45 @@ HARUKA_DYNAMIC_AT=True
```yml
HARUKA_SCREENSHOT_STYLE=pc
```

## HARUKA_DYNAMIC_TIMEOUT

默认值:10

动态加载超时,单位秒。
网络不好一直超时请调大此数值。

```json
HARUKA_DYNAMIC_TIMEOUT=30
```

## HARUKA_DYNAMIC_FONT

默认值:"Noto Sans CJK SC"

自定义动态截图使用的字体。只能使用系统中已经安装的字体。

```json
HARUKA_DYNAMIC_FONT="Microsoft YaHei"
```

## HARUKA_COMMAND_PREFIX

默认值:""

添加命令前缀,所有 HarukaBot 的命令需要带上前缀才能触发。

```json
# 使用方式:“hb帮助”、“hb关注列表”
HARUKA_COMMAND_PREFIX="hb"
```

## HARUKA_GUILD_ADMIN_ROLES

默认值:["管理员", "频道主"]

在频道里使用命令的身份组,可以写入多个身份组

```json
HARUKA_GUILD_ADMIN_ROLES=["Haruka", "频道主"]
```
2 changes: 1 addition & 1 deletion haruka_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

if isinstance(globals()["__loader__"], PluginLoader):
global_config = get_driver().config
config = Config(**global_config.dict())
config = Config.parse_obj(global_config)
from .utils import on_startup

on_startup()
Expand Down
5 changes: 3 additions & 2 deletions haruka_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class Config(BaseSettings):
haruka_dynamic_interval: int = 0
haruka_dynamic_at: bool = False
haruka_screenshot_style: str = "mobile"
haruka_dynamic_font: Optional[str] = "Noto Sans CJK SC"
haruka_dynamic_font_source: str = "system"
haruka_dynamic_timeout: int = 10
haruka_dynamic_font_source: str = "system"
haruka_dynamic_font: Optional[str] = "Noto Sans CJK SC"
haruka_command_prefix: str = ""
# 频道管理员身份组
haruka_guild_admin_roles: List[str] = ["频道主", "管理员"]

Expand Down
20 changes: 9 additions & 11 deletions haruka_bot/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from . import ( # noqa: F401
at,
auto_agree,
auto_delete,
dynamic,
help,
live,
permission,
pusher,
sub,
)
from . import auto_agree # noqa: F401
from . import auto_delete # noqa: F401
from . import help # noqa: F401
from .at import at_off, at_on # noqa: F401
from .dynamic import dynamic_off, dynamic_on # noqa: F401
from .live import live_off, live_on # noqa: F401
from .permission import permission_off, permission_on # noqa: F401
from .pusher import dynamic_pusher, live_pusher # noqa: F401
from .sub import add_sub, delete_sub, sub_list # noqa: F401
1 change: 0 additions & 1 deletion haruka_bot/plugins/at/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import at_off, at_on # noqa: F401
11 changes: 9 additions & 2 deletions haruka_bot/plugins/at/at_off.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Union

from nonebot import on_command
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.params import ArgPlainText
Expand All @@ -9,7 +8,15 @@

from ... import config
from ...database import DB as db
from ...utils import GUILD_ADMIN, get_type_id, group_only, handle_uid, to_me, uid_check
from ...utils import (
GUILD_ADMIN,
get_type_id,
group_only,
handle_uid,
on_command,
to_me,
uid_check,
)

at_off = on_command(
"关闭全体",
Expand Down
11 changes: 9 additions & 2 deletions haruka_bot/plugins/at/at_on.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Union

from nonebot import on_command
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.params import ArgPlainText
Expand All @@ -9,7 +8,15 @@

from ... import config
from ...database import DB as db
from ...utils import GUILD_ADMIN, get_type_id, group_only, handle_uid, to_me, uid_check
from ...utils import (
GUILD_ADMIN,
get_type_id,
group_only,
handle_uid,
on_command,
to_me,
uid_check,
)

at_on = on_command(
"开启全体",
Expand Down
1 change: 0 additions & 1 deletion haruka_bot/plugins/dynamic/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import dynamic_on, dynamic_off # noqa: F401
10 changes: 8 additions & 2 deletions haruka_bot/plugins/dynamic/dynamic_off.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText

from ...database import DB as db
from ...utils import get_type_id, handle_uid, permission_check, to_me, uid_check
from ...utils import (
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
)

dynamic_off = on_command("关闭动态", rule=to_me(), priority=5)
dynamic_off.__doc__ = """关闭动态 UID"""
Expand Down
10 changes: 8 additions & 2 deletions haruka_bot/plugins/dynamic/dynamic_on.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText

from ...database import DB as db
from ...utils import get_type_id, handle_uid, permission_check, to_me, uid_check
from ...utils import (
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
)

dynamic_on = on_command("开启动态", rule=to_me(), priority=5)
dynamic_on.__doc__ = """开启动态 UID"""
Expand Down
3 changes: 1 addition & 2 deletions haruka_bot/plugins/help.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from nonebot import on_command
from nonebot.matcher import matchers

from ..utils import to_me
from ..utils import on_command, to_me
from ..version import __version__

help = on_command("帮助", rule=to_me(), priority=5)
Expand Down
1 change: 0 additions & 1 deletion haruka_bot/plugins/live/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import live_off, live_on # noqa: F401
10 changes: 8 additions & 2 deletions haruka_bot/plugins/live/live_off.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText

from ...database import DB as db
from ...utils import get_type_id, handle_uid, permission_check, to_me, uid_check
from ...utils import (
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
)

live_off = on_command("关闭直播", rule=to_me(), priority=5)
live_off.__doc__ = """关闭直播 UID"""
Expand Down
10 changes: 8 additions & 2 deletions haruka_bot/plugins/live/live_on.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText

from ...database import DB as db
from ...utils import get_type_id, handle_uid, permission_check, to_me, uid_check
from ...utils import (
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
)

live_on = on_command("开启直播", rule=to_me(), priority=5)
live_on.__doc__ = """开启直播 UID"""
Expand Down
1 change: 0 additions & 1 deletion haruka_bot/plugins/permission/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import permission_off, permission_on # noqa
3 changes: 1 addition & 2 deletions haruka_bot/plugins/permission/permission_off.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Union

from nonebot import on_command
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.permission import SUPERUSER
from nonebot_plugin_guild_patch import GuildMessageEvent

from ...database import DB as db
from ...utils import GUILD_ADMIN, group_only, to_me
from ...utils import GUILD_ADMIN, group_only, on_command, to_me

permission_off = on_command(
"关闭权限",
Expand Down
3 changes: 1 addition & 2 deletions haruka_bot/plugins/permission/permission_on.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Union

from nonebot import on_command
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.permission import SUPERUSER
from nonebot_plugin_guild_patch import GuildMessageEvent

from ...database import DB as db
from ...utils import GUILD_ADMIN, group_only, to_me
from ...utils import GUILD_ADMIN, group_only, on_command, to_me

permission_on = on_command(
"开启权限",
Expand Down
2 changes: 1 addition & 1 deletion haruka_bot/plugins/pusher/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import dynamic_pusher, live_pusher # noqa: F401
# from . import dynamic_pusher, live_pusher # noqa: F401
4 changes: 3 additions & 1 deletion haruka_bot/plugins/pusher/live_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
status = {}


@scheduler.scheduled_job("interval", seconds=config.haruka_live_interval, id="live_sched")
@scheduler.scheduled_job(
"interval", seconds=config.haruka_live_interval, id="live_sched"
)
async def live_sched():
"""直播推送"""
uids = await db.get_uid_list("live")
Expand Down
1 change: 0 additions & 1 deletion haruka_bot/plugins/sub/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import add_sub, delete_sub, sub_list # noqa: F401
2 changes: 1 addition & 1 deletion haruka_bot/plugins/sub/add_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from bilireq.exceptions import ResponseCodeError
from bilireq.user import get_user_info
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText
from nonebot_plugin_guild_patch import GuildMessageEvent
Expand All @@ -10,6 +9,7 @@
PROXIES,
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
Expand Down
10 changes: 8 additions & 2 deletions haruka_bot/plugins/sub/delete_sub.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11.event import MessageEvent
from nonebot.params import ArgPlainText

from ...database import DB as db
from ...utils import get_type_id, handle_uid, permission_check, to_me, uid_check
from ...utils import (
get_type_id,
handle_uid,
on_command,
permission_check,
to_me,
uid_check,
)

delete_sub = on_command("取关", aliases={"删除主播"}, rule=to_me(), priority=5)
delete_sub.__doc__ = """取关 UID"""
Expand Down
Loading

0 comments on commit 8c4fb62

Please sign in to comment.