hungerlib 3.2.dev8__py3-none-any.whl → 3.2.dev10__py3-none-any.whl
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.
- hungerlib/datamap.py +35 -3
- hungerlib/messagerouter.py +5 -39
- {hungerlib-3.2.dev8.dist-info → hungerlib-3.2.dev10.dist-info}/METADATA +1 -1
- {hungerlib-3.2.dev8.dist-info → hungerlib-3.2.dev10.dist-info}/RECORD +7 -7
- {hungerlib-3.2.dev8.dist-info → hungerlib-3.2.dev10.dist-info}/WHEEL +0 -0
- {hungerlib-3.2.dev8.dist-info → hungerlib-3.2.dev10.dist-info}/licenses/LICENSE +0 -0
- {hungerlib-3.2.dev8.dist-info → hungerlib-3.2.dev10.dist-info}/top_level.txt +0 -0
hungerlib/datamap.py
CHANGED
|
@@ -48,33 +48,65 @@ datamap.angles = datamap(syntax=Syntax.angles)
|
|
|
48
48
|
datamap.dollars = datamap(syntax=Syntax.dollars)
|
|
49
49
|
datamap.percents = datamap(syntax=Syntax.percents)
|
|
50
50
|
|
|
51
|
-
def mapit(text: str, *maps, **runtime):
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
def mapit(text: str, *maps, only_maps=None, disable=None, enable=None, **runtime):
|
|
52
|
+
# 1. FULL OVERRIDE MODE
|
|
53
|
+
if only_maps is not None:
|
|
54
|
+
maps_to_use = list(only_maps)
|
|
55
|
+
|
|
56
|
+
else:
|
|
57
|
+
# 2. Start with default maps
|
|
58
|
+
maps_to_use = list(get_default_maps())
|
|
59
|
+
|
|
60
|
+
# 3. Remove disabled maps
|
|
61
|
+
if disable:
|
|
62
|
+
maps_to_use = [m for m in maps_to_use if m not in disable]
|
|
63
|
+
|
|
64
|
+
# 4. Add positional maps
|
|
65
|
+
if maps:
|
|
66
|
+
maps_to_use.extend(maps)
|
|
67
|
+
|
|
68
|
+
# 5. Add enabled maps
|
|
69
|
+
if enable:
|
|
70
|
+
maps_to_use.extend(enable)
|
|
71
|
+
|
|
72
|
+
# 6. Apply maps in order
|
|
73
|
+
for m in maps_to_use:
|
|
54
74
|
if isinstance(m, type) and is_dataclass(m):
|
|
55
75
|
m = m()
|
|
76
|
+
|
|
56
77
|
if is_dataclass(m):
|
|
57
78
|
pattern = m.get_syntax()
|
|
58
79
|
d = m.as_map()
|
|
80
|
+
|
|
59
81
|
elif hasattr(m, "as_dict"):
|
|
60
82
|
pattern = Syntax.angles
|
|
61
83
|
d = m.as_dict()
|
|
84
|
+
|
|
62
85
|
elif isinstance(m, dict):
|
|
63
86
|
pattern = runtime.get("syntax")
|
|
64
87
|
if not pattern:
|
|
65
88
|
continue
|
|
66
89
|
d = m
|
|
90
|
+
|
|
67
91
|
else:
|
|
68
92
|
continue
|
|
93
|
+
|
|
69
94
|
def repl(match):
|
|
70
95
|
k = match.group(1)
|
|
71
96
|
return str(d.get(k, match.group(0)))
|
|
97
|
+
|
|
72
98
|
text = re.sub(pattern, repl, text)
|
|
99
|
+
|
|
100
|
+
# 7. Runtime kwargs always apply last
|
|
73
101
|
if runtime:
|
|
74
102
|
pattern = Syntax.braces
|
|
75
103
|
d = runtime
|
|
104
|
+
|
|
76
105
|
def repl(match):
|
|
77
106
|
k = match.group(1)
|
|
78
107
|
return str(d.get(k, match.group(0)))
|
|
108
|
+
|
|
79
109
|
text = re.sub(pattern, repl, text)
|
|
110
|
+
|
|
80
111
|
return text
|
|
112
|
+
|
hungerlib/messagerouter.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import inspect
|
|
2
1
|
import logging
|
|
3
2
|
from pathlib import Path
|
|
4
3
|
from datetime import datetime
|
|
5
|
-
from hungerlib.utils.colormaps import ASCII_COLOR_MAP, MC_COLOR_MAP
|
|
6
|
-
from hungerlib.datamap import DataMap, Syntax, mapit
|
|
7
|
-
|
|
8
4
|
|
|
9
5
|
class MessageRouter:
|
|
10
6
|
def __init__(
|
|
@@ -15,11 +11,6 @@ class MessageRouter:
|
|
|
15
11
|
formatter=None,
|
|
16
12
|
console_backspaces=0,
|
|
17
13
|
|
|
18
|
-
origin_map=ASCII_COLOR_MAP,
|
|
19
|
-
destination_map=ASCII_COLOR_MAP,
|
|
20
|
-
broadcast_map=MC_COLOR_MAP,
|
|
21
|
-
log_map=None,
|
|
22
|
-
|
|
23
14
|
info_prefix="<white>[INFO]: ",
|
|
24
15
|
warn_prefix="<yellow>[WARN]: ",
|
|
25
16
|
error_prefix="<red>[ERROR]: "
|
|
@@ -33,11 +24,6 @@ class MessageRouter:
|
|
|
33
24
|
|
|
34
25
|
self.console_backspaces = "\b" * console_backspaces
|
|
35
26
|
|
|
36
|
-
self._origin_map = origin_map
|
|
37
|
-
self._destination_map = destination_map
|
|
38
|
-
self._broadcast_map = broadcast_map
|
|
39
|
-
self._log_map = log_map
|
|
40
|
-
|
|
41
27
|
self.info_prefix = info_prefix
|
|
42
28
|
self.warn_prefix = warn_prefix
|
|
43
29
|
self.error_prefix = error_prefix
|
|
@@ -57,47 +43,27 @@ class MessageRouter:
|
|
|
57
43
|
handler.setFormatter(formatter)
|
|
58
44
|
self.logger.addHandler(handler)
|
|
59
45
|
|
|
60
|
-
#
|
|
61
|
-
def setOriginMap(self, cmap): self._origin_map = cmap
|
|
62
|
-
def getOriginMap(self): return self._origin_map
|
|
63
|
-
|
|
64
|
-
def setDestinationMap(self, cmap): self._destination_map = cmap
|
|
65
|
-
def getDestinationMap(self): return self._destination_map
|
|
66
|
-
|
|
67
|
-
def setBroadcastMap(self, cmap): self._broadcast_map = cmap
|
|
68
|
-
def getBroadcastMap(self): return self._broadcast_map
|
|
69
|
-
|
|
70
|
-
def setLogMap(self, cmap): self._log_map = cmap
|
|
71
|
-
def getLogMap(self): return self._log_map
|
|
72
|
-
|
|
73
|
-
# routing primatives
|
|
46
|
+
# routing primitives
|
|
74
47
|
def origin(self, msg):
|
|
75
|
-
|
|
76
|
-
print(colored)
|
|
48
|
+
print(msg)
|
|
77
49
|
|
|
78
50
|
def destination(self, msg):
|
|
79
51
|
if not self.server or not hasattr(self.server, "_rcon_send"):
|
|
80
52
|
return
|
|
81
|
-
colored = mapit(msg, self._destination_map)
|
|
82
53
|
self.server._rcon_send(
|
|
83
|
-
f'logtellraw targetless "{self.console_backspaces}{
|
|
54
|
+
f'logtellraw targetless "{self.console_backspaces}{msg}"'
|
|
84
55
|
)
|
|
85
56
|
|
|
86
57
|
def log(self, msg, level="INFO"):
|
|
87
|
-
clean = msg
|
|
88
|
-
if self._log_map:
|
|
89
|
-
for tag in self._log_map.as_dict().keys():
|
|
90
|
-
clean = clean.replace(tag, "")
|
|
91
58
|
{
|
|
92
59
|
"INFO": self.logger.info,
|
|
93
60
|
"WARN": self.logger.warning,
|
|
94
61
|
"ERROR": self.logger.error
|
|
95
|
-
}[level](
|
|
62
|
+
}[level](msg)
|
|
96
63
|
|
|
97
64
|
def broadcast(self, msg):
|
|
98
65
|
if hasattr(self.server, "sendBroadcast"):
|
|
99
|
-
|
|
100
|
-
self.server.sendBroadcast(colored)
|
|
66
|
+
self.server.sendBroadcast(msg)
|
|
101
67
|
|
|
102
68
|
# high level router
|
|
103
69
|
def say(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
hungerlib/__init__.py,sha256=CTLIet8Tg8Gx3wWUrUNgIsHutv0JS1YzLelp1GLaLTs,2147
|
|
2
2
|
hungerlib/configloader.py,sha256=TdEFqk2zG5nT-vJqdjA36DrbRinY66n0rgI8Z-EZmAk,2548
|
|
3
|
-
hungerlib/datamap.py,sha256=
|
|
4
|
-
hungerlib/messagerouter.py,sha256=
|
|
3
|
+
hungerlib/datamap.py,sha256=Tvcjc-n-tNO9SNQeh0k3dWzbxrRnnNVUmPnq0gap_8w,2807
|
|
4
|
+
hungerlib/messagerouter.py,sha256=_Exn3zzwdnHCSDt8bvdCylq9atvhAyOK32a9TySKQCU,3098
|
|
5
5
|
hungerlib/panel.py,sha256=LljDy3FZoabWotdrNhN89xHd2VcvbiQDshtZgMa0g08,2013
|
|
6
6
|
hungerlib/api/__init__.py,sha256=xuPbWBXVTkr9Jtcmvk8PPiVvi8HDxrIOmb_gOcDZy-M,336
|
|
7
7
|
hungerlib/api/backups.py,sha256=eJEaCot9QpyvaqB3qne6e94CYmjJahj9Tf9r8ogUQr0,642
|
|
@@ -17,8 +17,8 @@ hungerlib/utils/__init__.py,sha256=xyUldIwkVopZrp0Yp5g18vqGDUp3OOT4KknntLU4oes,5
|
|
|
17
17
|
hungerlib/utils/colormaps.py,sha256=88eIDSI1hZYbtXmd7XujgmR1nhOXAkyB8ospQTqSHns,1240
|
|
18
18
|
hungerlib/utils/time.py,sha256=lhLHMkL5NEP9f7j5k24k5brr1ZvAL22t07eV2rxTZ50,2354
|
|
19
19
|
hungerlib/utils/utils.py,sha256=rGVXiK-ZaN1riNL_1QHKJZdOAX53vGlSDUzEP1Aqle4,1404
|
|
20
|
-
hungerlib-3.2.
|
|
21
|
-
hungerlib-3.2.
|
|
22
|
-
hungerlib-3.2.
|
|
23
|
-
hungerlib-3.2.
|
|
24
|
-
hungerlib-3.2.
|
|
20
|
+
hungerlib-3.2.dev10.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
21
|
+
hungerlib-3.2.dev10.dist-info/METADATA,sha256=IW8CwHOl0HJabmx0VdqIGLQtqu0djU8ZFEH5Hz-tfUg,1536
|
|
22
|
+
hungerlib-3.2.dev10.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
23
|
+
hungerlib-3.2.dev10.dist-info/top_level.txt,sha256=uHBMIM8b2Gt6daNkDF4uw-M2Hm2IpIVw1jOK9wC0fNQ,10
|
|
24
|
+
hungerlib-3.2.dev10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|