Skip to content

Commit

Permalink
修复了属性类的一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOrangeQWQ committed Mar 27, 2023
1 parent ae2b036 commit 836d14a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
12 changes: 6 additions & 6 deletions nonebot_plugin_orangedice/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def visit(self, node ):


# ——TEST——
args = [
'3d100q3'
]
# args = [
# '3d100q3'
# ]

for i in args:
parser = Parser(Lexer(i))
print(parser.parse())
# for i in args:
# parser = Parser(Lexer(i))
# print(parser.parse())

19 changes: 12 additions & 7 deletions nonebot_plugin_orangedice/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ class Attribute:
"""属性类"""

def __init__(self, args: str):
self.attrs = self.get_attrs(args)
self.same = self.same_list()
self.alias_dict = self._alias_dict()
self.attrs = self.get_attrs(args)

def get_attrs(self, msg: str) -> Dict[str, int]:
"""通过正则处理玩家的车卡数据,获取属性值"""
find: list[tuple[str, int]] = findall(r"(\D{2,10})(\d{1,3})", msg)
find: list[tuple[str, int]] = findall(r"(\D{1,10})(\d{1,3})", msg)
attrs: Dict[str, int] = {}
for i in find:
a, b = i
if not self.is_alias(a):
if self.is_alias(a):
attrs[self.alias_dict[a]] = int(b)
else:
attrs[str(a)] = int(b)
return attrs

Expand All @@ -55,10 +57,13 @@ def _alias_dict(self) -> Dict[str, str]:

def is_alias(self, attr: str) -> bool:
"""判定属性是否为别名"""
for v in same_attr_list.values():
if attr in v:
return True
if attr in self.same:
return True
return False
# for v in same_attr_list.values():
# if attr in v:
# return True
# return False

def set(self, attr: str, value: int) -> Self:
"""设置属性值"""
Expand Down Expand Up @@ -113,7 +118,7 @@ def __str__(self) -> str:
for k,v in self.attrs.items():
attrs += f"{k}{v}"
return attrs


def join_log_msg(data: DataContainer, event: MessageEvent, msg: str):
"""拼接日志消息"""
Expand Down
20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[project]
name = "nonebot_plugin_orangedice"
version = "0.3.5"
version = "0.3.6"
description = "A COC dice plugin for nonebot2"
authors = [
{name = "BigOrangeQWQ", email = "2284086963@qq.com"},
Expand All @@ -17,6 +17,24 @@ requires-python = ">=3.8"
readme = "README.md"
license = {text = "MIT"}

[tool.isort]
profile = "black"
line_length = 88
length_sort = true
skip_gitignore = true
force_sort_within_sections = true
src_paths = ["nonebot", "tests"]
extra_standard_library = ["typing_extensions"]

[tool.pyright]
reportShadowedImports = false
pythonVersion = "3.8"
pythonPlatform = "All"
executionEnvironments = [
{ root = "./tests", extraPaths = ["./"] },
{ root = "./" },
]

[build-system]
requires = ["pdm-pep517>=1.0"]
build-backend = "pdm.pep517.api"

0 comments on commit 836d14a

Please sign in to comment.