Skip to content

Commit

Permalink
Merge pull request #11 from MinatoAquaCrews/dev
Browse files Browse the repository at this point in the history
v0.1.5
  • Loading branch information
KafCoppelia authored Dec 19, 2022
2 parents 4de0719 + a622bfc commit 69db257
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 378 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ _🎶 随机唐可可 🎶_
</a>

<a href="https://github.com/nonebot/nonebot2">
<img src="https://img.shields.io/badge/nonebot2-2.0.0beta.3+-green">
<img src="https://img.shields.io/badge/nonebot2-2.0.0b3+-green">
</a>

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_randomtkk/releases/tag/v0.1.4">
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_randomtkk/releases/tag/v0.1.5">
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_randomtkk?color=orange">
</a>

Expand All @@ -31,11 +31,11 @@ _🎶 随机唐可可 🎶_

## 版本

v0.1.4
v0.1.5

⚠ 适配nonebot2-2.0.0b3+

[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_randomtkk/releases/tag/v0.1.4)
[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_randomtkk/releases/tag/v0.1.5)

## 安装

Expand Down Expand Up @@ -68,7 +68,7 @@ v0.1.4

## 功能

寻找LoveLive角色!(主要是唐可可)
寻找LoveLive的成员!

## 命令

Expand Down
26 changes: 19 additions & 7 deletions nonebot_plugin_randomtkk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
from nonebot import on_command, on_regex
from typing import List
from typing import List, Union
from nonebot.plugin import PluginMetadata
from nonebot.matcher import Matcher
from nonebot.adapters.onebot.v11 import Message, MessageSegment, MessageEvent, GroupMessageEvent
from nonebot.params import Depends, CommandArg, RegexMatched
from nonebot.rule import Rule
from .config import find_charac
from .handler import random_tkk_handler

__randomtkk_version__ = "v0.1.4"
__randomtkk_notes__ = f'''
__randomtkk_version__ = "v0.1.5"
__randomtkk_usages__ = f'''
随机唐可可 {__randomtkk_version__}
[随机唐可可]+[简单/普通/困难/地狱/自定义数量] 开启寻找唐可可挑战
不指定难度则默认普通
答案格式:[答案是][行][空格][列],例如:答案是114 514
[找不到唐可可] 发起者可提前结束游戏
将[唐可可]替换成其他角色可以寻找她们!'''.strip()

__plugin_meta__ = PluginMetadata(
name="随机唐可可",
description="找到唐可可!",
usage=__randomtkk_usages__,
extra={
"author": "KafCoppelia <[email protected]>",
"version": __randomtkk_version__
}
)

def inplaying_check(event: MessageEvent) -> bool:
uuid: str = str(event.group_id) if isinstance(event, GroupMessageEvent) else str(event.user_id)
return random_tkk_handler.check_tkk_playing(uuid)
Expand All @@ -26,8 +37,9 @@ def unplaying_check(event: MessageEvent) -> bool:

def starter_check(event: MessageEvent) -> bool:
uid: str = str(event.user_id)
gid = str(event.group_id) if isinstance(event, GroupMessageEvent) else None
return random_tkk_handler.check_starter(gid, uid)
gid: Union[str, None] = str(event.group_id) if isinstance(event, GroupMessageEvent) else None

return random_tkk_handler.check_starter(uid, gid)

def characs_check(event: MessageEvent) -> bool:
_charac: str = event.get_message().extract_plain_text()[2:]
Expand Down Expand Up @@ -63,7 +75,7 @@ async def _(matcher: Matcher, event: MessageEvent, matched: str = RegexMatched()
level = "普通"
elif len(args) == 2:
if args[1] == "帮助":
await matcher.finish(__randomtkk_notes__)
await matcher.finish(__randomtkk_usages__)
else:
level = args[1]
else:
Expand All @@ -82,7 +94,7 @@ async def _(matcher: Matcher, event: MessageEvent, matched: str = RegexMatched()
@random_tkk_default.handle()
async def _(matcher: Matcher, event: MessageEvent, matched: str = RegexMatched()):
if matched[-2:] == "帮助":
await matcher.finish(__randomtkk_notes__)
await matcher.finish(__randomtkk_usages__)

uid: str = str(event.user_id)
gid: str = ""
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_randomtkk/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pydantic import BaseModel, Extra
from typing import Union, Dict, List
from pathlib import Path
from nonebot import get_driver
from nonebot.log import logger
import httpx
import aiofiles
from nonebot import get_driver
from nonebot.log import logger

class RandomTkkConfig(BaseModel, extra=Extra.ignore):

Expand Down
29 changes: 17 additions & 12 deletions nonebot_plugin_randomtkk/handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Tuple, List, Dict, Union, Optional
from PIL import Image, ImageFont, ImageDraw
from io import BytesIO
from nonebot.matcher import Matcher
from nonebot.adapters.onebot.v11 import Message, MessageSegment
import random
import asyncio
from nonebot.matcher import Matcher
from nonebot.adapters.onebot.v11 import Message, MessageSegment
from .config import tkk_config, find_charac, other_characs_list

class RandomTkkHandler:
Expand All @@ -31,21 +31,24 @@ def _config_tkk_size(self, level: str) -> int:
tkk_size = int(level) if int(level) <= self.tkk_config.max_size else self.tkk_config.normal_size
if tkk_size < self.tkk_config.easy_size:
tkk_size = self.tkk_config.easy_size

return tkk_size

except ValueError:
return self.tkk_config.easy_size

def _get_tkk_position(self, tkk_size: int) -> Tuple[int, int]:
'''
生成唐可可坐标
'''
col = random.randint(1, tkk_size) # 列
row = random.randint(1, tkk_size) # 行
col: int = random.randint(1, tkk_size) # 列
row: int = random.randint(1, tkk_size) # 行

return row, col

def _get_waiting_time(self, tkk_size: int) -> int:
'''
计算等待时间
计算等待时间(秒)
'''
if tkk_size >= 30:
time = int(0.1 * (tkk_size - 30)**2 + 50)
Expand All @@ -60,7 +63,7 @@ def check_tkk_playing(self, uuid: str) -> bool:
'''
return False if not self.tkk_status.get(uuid, False) else self.tkk_status[uuid]["playing"]

