Skip to content

Commit

Permalink
format_platform
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed Sep 7, 2024
1 parent 66600cc commit 180d80c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
11 changes: 3 additions & 8 deletions nonebot_plugin_chatrecorder/adapters/onebot_v12.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing_extensions import override

from ..config import plugin_config
from ..consts import SupportedAdapter, SupportedPlatform
from ..consts import SupportedAdapter
from ..message import (
MessageDeserializer,
MessageSerializer,
Expand All @@ -18,6 +18,7 @@
serialize_message,
)
from ..model import MessageRecord
from ..utils import format_platform

try:
from nonebot.adapters.onebot.v12 import Bot, Message, MessageEvent
Expand Down Expand Up @@ -67,16 +68,10 @@ async def record_send_msg(
elif detail_type == "private":
level = SessionLevel.LEVEL1

platform = bot.platform
if platform in ("kook",):
platform = SupportedPlatform.kaiheila
elif platform not in list(SupportedPlatform):
platform = SupportedPlatform.unknown

session = Session(
bot_id=bot.self_id,
bot_type=bot.type,
platform=bot.platform,
platform=format_platform(bot.platform),
level=level,
id1=data.get("user_id"),
id2=data.get("group_id") or data.get("channel_id"),
Expand Down
14 changes: 3 additions & 11 deletions nonebot_plugin_chatrecorder/adapters/satori.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing_extensions import override

from ..config import plugin_config
from ..consts import SupportedAdapter, SupportedPlatform
from ..consts import SupportedAdapter
from ..message import (
MessageDeserializer,
MessageSerializer,
Expand All @@ -18,7 +18,7 @@
serialize_message,
)
from ..model import MessageRecord
from ..utils import remove_timezone
from ..utils import format_platform, remove_timezone

try:
from nonebot.adapters.satori import Bot, Message, MessageEvent
Expand Down Expand Up @@ -76,18 +76,10 @@ async def record_send_msg(
id2 = result_message.channel.id if result_message.channel else None
id3 = result_message.guild.id if result_message.guild else None

platform = bot.platform
if platform in ("onebot", "red", "chronocat"):
platform = SupportedPlatform.qq
elif platform in ("kook",):
platform = SupportedPlatform.kaiheila
elif platform not in list(SupportedPlatform):
platform = SupportedPlatform.unknown

session = Session(
bot_id=bot.self_id,
bot_type=bot.type,
platform=platform,
platform=format_platform(bot.platform),
level=level,
id1=id1,
id2=id2,
Expand Down
12 changes: 12 additions & 0 deletions nonebot_plugin_chatrecorder/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime, timezone

from .consts import SupportedPlatform


def remove_timezone(dt: datetime) -> datetime:
"""移除时区"""
Expand All @@ -8,3 +10,13 @@ def remove_timezone(dt: datetime) -> datetime:
# 先转至 UTC 时间,再移除时区
dt = dt.astimezone(timezone.utc)
return dt.replace(tzinfo=None)


def format_platform(platform: str) -> str:
if platform in ("onebot", "red", "chronocat"):
return SupportedPlatform.qq
elif platform in ("kook",):
return SupportedPlatform.kaiheila
elif platform not in list(SupportedPlatform):
return SupportedPlatform.unknown
return platform

0 comments on commit 180d80c

Please sign in to comment.