Skip to content

Commit

Permalink
Merge pull request #50 from Skyminers/dev_cypas
Browse files Browse the repository at this point in the history
Dev cypas
  • Loading branch information
Cypas authored Aug 14, 2023
2 parents 1cfffec + 5e8d3c7 commit fbcbfc5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
/nonebot_plugin_splatoon3.egg-info/
/setup.py
MANIFEST.in
/venv/
/poetry.lock
25 changes: 19 additions & 6 deletions nonebot_plugin_splatoon3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
from nonebot.adapters.telegram.event import GroupMessageEvent as Tg_GME
from nonebot.adapters.telegram.event import ChannelPostEvent as Tg_CME

# kook协议
from nonebot.adapters.kaiheila import Bot as Kook_Bot
from nonebot.adapters.kaiheila.event import MessageEvent as Kook_ME
from nonebot.adapters.kaiheila import MessageSegment as Kook_MsgSeg
from nonebot.adapters.kaiheila.event import PrivateMessageEvent as Kook_PME
from nonebot.adapters.kaiheila.event import ChannelMessageEvent as Kook_CME

from .image.image import *
from .image import image_to_base64
from .config import plugin_config, driver
Expand All @@ -49,8 +56,8 @@
supported_adapters={"~onebot.v11", "~onebot.v12", "~telegram"},
)

BOT = Union[V11_Bot, V12_Bot, Tg_Bot]
MESSAGE_EVENT = Union[V11_ME, V12_ME, Tg_ME]
BOT = Union[V11_Bot, V12_Bot, Tg_Bot, Kook_Bot]
MESSAGE_EVENT = Union[V11_ME, V12_ME, Tg_ME, Kook_ME]


async def _permission_check(bot: BOT, event: MESSAGE_EVENT, state: T_State):
Expand All @@ -59,11 +66,11 @@ async def _permission_check(bot: BOT, event: MESSAGE_EVENT, state: T_State):
uid: Union[int, str] = 114514
gid: Union[int, str] = 114514
cid: Union[int, str] = 114514
if isinstance(event, (V11_PME, V12_PME, Tg_PME)):
if isinstance(event, (V11_PME, V12_PME, Tg_PME, Kook_PME)):
if plugin_config.splatoon3_permit_private:
if isinstance(event, Tg_PME):
uid = event.from_.id
elif isinstance(event, (V11_PME, V12_PME)):
elif isinstance(event, (V11_PME, V12_PME, Kook_PME)):
uid = event.user_id
state["_uid_"] = uid
return plugin_config.verify_permission(uid)
Expand All @@ -85,14 +92,17 @@ async def _permission_check(bot: BOT, event: MESSAGE_EVENT, state: T_State):
return False

# 频道
elif isinstance(event, (V12_CME, Tg_CME)):
elif isinstance(event, (V12_CME, Tg_CME, Kook_CME)):
if plugin_config.splatoon3_permit_channel:
if isinstance(event, Tg_CME):
cid = event.chat.id
uid = event.get_user_id()
elif isinstance(event, V12_CME):
cid = event.channel_id
uid = event.user_id
elif isinstance(event, Kook_CME):
cid = event.group_id
uid = event.user_id
state["_cid_"] = cid
if plugin_config.verify_permission(cid):
# 再判断触发者是否有权限
Expand Down Expand Up @@ -401,7 +411,7 @@ async def send_msg(bot: BOT, event: MESSAGE_EVENT, matcher, msg):
await bot.send(event, msg)


async def send_img(bot: BOT, event: MESSAGE_EVENT, matcher, img):
async def send_img(bot: BOT, event: MESSAGE_EVENT, matcher, img: bytes):
"""公用send_img"""
# 指定回复模式
reply_mode = plugin_config.splatoon3_reply_mode
Expand All @@ -424,6 +434,9 @@ async def send_img(bot: BOT, event: MESSAGE_EVENT, matcher, img):
await bot.send(event, File.photo(img), reply_to_message_id=event.dict().get("message_id"))
else:
await bot.send(event, File.photo(img))
elif isinstance(bot, Kook_Bot):
url = await bot.upload_file(img)
await bot.send(event, Kook_MsgSeg.image(url), reply_sender=reply_mode)


@driver.on_startup
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_splatoon3/data/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_weapon_image_info(sch): # sch为schedule[idx]
# for _i in range(4) 是循环执行4次,不是多余的代码
return [
ImageInfo(
name=sch["setting"]["weapons"][_i]["name"],
name=sch["setting"]["weapons"][_i]["name"] + "_" + sch["setting"]["weapons"][_i]["__splatoon3ink_id"],
url=sch["setting"]["weapons"][_i]["image"]["url"],
zh_name=get_trans_weapon(sch["setting"]["weapons"][_i]["__splatoon3ink_id"]),
source_type="武器",
Expand Down
Binary file modified nonebot_plugin_splatoon3/data/db/image.db
Binary file not shown.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "nonebot-plugin-splatoon3"
version = "1.2.4"
version = "1.2.5"
description = "一个基于nonebot2框架的splatoon3游戏日程查询插件"
authors = ["cypas <[email protected]>"]
readme = "README.md"
packages = [{include = "nonebot_plugin_splatoon3"}]

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
beautifulsoup4="^4.12.2"
cfscrape="^2.1.1"
httpx="^0.24.1"
Expand All @@ -18,6 +18,7 @@ urllib3="1.26.16"
requests="^2.28.2"
nonebot-adapter-onebot = "^2.1.3"
nonebot-adapter-telegram= "^0.1.0b14"
nonebot-adapter-kaiheila = "^0.2.8"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit fbcbfc5

Please sign in to comment.