mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2025-05-23 14:11:17 +00:00
👽 适配chatrecorder 0.7.0
This commit is contained in:
parent
aff02f2666
commit
0d4f69356a
@ -10,46 +10,37 @@ require("nonebot_plugin_cesaa")
|
||||
|
||||
import re
|
||||
import time as t
|
||||
import nonebot_plugin_saa as saa
|
||||
|
||||
from typing import Union, Optional
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, Union
|
||||
|
||||
import nonebot_plugin_saa as saa
|
||||
from arclet.alconna import ArparmaBehavior
|
||||
from arclet.alconna.arparma import Arparma
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.params import Arg, Depends
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.log import logger
|
||||
from nonebot.params import Arg, Depends
|
||||
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
|
||||
from nonebot_plugin_alconna import (
|
||||
At,
|
||||
Args,
|
||||
Field,
|
||||
Match,
|
||||
Option,
|
||||
Alconna,
|
||||
on_alconna,
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_alconna import Alconna, Args, At, Field, Match, Option, on_alconna
|
||||
from nonebot_plugin_chatrecorder import get_message_records
|
||||
from nonebot_plugin_session import Session, SessionIdType, extract_session
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
from nonebot_plugin_session import SessionIdType, extract_session
|
||||
from nonebot_plugin_uninfo import Session, Uninfo, get_session
|
||||
|
||||
from .storage import get_cache, build_cache
|
||||
from .config import Config, plugin_config
|
||||
from .usage import __usage__
|
||||
from .storage import build_cache, get_cache
|
||||
from .time import (
|
||||
get_datetime_fromisoformat_with_timezone,
|
||||
get_datetime_now_with_timezone,
|
||||
parse_datetime,
|
||||
)
|
||||
from .usage import __usage__
|
||||
from .utils import (
|
||||
get_rank_image,
|
||||
get_user_infos,
|
||||
got_rank,
|
||||
msg_counter,
|
||||
get_rank_image,
|
||||
persist_id2user_id,
|
||||
get_user_infos,
|
||||
)
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
@ -59,7 +50,9 @@ __plugin_meta__ = PluginMetadata(
|
||||
homepage="https://github.com/ChenXu233/nonebot_plugin_dialectlist",
|
||||
type="application",
|
||||
supported_adapters=inherit_supported_adapters(
|
||||
"nonebot_plugin_chatrecorder", "nonebot_plugin_saa", "nonebot_plugin_alconna"
|
||||
"nonebot_plugin_chatrecorder",
|
||||
"nonebot_plugin_saa",
|
||||
"nonebot_plugin_alconna",
|
||||
),
|
||||
config=Config,
|
||||
)
|
||||
@ -108,7 +101,7 @@ async def handle_b_cmd(
|
||||
group_id: Match[str],
|
||||
keyword: Match[str],
|
||||
uninfo: Uninfo,
|
||||
session: Session = Depends(extract_session),
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
id = at.result
|
||||
if isinstance(id, At):
|
||||
@ -116,7 +109,7 @@ async def handle_b_cmd(
|
||||
if group_id.available:
|
||||
gid = group_id.result
|
||||
else:
|
||||
gid = session.id2
|
||||
gid = session.scene.id
|
||||
|
||||
if not gid:
|
||||
await b_cmd.finish("请指定群号。")
|
||||
@ -126,14 +119,13 @@ async def handle_b_cmd(
|
||||
else:
|
||||
keywords = None
|
||||
|
||||
messages = await get_message_records(scene_ids=[gid], user_ids=[id])
|
||||
|
||||
messages = await get_message_records(
|
||||
id1s=[id],
|
||||
id2s=[gid],
|
||||
id_type=SessionIdType.GROUP,
|
||||
include_bot_id=False,
|
||||
include_bot_type=False,
|
||||
scene_ids=[gid],
|
||||
user_ids=[id],
|
||||
types=["message"], # 排除机器人自己发的消息
|
||||
exclude_id1s=plugin_config.excluded_people,
|
||||
exclude_user_ids=plugin_config.excluded_people,
|
||||
)
|
||||
d = msg_counter(messages, keywords)
|
||||
rank = got_rank(d)
|
||||
@ -150,7 +142,10 @@ async def handle_b_cmd(
|
||||
rank_cmd = on_alconna(
|
||||
Alconna(
|
||||
"B话榜",
|
||||
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
||||
Args[
|
||||
"type?",
|
||||
["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"],
|
||||
][
|
||||
"time?",
|
||||
str,
|
||||
],
|
||||
@ -199,7 +194,7 @@ async def _group_message(
|
||||
dt = get_datetime_now_with_timezone()
|
||||
|
||||
if not group_id:
|
||||
group_id = session.id2
|
||||
group_id = session.scene.id
|
||||
logger.debug(f"session id2: {group_id}")
|
||||
if group_id:
|
||||
state["group_id"] = group_id
|
||||
@ -281,12 +276,11 @@ async def handle_rank(
|
||||
start: datetime = Arg(),
|
||||
stop: datetime = Arg(),
|
||||
):
|
||||
|
||||
if id := state["group_id"]:
|
||||
id = str(id)
|
||||
logger.debug(f"group_id: {id}")
|
||||
else:
|
||||
id = session.id2
|
||||
id = session.scene.id
|
||||
logger.debug(f"group_id: {id}")
|
||||
|
||||
if not id:
|
||||
@ -303,14 +297,11 @@ async def handle_rank(
|
||||
else:
|
||||
t1 = t.time()
|
||||
messages = await get_message_records(
|
||||
id2s=[id],
|
||||
id_type=SessionIdType.GROUP,
|
||||
include_bot_id=False,
|
||||
include_bot_type=False,
|
||||
scene_ids=[id],
|
||||
types=["message"], # 排除机器人自己发的消息
|
||||
time_start=start,
|
||||
time_stop=stop,
|
||||
exclude_id1s=plugin_config.excluded_people,
|
||||
exclude_user_ids=plugin_config.excluded_people,
|
||||
)
|
||||
raw_rank = msg_counter(messages, keyword)
|
||||
logger.debug(f"获取计数消息花费时间:{t.time() - t1}")
|
||||
@ -332,7 +323,6 @@ async def handle_rank(
|
||||
|
||||
string: str = ""
|
||||
if plugin_config.show_text_rank:
|
||||
|
||||
if keyword:
|
||||
string += f"关于{keyword}的话痨榜结果:\n"
|
||||
else:
|
||||
|
@ -1,6 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, List
|
||||
from typing import List, Optional
|
||||
|
||||
from nonebot import get_driver, get_plugin_config
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ScopedConfig(BaseModel):
|
||||
|
@ -0,0 +1,78 @@
|
||||
"""init dialectlist
|
||||
|
||||
迁移 ID: 506cbd6bf1ec
|
||||
父迁移: f7a853b48636
|
||||
创建时间: 2025-04-20 08:35:53.637761
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "506cbd6bf1ec"
|
||||
down_revision: str | Sequence[str] | None = "f7a853b48636"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade(name: str = "") -> None:
|
||||
if name:
|
||||
return
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"nonebot_plugin_dialectlist_messagecountcache",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("time", sa.DateTime(), nullable=False),
|
||||
sa.Column("session_id", sa.Integer(), nullable=False),
|
||||
sa.Column("session_bnum", sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"id", name=op.f("pk_nonebot_plugin_dialectlist_messagecountcache")
|
||||
),
|
||||
info={"bind_key": "nonebot_plugin_dialectlist"},
|
||||
)
|
||||
with op.batch_alter_table(
|
||||
"nonebot_plugin_dialectlist_messagecountcache", schema=None
|
||||
) as batch_op:
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_nonebot_plugin_dialectlist_messagecountcache_session_id"),
|
||||
["session_id"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("model_messagecountcache", schema=None) as batch_op:
|
||||
batch_op.drop_index("ix_model_messagecountcache_session_id")
|
||||
|
||||
op.drop_table("model_messagecountcache")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade(name: str = "") -> None:
|
||||
if name:
|
||||
return
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"model_messagecountcache",
|
||||
sa.Column("id", sa.INTEGER(), nullable=False),
|
||||
sa.Column("time", sa.DATETIME(), nullable=False),
|
||||
sa.Column("session_id", sa.INTEGER(), nullable=False),
|
||||
sa.Column("session_bnum", sa.INTEGER(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name="pk_model_messagecountcache"),
|
||||
)
|
||||
with op.batch_alter_table("model_messagecountcache", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
"ix_model_messagecountcache_session_id", ["session_id"], unique=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"nonebot_plugin_dialectlist_messagecountcache", schema=None
|
||||
) as batch_op:
|
||||
batch_op.drop_index(
|
||||
batch_op.f("ix_nonebot_plugin_dialectlist_messagecountcache_session_id")
|
||||
)
|
||||
|
||||
op.drop_table("nonebot_plugin_dialectlist_messagecountcache")
|
||||
# ### end Alembic commands ###
|
@ -1,8 +1,9 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
from sqlalchemy import Integer
|
||||
|
||||
from nonebot_plugin_orm import Model
|
||||
from nonebot_plugin_userinfo import UserInfo
|
||||
from sqlalchemy import Integer
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
|
@ -1,23 +1,22 @@
|
||||
import os
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from sqlalchemy import delete, or_, select
|
||||
|
||||
from nonebot import get_driver
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.log import logger
|
||||
from nonebot.params import Depends
|
||||
from nonebot.adapters import Event, Bot
|
||||
from nonebot.message import event_postprocessor
|
||||
|
||||
from .model import MessageCountCache
|
||||
from .config import plugin_config
|
||||
|
||||
from nonebot_plugin_localstore import get_data_file
|
||||
from nonebot.params import Depends
|
||||
from nonebot_plugin_chatrecorder import get_message_records
|
||||
from nonebot_plugin_chatrecorder.utils import remove_timezone
|
||||
from nonebot_plugin_session import extract_session, Session
|
||||
from nonebot_plugin_session_orm import SessionModel, get_session_persist_id
|
||||
from nonebot_plugin_localstore import get_data_file
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import Session, extract_session
|
||||
from nonebot_plugin_session_orm import SessionModel, get_session_persist_id
|
||||
from sqlalchemy import delete, or_, select
|
||||
|
||||
from .config import plugin_config
|
||||
from .model import MessageCountCache
|
||||
|
||||
|
||||
async def get_cache(time_start: datetime, time_stop: datetime, group_id: str):
|
||||
|
@ -1,13 +1,12 @@
|
||||
from zoneinfo import ZoneInfo
|
||||
from typing import Optional, Union
|
||||
from datetime import datetime, time, tzinfo
|
||||
from typing import Optional, Union
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import Arg
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters import Message
|
||||
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_alconna import AlconnaMatcher
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
|
||||
from .config import plugin_config
|
||||
|
||||
|
@ -1,31 +1,28 @@
|
||||
import asyncio
|
||||
import os
|
||||
import re
|
||||
import httpx
|
||||
import asyncio
|
||||
import unicodedata
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import httpx
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.compat import model_dump
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Depends
|
||||
from nonebot_plugin_chatrecorder import MessageRecord
|
||||
from nonebot_plugin_htmlrender import template_to_pic
|
||||
from nonebot_plugin_localstore import get_cache_dir
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import Session, SessionLevel, extract_session
|
||||
from nonebot_plugin_session_orm import SessionModel
|
||||
from nonebot_plugin_userinfo import UserInfo, get_user_info
|
||||
from nonebot_plugin_userinfo.exception import NetworkError
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.sql import ColumnElement
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.params import Depends
|
||||
from nonebot.compat import model_dump
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Bot, Event
|
||||
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import Session, SessionLevel, extract_session
|
||||
from nonebot_plugin_userinfo import get_user_info, UserInfo
|
||||
from nonebot_plugin_userinfo.exception import NetworkError
|
||||
from nonebot_plugin_localstore import get_cache_dir
|
||||
from nonebot_plugin_htmlrender import template_to_pic
|
||||
from nonebot_plugin_session_orm import SessionModel
|
||||
from nonebot_plugin_chatrecorder import MessageRecord
|
||||
|
||||
|
||||
from .model import UserRankInfo
|
||||
from .config import plugin_config
|
||||
from .model import UserRankInfo
|
||||
|
||||
cache_path = get_cache_dir("nonebot_plugin_dialectlist")
|
||||
|
||||
@ -40,7 +37,11 @@ async def persist_id2user_id(ids: List) -> List[str]:
|
||||
user_ids = []
|
||||
async with get_session() as db_session:
|
||||
for i in ids:
|
||||
user_id = (await db_session.scalar(select(SessionModel).where(or_(*[SessionModel.id == i])))).id1 # type: ignore
|
||||
user_id = (
|
||||
await db_session.scalar(
|
||||
select(SessionModel).where(or_(*[SessionModel.id == i]))
|
||||
)
|
||||
).id1 # type: ignore
|
||||
user_ids.append(user_id)
|
||||
return user_ids
|
||||
|
||||
@ -61,7 +62,11 @@ async def group_id2persist_id(ids: List[str]) -> List[int]:
|
||||
persist_ids = []
|
||||
async with get_session() as db_session:
|
||||
for i in ids:
|
||||
persist_id = (await db_session.scalar(select(SessionModel).where(or_(*[SessionModel.id2 == i])))).id # type: ignore
|
||||
persist_id = (
|
||||
await db_session.scalar(
|
||||
select(SessionModel).where(or_(*[SessionModel.id2 == i]))
|
||||
)
|
||||
).id # type: ignore
|
||||
persist_ids.append(persist_id)
|
||||
return persist_ids
|
||||
|
||||
@ -232,7 +237,6 @@ async def get_user_infos(
|
||||
rank: List,
|
||||
use_cache: bool = plugin_config.use_user_info_cache,
|
||||
) -> List[UserRankInfo]:
|
||||
|
||||
user_ids = [i[0] for i in rank]
|
||||
pool = [get_user_info(bot, event, id, use_cache) for id in user_ids]
|
||||
user_infos = await asyncio.gather(*pool)
|
||||
@ -254,7 +258,6 @@ async def get_user_infos(
|
||||
total = sum([i[1] for i in rank])
|
||||
rank2 = []
|
||||
for i in range(len(rank)):
|
||||
|
||||
user_info = user_infos[i]
|
||||
if not user_info:
|
||||
user_info = get_default_user_info()
|
||||
|
@ -2,11 +2,9 @@
|
||||
name = "nonebot-plugin-dialectlist"
|
||||
version = "2.6.2"
|
||||
description = "看看你群群友有多能说"
|
||||
authors = [
|
||||
{name = "Chen_Xu233", email = "woyerpa@outlook.com"},
|
||||
]
|
||||
authors = [{ name = "Chen_Xu233", email = "woyerpa@outlook.com" }]
|
||||
dependencies = [
|
||||
"nonebot-plugin-chatrecorder>=0.6.0,<0.7.0",
|
||||
"nonebot-plugin-chatrecorder>=0.7.0",
|
||||
"nonebot-plugin-orm[default]",
|
||||
"nonebot-plugin-apscheduler>=0.4.0",
|
||||
"nonebot-plugin-alconna>=0.50.2",
|
||||
@ -19,7 +17,7 @@ dependencies = [
|
||||
]
|
||||
requires-python = ">=3.9,<4.0"
|
||||
readme = "README.md"
|
||||
license = {text = "MIT"}
|
||||
license = { text = "MIT" }
|
||||
|
||||
|
||||
[project.optional-dependencies]
|
||||
@ -30,9 +28,7 @@ dev = [
|
||||
"nb-cli>=0.7.6",
|
||||
"py-spy>=0.3.14",
|
||||
]
|
||||
Test = [
|
||||
"nonebot-adapter-onebot>=2.4.4",
|
||||
]
|
||||
Test = ["nonebot-adapter-onebot>=2.4.4"]
|
||||
|
||||
[tool.pdm]
|
||||
distribution = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user