def check_starter(self, gid: Optional[str], uid: str) -> bool:
def check_starter(self, uid: str, gid: Optional[str] = None) -> bool:
'''
作为Rule: 是否为发起者提前结束游戏
'''
Expand All @@ -82,18 +85,18 @@ def _draw_tkk(self, row: int, col: int, tkk_size: int, _find_charac: str) -> Tup
_charac: str = find_charac(_find_charac) # type: ignore
pick_list: List[str] = other_characs_list(_charac)

for r in range(0, tkk_size):
for c in range(0, tkk_size):
for r in range(tkk_size):
for c in range(tkk_size):
if r == row - 1 and c == col - 1:
charac = Image.open(tkk_config.tkk_path / (_charac + ".png"))
charac = charac.resize((64, 64), Image.ANTIALIAS) # 加载icon
charac = charac.resize((64, 64), Image.Resampling.LANCZOS) # 加载icon
draw = ImageDraw.Draw(charac)
draw.text((20, 40), f"({c+1},{r+1})", font=font, fill=(255, 0, 0, 0))
base.paste(charac, (r * 64, c * 64))
temp += 1
else:
icon = Image.open(tkk_config.tkk_path / (random.choice(pick_list) + '.png'))
icon = icon.resize((64,64), Image.ANTIALIAS)
icon = icon.resize((64,64), Image.Resampling.LANCZOS)
draw = ImageDraw.Draw(icon)
draw.text((20, 40), f"({c+1},{r+1})", font=font, fill=(255, 0, 0, 0))
base.paste(icon, (r * 64, c * 64))
Expand All @@ -104,7 +107,7 @@ def _draw_tkk(self, row: int, col: int, tkk_size: int, _find_charac: str) -> Tup
base2: Image.Image = base.copy()
mark = Image.open(tkk_config.tkk_path / "mark.png")

base2.paste(mark,((row - 1) * 64, (col - 1) * 64), mark)
base2.paste(mark, ((row - 1) * 64, (col - 1) * 64))
buf2 = BytesIO()
base2.save(buf2, format='png')

Expand Down Expand Up @@ -168,8 +171,10 @@ def bingo_close_game(self, uuid: str) -> bool:
timer = self.timers.get(uuid, None)
if timer:
timer.cancel()

self.timers.pop(uuid, None)
self.tkk_status.pop(uuid, False)

except KeyError:
return False

Expand Down Expand Up @@ -204,4 +209,4 @@ def one_go(self, matcher: Matcher, uuid: str, uid: str, level: str, find_charac:

return img_file, waiting

random_tkk_handler = RandomTkkHandler()
random_tkk_handler = RandomTkkHandler()
Loading

0 comments on commit 69db257

Please sign in to comment.