nonebot-plugin-dbdmap 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-dbdmap
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: 《黎明杀机地图查询插件》
5
5
  Author-email: 77_77 <xiexiewen73@gmail.com>
6
6
  License: MIT
7
- Project-URL: Homepage, https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap
8
- Project-URL: Repository, https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap
9
7
  Keywords: nonebot,plugin,dead-by-daylight,dbd
10
8
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
- Classifier: Programming Language :: Python :: 3.9
13
9
  Classifier: Programming Language :: Python :: 3.10
14
10
  Classifier: Programming Language :: Python :: 3.11
15
- Requires-Python: >=3.8
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Python: <4.0,>=3.9
16
13
  Description-Content-Type: text/markdown
17
- Requires-Dist: nonebot2>=2.0.0
14
+ Requires-Dist: nonebot2>=2.5.0
15
+ Requires-Dist: nonebot-adapter-onebot>=2.4.6
18
16
 
19
17
  # NoneBot-Plugin-DBD-Map
20
18
 
@@ -1,24 +1,22 @@
1
1
  from nonebot.plugin import PluginMetadata
2
2
  import os
3
3
  import json
4
- from nonebot import on_command,get_driver
5
- from nonebot.adapters.onebot.v11 import Message, MessageEvent, MessageSegment,Bot
4
+ from nonebot import on_command, get_driver
5
+ from nonebot.adapters.onebot.v11 import Message, MessageEvent, MessageSegment, Bot
6
6
  from nonebot.params import CommandArg
7
7
  from nonebot.exception import FinishedException
8
8
  from pathlib import Path
9
+
9
10
  __plugin_meta__ = PluginMetadata(
10
11
  name="黎明杀机地图查询",
11
- description="支持查询所有官方地图",
12
- usage="发送 /查询 地图名&添加别名详见md",
12
+ description="支持查询所有官方地图及自定义别名",
13
+ usage="发送 /查询 地图名 或 /添加别名 原名 新别名",
13
14
  type="application",
14
- homepage="https://github.com/你的用户名/nonebot-plugin-dbdmap",
15
+ homepage="https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap",
15
16
  supported_adapters={"~onebot.v11"}
16
17
  )
17
- # ==================== 1. 基础地图数据(官方中文名 + 文件名) ====================
18
- base_dir = Path(os.path.dirname(os.path.abspath(__file__))).parent.parent.parent
19
18
 
