mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
👷 添加ruff actions
🐛 分支应该是main而不是master 💄 auto fix by pre-commit hooks 🔥 dependabot.yml的registrys需要token,先删除
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from .platform import platform_manager
|
||||
from .scheduler import scheduler_dict
|
||||
from .types import Target
|
||||
from .scheduler import scheduler_dict
|
||||
from .platform import platform_manager
|
||||
|
||||
|
||||
async def check_sub_target(platform_name: str, target: Target):
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from nonebot.log import logger
|
||||
from nonebot_plugin_datastore.db import get_engine, post_db_init, pre_db_init
|
||||
from sqlalchemy import inspect, text
|
||||
from sqlalchemy import text, inspect
|
||||
from nonebot_plugin_datastore.db import get_engine, pre_db_init, post_db_init
|
||||
|
||||
from .config.config_legacy import start_up as legacy_db_startup
|
||||
from .config.db_migration import data_migrate
|
||||
from .scheduler.manager import init_scheduler
|
||||
from .config.config_legacy import start_up as legacy_db_startup
|
||||
|
||||
|
||||
@pre_db_init
|
||||
@@ -35,9 +35,7 @@ async def pre():
|
||||
if await conn.run_sync(_has_table, "nonebot_bison_alembic_version"):
|
||||
await conn.execute(text("drop table nonebot_bison_alembic_version"))
|
||||
|
||||
await conn.execute(
|
||||
text("alter table alembic_version rename to nonebot_bison_alembic_version")
|
||||
)
|
||||
await conn.execute(text("alter table alembic_version rename to nonebot_bison_alembic_version"))
|
||||
|
||||
|
||||
@post_db_init
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot_plugin_datastore import get_plugin_data
|
||||
from nonebot_plugin_saa.utils import PlatformTarget
|
||||
from sqlalchemy import JSON, ForeignKey, String, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from nonebot_plugin_saa.utils import PlatformTarget
|
||||
from nonebot_plugin_datastore import get_plugin_data
|
||||
from sqlalchemy.orm import Mapped, relationship, mapped_column
|
||||
from sqlalchemy import JSON, String, ForeignKey, UniqueConstraint
|
||||
|
||||
from ..types import Category, Tag
|
||||
from ..types import Tag, Category
|
||||
|
||||
Model = get_plugin_data().Model
|
||||
get_plugin_data().set_migration_dir(Path(__file__).parent / "migrations")
|
||||
@@ -25,9 +25,7 @@ class User(Model):
|
||||
|
||||
|
||||
class Target(Model):
|
||||
__table_args__ = (
|
||||
UniqueConstraint("target", "platform_name", name="unique-target-constraint"),
|
||||
)
|
||||
__table_args__ = (UniqueConstraint("target", "platform_name", name="unique-target-constraint"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
platform_name: Mapped[str] = mapped_column(String(20))
|
||||
@@ -36,9 +34,7 @@ class Target(Model):
|
||||
default_schedule_weight: Mapped[int] = mapped_column(default=10)
|
||||
|
||||
subscribes: Mapped[list["Subscribe"]] = relationship(back_populates="target")
|
||||
time_weight: Mapped[list["ScheduleTimeWeight"]] = relationship(
|
||||
back_populates="target"
|
||||
)
|
||||
time_weight: Mapped[list["ScheduleTimeWeight"]] = relationship(back_populates="target")
|
||||
|
||||
|
||||
class ScheduleTimeWeight(Model):
|
||||
@@ -55,9 +51,7 @@ class ScheduleTimeWeight(Model):
|
||||
|
||||
|
||||
class Subscribe(Model):
|
||||
__table_args__ = (
|
||||
UniqueConstraint("target_id", "user_id", name="unique-subscribe-constraint"),
|
||||
)
|
||||
__table_args__ = (UniqueConstraint("target_id", "user_id", name="unique-subscribe-constraint"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
target_id: Mapped[int] = mapped_column(ForeignKey("nonebot_bison_target.id"))
|
||||
|
||||
@@ -31,9 +31,7 @@ def upgrade():
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
with op.batch_alter_table("target", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("default_schedule_weight", sa.Integer(), nullable=True)
|
||||
)
|
||||
batch_op.add_column(sa.Column("default_schedule_weight", sa.Integer(), nullable=True))
|
||||
batch_op.drop_column("last_schedule_time")
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -42,9 +40,7 @@ def upgrade():
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("target", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("last_schedule_time", sa.DATETIME(), nullable=True)
|
||||
)
|
||||
batch_op.add_column(sa.Column("last_schedule_time", sa.DATETIME(), nullable=True))
|
||||
batch_op.drop_column("default_schedule_weight")
|
||||
|
||||
op.drop_table("schedule_time_weight")
|
||||
|
||||
@@ -18,9 +18,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("target", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("last_schedule_time", sa.DateTime(timezone=True), nullable=True)
|
||||
)
|
||||
batch_op.add_column(sa.Column("last_schedule_time", sa.DateTime(timezone=True), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ Create Date: 2023-03-20 01:14:42.623789
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "a5466912fad0"
|
||||
|
||||
@@ -17,9 +17,7 @@ depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table(
|
||||
"nonebot_bison_scheduletimeweight", schema=None
|
||||
) as batch_op:
|
||||
with op.batch_alter_table("nonebot_bison_scheduletimeweight", schema=None) as batch_op:
|
||||
batch_op.alter_column("target_id", existing_type=sa.INTEGER(), nullable=False)
|
||||
batch_op.alter_column("start_time", existing_type=sa.TIME(), nullable=False)
|
||||
batch_op.alter_column("end_time", existing_type=sa.TIME(), nullable=False)
|
||||
@@ -30,9 +28,7 @@ def upgrade() -> None:
|
||||
batch_op.alter_column("user_id", existing_type=sa.INTEGER(), nullable=False)
|
||||
|
||||
with op.batch_alter_table("nonebot_bison_target", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"default_schedule_weight", existing_type=sa.INTEGER(), nullable=False
|
||||
)
|
||||
batch_op.alter_column("default_schedule_weight", existing_type=sa.INTEGER(), nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
@@ -40,17 +36,13 @@ def upgrade() -> None:
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("nonebot_bison_target", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"default_schedule_weight", existing_type=sa.INTEGER(), nullable=True
|
||||
)
|
||||
batch_op.alter_column("default_schedule_weight", existing_type=sa.INTEGER(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("nonebot_bison_subscribe", schema=None) as batch_op:
|
||||
batch_op.alter_column("user_id", existing_type=sa.INTEGER(), nullable=True)
|
||||
batch_op.alter_column("target_id", existing_type=sa.INTEGER(), nullable=True)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"nonebot_bison_scheduletimeweight", schema=None
|
||||
) as batch_op:
|
||||
with op.batch_alter_table("nonebot_bison_scheduletimeweight", schema=None) as batch_op:
|
||||
batch_op.alter_column("weight", existing_type=sa.INTEGER(), nullable=True)
|
||||
batch_op.alter_column("end_time", existing_type=sa.TIME(), nullable=True)
|
||||
batch_op.alter_column("start_time", existing_type=sa.TIME(), nullable=True)
|
||||
|
||||
@@ -8,8 +8,8 @@ Create Date: 2023-03-02 14:04:16.492133
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "bd92923c218f"
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
""" nbesf is Nonebot Bison Enchangable Subscribes File! ver.1"""
|
||||
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
from functools import partial
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot_plugin_saa import TargetQQGroup, TargetQQPrivate
|
||||
from pydantic import BaseModel
|
||||
from nonebot_plugin_saa import TargetQQGroup, TargetQQPrivate
|
||||
|
||||
from ....types import Category, Tag
|
||||
from ...db_config import SubscribeDupException, config
|
||||
from ..utils import NBESFParseErr
|
||||
from ....types import Tag, Category
|
||||
from .base import NBESFBase, SubReceipt
|
||||
from ...db_config import SubscribeDupException, config
|
||||
|
||||
# ===== nbesf 定义格式 ====== #
|
||||
NBESF_VERSION = 1
|
||||
@@ -65,7 +65,6 @@ class SubGroup(
|
||||
|
||||
async def subs_receipt_gen(nbesf_data: SubGroup):
|
||||
for item in nbesf_data.groups:
|
||||
|
||||
match item.user.type:
|
||||
case "group":
|
||||
user = TargetQQGroup(group_id=item.user.uid)
|
||||
@@ -85,9 +84,7 @@ async def subs_receipt_gen(nbesf_data: SubGroup):
|
||||
tags=sub.tags,
|
||||
)
|
||||
try:
|
||||
await config.add_subscribe(
|
||||
receipt.user, **receipt.dict(exclude={"user"})
|
||||
)
|
||||
await config.add_subscribe(receipt.user, **receipt.dict(exclude={"user"}))
|
||||
except SubscribeDupException:
|
||||
logger.warning(f"!添加订阅条目 {repr(receipt)} 失败: 相同的订阅已存在")
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
""" nbesf is Nonebot Bison Enchangable Subscribes File! ver.2"""
|
||||
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
from functools import partial
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot_plugin_saa.utils import AllSupportedPlatformTarget
|
||||
from pydantic import BaseModel
|
||||
from nonebot_plugin_saa.utils import AllSupportedPlatformTarget
|
||||
|
||||
from ....types import Category, Tag
|
||||
from ...db_config import SubscribeDupException, config
|
||||
from ..utils import NBESFParseErr
|
||||
from ....types import Tag, Category
|
||||
from .base import NBESFBase, SubReceipt
|
||||
from ...db_config import SubscribeDupException, config
|
||||
|
||||
# ===== nbesf 定义格式 ====== #
|
||||
NBESF_VERSION = 2
|
||||
@@ -57,7 +57,6 @@ class SubGroup(NBESFBase):
|
||||
|
||||
async def subs_receipt_gen(nbesf_data: SubGroup):
|
||||
for item in nbesf_data.groups:
|
||||
|
||||
sub_receipt = partial(SubReceipt, user=item.user_target)
|
||||
|
||||
for sub in item.subs:
|
||||
@@ -69,9 +68,7 @@ async def subs_receipt_gen(nbesf_data: SubGroup):
|
||||
tags=sub.tags,
|
||||
)
|
||||
try:
|
||||
await config.add_subscribe(
|
||||
receipt.user, **receipt.dict(exclude={"user"})
|
||||
)
|
||||
await config.add_subscribe(receipt.user, **receipt.dict(exclude={"user"}))
|
||||
except SubscribeDupException:
|
||||
logger.warning(f"!添加订阅条目 {repr(receipt)} 失败: 相同的订阅已存在")
|
||||
except Exception as e:
|
||||
|
||||
@@ -2,25 +2,19 @@ import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.rule import Rule, to_me
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
from nonebot.params import ArgStr, ArgPlainText
|
||||
from nonebot.adapters import Bot, MessageTemplate
|
||||
from nonebot.adapters.onebot.v11.event import PrivateMessageEvent
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import ArgPlainText, ArgStr
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.rule import Rule, to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from .add_sub import do_add_sub
|
||||
from .del_sub import do_del_sub
|
||||
from .query_sub import do_query_sub
|
||||
from .utils import (
|
||||
admin_permission,
|
||||
common_platform,
|
||||
configurable_to_me,
|
||||
gen_handle_cancel,
|
||||
set_target_user_info,
|
||||
)
|
||||
from .utils import common_platform, admin_permission, gen_handle_cancel, configurable_to_me, set_target_user_info
|
||||
|
||||
add_sub_matcher = on_command(
|
||||
"添加订阅",
|
||||
@@ -48,9 +42,7 @@ del_sub_matcher = on_command(
|
||||
del_sub_matcher.handle()(set_target_user_info)
|
||||
do_del_sub(del_sub_matcher)
|
||||
|
||||
group_manage_matcher = on_command(
|
||||
"群管理", rule=to_me(), permission=SUPERUSER, priority=4, block=True
|
||||
)
|
||||
group_manage_matcher = on_command("群管理", rule=to_me(), permission=SUPERUSER, priority=4, block=True)
|
||||
|
||||
group_handle_cancel = gen_handle_cancel(group_manage_matcher, "已取消")
|
||||
|
||||
@@ -69,12 +61,8 @@ async def send_group_list(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
state["group_number_idx"] = group_number_idx
|
||||
|
||||
|
||||
@group_manage_matcher.got(
|
||||
"group_idx", MessageTemplate("{_prompt}"), [group_handle_cancel]
|
||||
)
|
||||
async def do_choose_group_number(
|
||||
state: T_State, event: PrivateMessageEvent, group_idx: str = ArgPlainText()
|
||||
):
|
||||
@group_manage_matcher.got("group_idx", MessageTemplate("{_prompt}"), [group_handle_cancel])
|
||||
async def do_choose_group_number(state: T_State, event: PrivateMessageEvent, group_idx: str = ArgPlainText()):
|
||||
group_number_idx: dict[int, int] = state["group_number_idx"]
|
||||
assert group_number_idx
|
||||
idx = int(group_idx)
|
||||
@@ -87,9 +75,7 @@ async def do_choose_group_number(
|
||||
state["target_user_info"] = TargetQQGroup(group_id=group_id)
|
||||
|
||||
|
||||
@group_manage_matcher.got(
|
||||
"command", "请输入需要使用的命令:添加订阅,查询订阅,删除订阅,取消", [group_handle_cancel]
|
||||
)
|
||||
@group_manage_matcher.got("command", "请输入需要使用的命令:添加订阅,查询订阅,删除订阅,取消", [group_handle_cancel])
|
||||
async def do_dispatch_command(
|
||||
bot: Bot,
|
||||
event: PrivateMessageEvent,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from dataclasses import dataclass
|
||||
from datetime import time
|
||||
from typing import Any, Literal, NamedTuple, NewType
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Literal, NewType, NamedTuple
|
||||
|
||||
from httpx import URL
|
||||
from nonebot_plugin_saa import PlatformTarget as SendTarget
|
||||
from pydantic import BaseModel
|
||||
from nonebot_plugin_saa import PlatformTarget as SendTarget
|
||||
|
||||
RawPost = Any
|
||||
Target = NewType("Target", str)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
""" 提供获取 Bot 的方法 """
|
||||
from collections import defaultdict
|
||||
from typing import Any
|
||||
from collections import defaultdict
|
||||
|
||||
import nonebot
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.onebot.v11 import Bot as Ob11Bot
|
||||
from nonebot_plugin_saa import PlatformTarget
|
||||
from nonebot.adapters.onebot.v11 import Bot as Ob11Bot
|
||||
|
||||
GROUP: dict[int, list[Bot]] = {}
|
||||
USER: dict[int, list[Bot]] = {}
|
||||
@@ -28,12 +28,6 @@ async def get_groups() -> list[dict[str, Any]]:
|
||||
all_groups: dict[int, dict[str, Any]] = {}
|
||||
for bot in get_bots():
|
||||
groups = await bot.get_group_list()
|
||||
all_groups.update(
|
||||
{
|
||||
group["group_id"]: group
|
||||
for group in groups
|
||||
if group["group_id"] not in all_groups
|
||||
}
|
||||
)
|
||||
all_groups.update({group["group_id"]: group for group in groups if group["group_id"] not in all_groups})
|
||||
|
||||
return list(all_groups.values())
|
||||
|
||||
Reference in New Issue
Block a user