hungerlib 3.0.dev4__py3-none-any.whl → 3.0.dev6__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/__init__.py CHANGED
@@ -9,6 +9,7 @@ except PackageNotFoundError:
9
9
  # --- Core modules ---
10
10
  from .panel import Panel
11
11
  from .messagerouter import MessageRouter
12
+ from .datamap import *
12
13
 
13
14
  # --- API endpoints ---
14
15
  from .api.schedule import ScheduleAPI
@@ -23,6 +24,9 @@ __all__ = [
23
24
  # core utilities
24
25
  "Panel",
25
26
  "MessageRouter",
27
+ "Syntax",
28
+ "DataMap",
29
+ "mapit",
26
30
 
27
31
  # API endpoints
28
32
  "ScheduleAPI",
hungerlib/datamap.py ADDED
@@ -0,0 +1,60 @@
1
+ import re
2
+ from dataclasses import dataclass, fields, is_dataclass
3
+
4
+
5
+ class Syntax:
6
+ BRACES = r"\{([^{}]+)\}" # {key}
7
+ DOLLARS = r"\$\{([^{}]+)\}" # ${key}
8
+ ANGLES = r"<([^<>]+)>" # <key>
9
+ PERCENTS = r"%([^%]+)%" # %key%
10
+
11
+
12
+ @dataclass
13
+ class DataMap:
14
+ __syntax__: str = Syntax.BRACES
15
+
16
+ def as_map(self) -> dict:
17
+ return {
18
+ f.name: getattr(self, f.name)
19
+ for f in fields(self)
20
+ if f.init and f.name != "__syntax__"
21
+ }
22
+
23
+ @classmethod
24
+ def syntax(cls) -> str:
25
+ return getattr(cls, "__syntax__", Syntax.BRACES)
26
+
27
+
28
+ def mapit(text: str, *maps, **runtime) -> str:
29
+ for m in maps:
30
+ # auto-instantiate dataclass classes
31
+ if isinstance(m, type) and is_dataclass(m):
32
+ m = m()
33
+
34
+ # dataclass instance to dict
35
+ if is_dataclass(m):
36
+ pattern = m.syntax()
37
+ dmap = m.as_map()
38
+
39
+ # colormap-like objects to dict
40
+ elif hasattr(m, "as_dict"):
41
+ pattern = Syntax.ANGLES
42
+ dmap = m.as_dict()
43
+
44
+ # raw dict
45
+ elif isinstance(m, dict):
46
+ pattern = runtime.get("syntax", None)
47
+ if not pattern:
48
+ continue
49
+ dmap = m
50
+
51
+ else:
52
+ continue
53
+
54
+ # apply this map's syntax only
55
+ def repl(match):
56
+ key = match.group(1)
57
+ return str(dmap.get(key, match.group(0)))
58
+ text = re.sub(pattern, repl, text)
59
+
60
+ return text
@@ -102,10 +102,10 @@ class MessageRouter:
102
102
  self,
103
103
  template,
104
104
  level="info",
105
- origin=True,
106
105
  destination=False,
107
- log=True,
108
106
  broadcast=False,
107
+ log=True,
108
+ origin=True,
109
109
  **fmt
110
110
  ):
111
111
  if not template:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hungerlib
3
- Version: 3.0.dev4
3
+ Version: 3.0.dev6
4
4
  Summary: Powerful automation library for Pterodactyl.
5
5
  Author: iFamished
6
6
  License: MIT
@@ -1,5 +1,6 @@
1
- hungerlib/__init__.py,sha256=54enfzxjodLYPVg-CdeaZ2tInvkRspXjiUpc3MscS_g,717
2
- hungerlib/messagerouter.py,sha256=i49LHShxew_Cd7aJdtOkOWHVBJJ5hxsoYC8vOV5oHd0,4285
1
+ hungerlib/__init__.py,sha256=4Pq93TuN6ObGHypPxjXsAbCPUu2hlwRnj5GMpr8rnNg,782
2
+ hungerlib/datamap.py,sha256=h4gahAllz7ykpl9YSkFHPQ74IZrafda15SyRbBE_guA,1493
3
+ hungerlib/messagerouter.py,sha256=Zyz_N93hTfV0SvzHDMT0l5fDYgjIpYMVIEvigm5lh8U,4285
3
4
  hungerlib/panel.py,sha256=WMKBVh9MUM1KEYbvYwLFVzLCMZW4Dopfcxs09FEvfhU,2123
4
5
  hungerlib/addons/__init__.py,sha256=-wTg8YkIc_-99JY5Vyf3LcV1xdCOyIgoIBgPm98ByBQ,540
5
6
  hungerlib/addons/colormap.py,sha256=u3FqIn9Ny0lzSb4YB77MAPLz_tnqw587bDYJVnxDmqU,1983
@@ -18,8 +19,8 @@ hungerlib/api/startup.py,sha256=hKhBjpLMVYa3jjq6ahqm2N32B_fu-bZnOJTZ-P57v4M,434
18
19
  hungerlib/servers/__init__.py,sha256=iL2KajxhGHLdvGzEujTaEQmj1wvoHEB5f23YMu1gpyQ,133
19
20
  hungerlib/servers/generic.py,sha256=IOztlMuSCjrW37HJdqGu1762GMBTJlakjFI-6NoawAw,8789
20
21
  hungerlib/servers/minecraft.py,sha256=MasT_sRtHDuPWopo1Aa_tVtCVd-_n5zEysYIRykAY64,3176
21
- hungerlib-3.0.dev4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
- hungerlib-3.0.dev4.dist-info/METADATA,sha256=OGyAV4Eks1zd_FDOTbtwgJ7g_35feUFA_Hs4fstqUT0,1535
23
- hungerlib-3.0.dev4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
24
- hungerlib-3.0.dev4.dist-info/top_level.txt,sha256=uHBMIM8b2Gt6daNkDF4uw-M2Hm2IpIVw1jOK9wC0fNQ,10
25
- hungerlib-3.0.dev4.dist-info/RECORD,,
22
+ hungerlib-3.0.dev6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
23
+ hungerlib-3.0.dev6.dist-info/METADATA,sha256=RfBFCuNR9qNvaTdzt4s0Wdi9ouRKpEu1rmuBdjSz0RI,1535
24
+ hungerlib-3.0.dev6.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
25
+ hungerlib-3.0.dev6.dist-info/top_level.txt,sha256=uHBMIM8b2Gt6daNkDF4uw-M2Hm2IpIVw1jOK9wC0fNQ,10
26
+ hungerlib-3.0.dev6.dist-info/RECORD,,