20
- # 拼接静态资源路径
21
- STATIC_FOLDER = base_dir / "static" / "DBD_Map"
19
+ # 基础地图数据(纯内存数据,无外部依赖)
22
20
  BASE_MAP_DATA = {
23
21
  "gas_heaven": {"zh": "天堂加油站", "file": "gas_heaven.jpg"},
24
22
  "forgotten_ruins": {"zh": "被遗忘的废墟", "file": "forgotten_ruins.jpg"},
@@ -42,7 +40,7 @@ BASE_MAP_DATA = {
42
40
  "forgotten_ruins_dnd": {"zh": "被遗忘的废墟 (D&D)", "file": "forgotten_ruins_dnd.jpg"},
43
41
  "mount_ormond_resort": {"zh": "奥蒙德度假村", "file": "mount_ormond_resort.jpg"},
44
42
  "mount_ormond_resort_v2": {"zh": "奥蒙德度假村 v2", "file": "mount_ormond_resort_v2.jpg"},
45
- "shelter_woods_2": {"zh": "庇护林", "file": "shelter_woods_2.jpg"},
43
+ "shelter_woods_2": {"zh": "庇护林 II", "file": "shelter_woods_2.jpg"},
46
44
  "family_residence": {"zh": "家族住所", "file": "family_residence.jpg"},
47
45
  "dead_sands": {"zh": "死亡沙地", "file": "dead_sands.jpg"},
48
46
  "raccoon_city_police_station": {"zh": "浣熊市警察局", "file": "raccoon_city_police_station.jpg"},
@@ -50,7 +48,7 @@ BASE_MAP_DATA = {
50
48
  "mothers_dwelling": {"zh": "母亲之屋", "file": "mothers_dwelling.jpg"},
51
49
  "rotten_fields": {"zh": "腐烂田野", "file": "rotten_fields.jpg"},
52
50
  "toba_landing": {"zh": "托巴登陆点", "file": "toba_landing.jpg"},
53
- "suffocation_pit_ii": {"zh": "窒息矿井", "file": "suffocation_pit_ii.jpg"},
51
+ "suffocation_pit_ii": {"zh": "窒息矿井 II", "file": "suffocation_pit_ii.jpg"},
54
52
  "freddy_fazbears_pizza": {"zh": "弗莱迪披萨店", "file": "freddy_fazbears_pizza.jpg"},
55
53
  "torment_creek": {"zh": "折磨溪流", "file": "torment_creek.jpg"},
56
54
  "family_residence_v1": {"zh": "家族住所 v1", "file": "family_residence_v1.jpg"},
@@ -58,10 +56,10 @@ BASE_MAP_DATA = {
58
56
  "nostromo_wreckage": {"zh": "诺斯特罗莫残骸", "file": "nostromo_wreckage.jpg"},
59
57
  "dead_dawg_saloon": {"zh": "死狗酒馆", "file": "dead_dawg_saloon.jpg"},
60
58
  "blood_lodge": {"zh": "血腥小屋", "file": "blood_lodge.jpg"},
61
- "coal_tower_i": {"zh": "煤塔", "file": "coal_tower_i.jpg"},
62
- "coal_tower_ii": {"zh": "煤塔", "file": "coal_tower_ii.jpg"},
59
+ "coal_tower_i": {"zh": "煤塔 I", "file": "coal_tower_i.jpg"},
60
+ "coal_tower_ii": {"zh": "煤塔 II", "file": "coal_tower_ii.jpg"},
63
61
  "shelter_woods": {"zh": "庇护林", "file": "shelter_woods.jpg"},
64
- "ironworks_of_misery_ii": {"zh": "苦难铁厂", "file": "ironworks_of_misery_ii.jpg"},
62
+ "ironworks_of_misery_ii": {"zh": "苦难铁厂 II", "file": "ironworks_of_misery_ii.jpg"},
65
63
  "rancid_abattoir": {"zh": "腐臭屠宰场", "file": "rancid_abattoir.jpg"},
66
64
  "crotus_prenn_asylum": {"zh": "克劳图斯精神病院", "file": "crotus_prenn_asylum.jpg"},
67
65
  "eyrie_of_crows": {"zh": "乌鸦之巢", "file": "eyrie_of_crows.jpg"},
@@ -71,47 +69,18 @@ BASE_MAP_DATA = {
71
69
  "wretched_shop": {"zh": "悲惨商店", "file": "wretched_shop.jpg"},
72
70
  }
73
71
 
74
- # ==================== 2. 动态别名文件管理 ====================
75
- current_dir = os.path.dirname(os.path.abspath(__file__))
76
- base_dir = os.path.dirname(current_dir)
77
- ALIAS_FILE = os.path.join(base_dir, "data", "dbd_aliases.json")
78
-
79
- # 确保 data 文件夹存在
80
- os.makedirs(os.path.dirname(ALIAS_FILE), exist_ok=True)
81
-
82
-
83
- # 读取自定义别名
84
- def load_custom_aliases():
85
- if os.path.exists(ALIAS_FILE):
86
- with open(ALIAS_FILE, "r", encoding="utf-8") as f:
87
- return json.load(f)
88
- return {}
89
-
90
-
91
- # 保存自定义别名
92
- def save_custom_aliases(aliases):
93
- with open(ALIAS_FILE, "w", encoding="utf-8") as f:
94
- json.dump(aliases, f, ensure_ascii=False, indent=4)
95
-
96
-
97
- # 构建当前所有别名(基础中文 + 自定义别名)
72
+ # 构建所有别名(纯内存操作)
98
73
  def get_all_aliases():
99
74
  aliases = {}
100
- # 基础中文名
101
75
  for info in BASE_MAP_DATA.values():
102
76
  aliases[info["zh"]] = info["file"]
103
- # 自定义别名
104
- custom = load_custom_aliases()
105
- aliases.update(custom)
106
77
  return aliases
107
78
 
108
-
109
- # ==================== 3. 查询指令 ====================
79
+ # ==================== 查询指令 ====================
110
80
  query_cmd = on_command("查询", aliases={"地图", "查图"}, priority=1, block=True)
111
81
 
112
-
113
82
  @query_cmd.handle()
114
- async def handle_query(event: MessageEvent,bot:Bot,args: Message = CommandArg()):
83
+ async def handle_query(event: MessageEvent, bot: Bot, args: Message = CommandArg()):
115
84
  keyword = args.extract_plain_text().strip()
116
85
 
117
86
  if not keyword:
@@ -123,46 +92,43 @@ async def handle_query(event: MessageEvent,bot:Bot,args: Message = CommandArg())
123
92
  filename = aliases.get(keyword)
124
93
 
125
94
  if not filename:
126
- # 如果没找到,尝试匹配英文名
127
95
  if keyword.lower() in BASE_MAP_DATA:
128
96
  filename = BASE_MAP_DATA[keyword.lower()]["file"]
129
97
  else:
130
98
  await query_cmd.finish(f"没有找到地图【{keyword}】,请尝试其他关键词。")
131
99
  return
132
100
 
133
- # 拼接图片路径(使用动态绝对路径)
134
- img_path = os.path.join(base_dir, "static", "DBD_Map", filename)
101
+ # 动态获取机器人项目根目录(测试服务器也会成功)
102
+ plugin_dir = Path(__file__).parent
103
+ # 向上3级找到项目根目录
104
+ project_root = plugin_dir.parent.parent.parent
105
+ img_path = project_root / "static" / "DBD_Map" / filename
135
106
 
136
107
  try:
137
- # 尝试发送图片
138
108
  await query_cmd.send(MessageSegment.image(f"file:///{img_path}"))
139
109
 
140
- except FinishedException as e: # 3. 直接在这里“捕获”它,不需要赋值!
141
- error_msg = f"事件已经被其他插件结束 (FinishedException)\n可能被抢答:{img_path}"
110
+ except FinishedException:
111
+ error_msg = f"事件已经被其他插件结束\n可能被抢答:{img_path}"
142
112
  global_config = get_driver().config
143
113
 
144
- async def send_error_to_master(bot: Bot, error_msg: str):
145
- # 遍历所有超级用户的 QQ 号,发给每一个
146
- for master_id in global_config.superusers:
147
- try:
148
- await bot.call_api(
149
- "send_private_msg",
150
- user_id=int(master_id),
151
- message=f"⚠️ DBD地图查询被拦截了!\n\n错误详情:\n{error_msg}"
152
- )
153
- print(f"[报错上报] 已私聊通知主人:{master_id}")
154
- except Exception as e:
155
- print(f"[报错上报失败] 无法私聊主人 {master_id},原因:{e}")
156
- print(f"[DBD地图] 遭遇 FinishedException,已上报主人。")
157
-
158
- except Exception as e: # 4. 其他普通错误,直接回复用户
114
+ for master_id in global_config.superusers:
115
+ try:
116
+ await bot.call_api(
117
+ "send_private_msg",
118
+ user_id=int(master_id),
119
+ message=f"⚠️ DBD地图查询被拦截了!\n\n错误详情:\n{error_msg}"
120
+ )
121
+ print(f"[报错上报] 已私聊通知主人:{master_id}")
122
+ except Exception as e:
123
+ print(f"[报错上报失败] 无法私聊主人 {master_id},原因:{e}")
124
+
125
+ except Exception as e:
159
126
  await query_cmd.finish(f"图片发送失败:{e}")
160
127
 
161
128
 
162
- # ==================== 4. 添加别名管理指令 ====================
129
+ # ==================== 添加别名指令 ====================
163
130
  add_alias_cmd = on_command("添加别名", aliases={"别名"}, priority=1, block=True)
164
131
 
165
-
166
132
  @add_alias_cmd.handle()
167
133
  async def handle_add_alias(event: MessageEvent, args: Message = CommandArg()):
168
134
  input_text = args.extract_plain_text().strip()
@@ -177,7 +143,6 @@ async def handle_add_alias(event: MessageEvent, args: Message = CommandArg()):
177
143
 
178
144
  original_keyword, new_alias = parts[0], parts[1]
179
145
 
180
- # 查找原关键词对应的图片文件名
181
146
  all_aliases = get_all_aliases()
182
147
  target_file = all_aliases.get(original_keyword) or BASE_MAP_DATA.get(original_keyword.lower(), {}).get("file")
183
148
 
@@ -185,9 +150,23 @@ async def handle_add_alias(event: MessageEvent, args: Message = CommandArg()):
185
150
  await add_alias_cmd.finish(f"找不到原关键词【{original_keyword}】,请确认它是否存在。")
186
151
  return
187
152
 
188
- # 更新并保存自定义别名
189
- custom_aliases = load_custom_aliases()
153
+ # 动态获取项目目录
154
+ plugin_dir = Path(__file__).parent
155
+ project_root = plugin_dir.parent.parent.parent
156
+ data_dir = project_root / "data"
157
+ data_dir.mkdir(parents=True, exist_ok=True)
158
+
159
+ alias_file = data_dir / "dbd_aliases.json"
160
+
161
+ # 读取
162
+ custom_aliases = {}
163
+ if alias_file.exists():
164
+ with open(alias_file, "r", encoding="utf-8") as f:
165
+ custom_aliases = json.load(f)
166
+
167
+ # 写入
190
168
  custom_aliases[new_alias] = target_file
191
- save_custom_aliases(custom_aliases)
169
+ with open(alias_file, "w", encoding="utf-8") as f:
170
+ json.dump(custom_aliases, f, ensure_ascii=False, indent=4)
192
171
 
193
172
  await add_alias_cmd.finish(f"✅ 成功添加别名!以后发送“{new_alias}”也能查到“{original_keyword}”对应的地图了。")
@@ -1,20 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-dbdmap
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: 《黎明杀机地图查询插件》
5
5
  Author-email: 77_77 <xiexiewen73@gmail.com>
6
6
  License: MIT
7
- Project-URL: Homepage, https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap
8
- Project-URL: Repository, https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap
9
7
  Keywords: nonebot,plugin,dead-by-daylight,dbd
10
8
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
- Classifier: Programming Language :: Python :: 3.9
13
9
  Classifier: Programming Language :: Python :: 3.10
14
10
  Classifier: Programming Language :: Python :: 3.11
15
- Requires-Python: >=3.8
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Python: <4.0,>=3.9
16
13
  Description-Content-Type: text/markdown
17
- Requires-Dist: nonebot2>=2.0.0
14
+ Requires-Dist: nonebot2>=2.5.0
15
+ Requires-Dist: nonebot-adapter-onebot>=2.4.6
18
16
 
19
17
  # NoneBot-Plugin-DBD-Map
20
18
 
@@ -0,0 +1,2 @@
1
+ nonebot2>=2.5.0
2
+ nonebot-adapter-onebot>=2.4.6
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-dbdmap"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "《黎明杀机地图查询插件》"
5
5
  readme = "README.md"
6
- requires-python = ">=3.8"
6
+ requires-python = ">=3.9, <4.0"
7
7
  license = {text = "MIT"}
8
8
  authors = [
9
9
  {name = "77_77", email = "xiexiewen73@gmail.com"}
@@ -11,16 +11,11 @@ authors = [
11
11
  keywords = ["nonebot", "plugin", "dead-by-daylight", "dbd"]
12
12
  classifiers = [
13
13
  "Programming Language :: Python :: 3",
14
- "Programming Language :: Python :: 3.8",
15
- "Programming Language :: Python :: 3.9",
16
14
  "Programming Language :: Python :: 3.10",
17
15
  "Programming Language :: Python :: 3.11",
18
- # "Framework :: NoneBot",
16
+ "Programming Language :: Python :: 3.12",
19
17
  ]
20
18
  dependencies = [
21
- "nonebot2>=2.0.0",
22
- ]
23
-
24
- [project.urls]
25
- Homepage = "https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap"
26
- Repository = "https://github.com/xiexiewen73-source/nonebot-plugin-dbdmap"
19
+ "nonebot2>=2.5.0",
20
+ "nonebot-adapter-onebot>=2.4.6"
21
+ ]