serverwatcher 5.33.dev3__tar.gz → 6a1__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.
Files changed (29) hide show
  1. serverwatcher-6a1/PKG-INFO +60 -0
  2. serverwatcher-6a1/README.md +31 -0
  3. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/pyproject.toml +6 -9
  4. serverwatcher-6a1/src/serverwatcher/__main__.py +101 -0
  5. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/configclasses/config.py +14 -3
  6. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/configclasses/messages.py +2 -2
  7. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/configclasses/watcher.py +2 -2
  8. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/defaultconfigs/config.yaml +6 -1
  9. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/defaultconfigs/messages.yaml +21 -21
  10. serverwatcher-6a1/src/serverwatcher/tests/test.py +77 -0
  11. serverwatcher-6a1/src/serverwatcher/tests/test2.py +323 -0
  12. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/validator.py +17 -3
  13. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/watcher.py +103 -28
  14. serverwatcher-6a1/src/serverwatcher/watchercli.py +130 -0
  15. serverwatcher-6a1/src/serverwatcher.egg-info/PKG-INFO +60 -0
  16. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher.egg-info/SOURCES.txt +4 -1
  17. serverwatcher-6a1/src/serverwatcher.egg-info/requires.txt +3 -0
  18. serverwatcher-5.33.dev3/PKG-INFO +0 -47
  19. serverwatcher-5.33.dev3/README.md +0 -16
  20. serverwatcher-5.33.dev3/src/serverwatcher/__main__.py +0 -47
  21. serverwatcher-5.33.dev3/src/serverwatcher.egg-info/PKG-INFO +0 -47
  22. serverwatcher-5.33.dev3/src/serverwatcher.egg-info/requires.txt +0 -5
  23. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/LICENSE +0 -0
  24. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/setup.cfg +0 -0
  25. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/__init__.py +0 -0
  26. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/configclasses/__init__.py +0 -0
  27. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher/defaultconfigs/watcher.yaml +0 -0
  28. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
  29. {serverwatcher-5.33.dev3 → serverwatcher-6a1}/src/serverwatcher.egg-info/top_level.txt +0 -0
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: serverwatcher
3
+ Version: 6a1
4
+ Summary: A HungerLib-powered Minecraft server automation engine.
5
+ Author: iFamished
6
+ License: GPL-3.0
7
+ Project-URL: Homepage, https://github.com/iFamished/ServerWatcher
8
+ Project-URL: Documentation, https://github.com/iFamished/ServerWatcher
9
+ Project-URL: Source, https://github.com/iFamished/ServerWatcher
10
+ Project-URL: Issues, https://github.com/iFamished/ServerWatcher/issues
11
+ Keywords: pterodactyl,minecraft,automation,server-management,hungerlib,hungernet
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Development Status :: 4 - Beta
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: System :: Systems Administration
22
+ Requires-Python: >=3.14
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: hungerlib>=3.1
26
+ Requires-Dist: mapres
27
+ Requires-Dist: C2E
28
+ Dynamic: license-file
29
+
30
+ # ServerWatcher
31
+ A highly configurable Minecraft server monitoring and restart engine for HungerBridge / Pterodactyl-based Minecraft servers.
32
+
33
+ ## System requirements
34
+ | | **Minimum** | **Recommended** |
35
+ | ----------- | ----------- | --------------- |
36
+ | **RAM** | 128 MB | 256 MB |
37
+ | **Storage** | 256 MB | 1 GB |
38
+
39
+ ## Prerequisites
40
+ **Pterodactyl Panel / API credentials**
41
+ - You must have the server on a Pterodactyl Panel
42
+ - You need a valid client API token
43
+ **HungerBridge**
44
+ - Install [HungerBridge from Modrinth](https://modrinth.com/project/hungerbridge) on the Minecraft server you wish to monitor
45
+ - HungerBridge supports `Fabric`, `Quilt`, `Paper`, `Purpur`, and `Folia`
46
+ **A dedicated Python environment**
47
+ - ServerWatcher requires a Python 3.14+ environment to run
48
+ *Discord bot*
49
+ - Optional. The bot must have the correct endpoints set up.
50
+ *Logging directory*
51
+ - Optional. Only necessary if you want to use file logging.
52
+
53
+ ## Installation
54
+ - Download the [**ServerWatcher Pterodactyl egg**](https://github.com/iFamished/ServerWatcher/blob/main/eggs/serverwatcher.json)
55
+ - Import it into your desired nest in your panel
56
+ - Create a server with the egg selected
57
+ - Start the server and wait for instalation and file generation to finish
58
+ - Configure the files in config/
59
+ - Start the server again
60
+ - You're done! Just let it do its thing.
@@ -0,0 +1,31 @@
1
+ # ServerWatcher
2
+ A highly configurable Minecraft server monitoring and restart engine for HungerBridge / Pterodactyl-based Minecraft servers.
3
+
4
+ ## System requirements
5
+ | | **Minimum** | **Recommended** |
6
+ | ----------- | ----------- | --------------- |
7
+ | **RAM** | 128 MB | 256 MB |
8
+ | **Storage** | 256 MB | 1 GB |
9
+
10
+ ## Prerequisites
11
+ **Pterodactyl Panel / API credentials**
12
+ - You must have the server on a Pterodactyl Panel
13
+ - You need a valid client API token
14
+ **HungerBridge**
15
+ - Install [HungerBridge from Modrinth](https://modrinth.com/project/hungerbridge) on the Minecraft server you wish to monitor
16
+ - HungerBridge supports `Fabric`, `Quilt`, `Paper`, `Purpur`, and `Folia`
17
+ **A dedicated Python environment**
18
+ - ServerWatcher requires a Python 3.14+ environment to run
19
+ *Discord bot*
20
+ - Optional. The bot must have the correct endpoints set up.
21
+ *Logging directory*
22
+ - Optional. Only necessary if you want to use file logging.
23
+
24
+ ## Installation
25
+ - Download the [**ServerWatcher Pterodactyl egg**](https://github.com/iFamished/ServerWatcher/blob/main/eggs/serverwatcher.json)
26
+ - Import it into your desired nest in your panel
27
+ - Create a server with the egg selected
28
+ - Start the server and wait for instalation and file generation to finish
29
+ - Configure the files in config/
30
+ - Start the server again
31
+ - You're done! Just let it do its thing.
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "serverwatcher"
10
- version = "5.33.dev3"
10
+ version = "6-alpha.1"
11
11
  description = "A HungerLib-powered Minecraft server automation engine."
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.14"
@@ -18,17 +18,14 @@ keywords = [
18
18
  "pterodactyl",
19
19
  "minecraft",
20
20
  "automation",
21
- "rcon",
22
21
  "server-management",
23
22
  "hungerlib",
24
23
  "hungernet",
25
24
  ]
26
25
  dependencies = [
27
- "requests",
28
- "mcrcon",
29
26
  "hungerlib>=3.1",
30
- "PyYaml",
31
27
  "mapres",
28
+ "C2E",
32
29
  ]
33
30
  classifiers = [
34
31
  "Programming Language :: Python :: 3",
@@ -47,10 +44,10 @@ classifiers = [
47
44
  text = "GPL-3.0"
48
45
 
49
46
  [project.urls]
50
- Homepage = "https://github.com/iFamishedX/ServerWatcher"
51
- Documentation = "https://github.com/iFamishedX/ServerWatcher"
52
- Source = "https://github.com/iFamishedX/ServerWatcher"
53
- Issues = "https://github.com/iFamishedX/ServerWatcher/issues"
47
+ Homepage = "https://github.com/iFamished/ServerWatcher"
48
+ Documentation = "https://github.com/iFamished/ServerWatcher"
49
+ Source = "https://github.com/iFamished/ServerWatcher"
50
+ Issues = "https://github.com/iFamished/ServerWatcher/issues"
54
51
 
55
52
  [tool.setuptools.packages.find]
56
53
  where = [
@@ -0,0 +1,101 @@
1
+ import time
2
+ import asyncio
3
+ import threading
4
+
5
+ from mapres import rprint, setGlobalMaps, ascii_colors
6
+
7
+ from hungerlib.validator import (
8
+ ValidationError,
9
+ FatalError,
10
+ TypeMismatchError,
11
+ FallbackError,
12
+ RecommendedError,
13
+ )
14
+
15
+ from .watcher import ServerWatcher
16
+ from .validator import validate_all
17
+ from .watchercli import WatcherCLI
18
+
19
+
20
+ setGlobalMaps(ascii_colors)
21
+
22
+
23
+ def pretty_report(report: str) -> str:
24
+ lines = report.splitlines()
25
+ out = []
26
+ for line in lines:
27
+ stripped = line.strip()
28
+ if stripped.startswith('errors:'):
29
+ out.append('<red>Errors:')
30
+ continue
31
+ if stripped.startswith('recommended:'):
32
+ out.append('<yellow>Recommended:')
33
+ continue
34
+ if stripped.startswith('fallbacks:'):
35
+ out.append('<yellow>Fallbacks:')
36
+ continue
37
+ if stripped.startswith('warnings:'):
38
+ out.append('<aqua>Warnings:')
39
+ continue
40
+ if stripped.startswith('- '):
41
+ out.append(f' {stripped}')
42
+ continue
43
+ out.append(line)
44
+ return '\n'.join(out)
45
+
46
+
47
+ def main():
48
+ try:
49
+ validate_all()
50
+
51
+ except FatalError as e:
52
+ rprint('<bold><red>FATAL CONFIG ERROR:')
53
+ rprint(pretty_report(e.report))
54
+ rprint('\nIt looks like ServerWatcher is not configured yet.')
55
+ rprint('<aqua>Please edit your config files in config/ and try again.')
56
+ return
57
+
58
+ except TypeMismatchError as e:
59
+ rprint('<bold><red>TYPE MISMATCH ERROR:')
60
+ rprint(pretty_report(e.report))
61
+ rprint('\nYour configuration contains values of the wrong type.')
62
+ rprint('<aqua>Please fix your config files and try again.')
63
+ return
64
+
65
+ except FallbackError as e:
66
+ rprint('<bold><yellow>FALLBACKS IN USE:')
67
+ rprint(pretty_report(e.report))
68
+ rprint('\nIt looks like you have not configured ServerWatcher yet.')
69
+ rprint('<aqua>Please edit your config files in config/ and try again.')
70
+ return
71
+
72
+ except RecommendedError as e:
73
+ rprint('<bold><yellow>RECOMMENDED KEYS MISSING:')
74
+ rprint(pretty_report(e.report))
75
+ rprint('\nYour configuration is missing recommended keys.')
76
+ rprint('<aqua>Continuing in 5 seconds...')
77
+ time.sleep(5)
78
+
79
+ except ValidationError as e:
80
+ rprint('<bold><red>CONFIG ERROR:')
81
+ rprint(pretty_report(e.report))
82
+ rprint('\nYour configuration is invalid.')
83
+ rprint('<aqua>Please edit your config files and try again.')
84
+ return
85
+
86
+ except Exception as e:
87
+ rprint('<bold><red>UNEXPECTED ERROR:')
88
+ rprint(str(e))
89
+ rprint('\nSomething went wrong before ServerWatcher could start.')
90
+ rprint('<aqua>Please check your configuration and environment.')
91
+ return
92
+
93
+ # Start watcher thread
94
+ watcher = ServerWatcher()
95
+ threading.Thread(target=watcher.run, daemon=True).start()
96
+
97
+ cli = WatcherCLI(watcher)
98
+ asyncio.run(cli.run())
99
+
100
+ if __name__ == '__main__':
101
+ main()
@@ -1,6 +1,6 @@
1
- from mapres import datamap, syntax
1
+ from mapres import datamap
2
2
 
3
- @datamap(syntax=syntax.braces, mode='config')
3
+ @datamap.braces.config(recursive=True)
4
4
  class GlobalConfig:
5
5
  __user_config_path__ = 'config/config.yaml'
6
6
  __default_config_path__ = 'defaultconfigs/config.yaml'
@@ -20,6 +20,10 @@ class GlobalConfig:
20
20
  bridge_token: str = 'hungerbridge.token'
21
21
  bridge_url: str = 'hungerbridge.url'
22
22
 
23
+ discord_enabled: bool = 'discord.enabled'
24
+ discord_token: str = 'discord.token'
25
+ discord_url: str = 'discord.url'
26
+
23
27
  enable_logging: bool = 'logger.enabled'
24
28
  logger_name: str = 'logger.name'
25
29
  log_path: str = 'logger.log_path'
@@ -47,7 +51,11 @@ class fallbacks:
47
51
  server_port = 25565
48
52
 
49
53
  bridge_token = 'CHANGE_ME'
50
- bridge_url = 'https://api.example.com:1913'
54
+ bridge_url = 'https://api.example.com'
55
+
56
+ discord_enabled = True
57
+ discord_token = 'CHANGE_ME'
58
+ discord_url = 'https://bot.example.com/webhook'
51
59
 
52
60
  enable_logging = True
53
61
  logger_name = 'Server Watcher'
@@ -74,4 +82,7 @@ class rules:
74
82
  server_port = 'recommended'
75
83
  bridge_url = 'recommended'
76
84
 
85
+ discord_url = 'recommended'
86
+ discord_token = 'recommended'
87
+
77
88
  # everything else defaults to optional
@@ -1,6 +1,6 @@
1
- from mapres import datamap, syntax
1
+ from mapres import datamap
2
2
 
3
- @datamap(syntax=syntax.braces, mode='config')
3
+ @datamap.braces.config(recursive=True)
4
4
  class MessagesConfig:
5
5
  __user_config_path__ = 'config/messages.yaml'
6
6
  __default_config_path__ = 'defaultconfigs/messages.yaml'
@@ -1,6 +1,6 @@
1
- from mapres import datamap, syntax
1
+ from mapres import datamap
2
2
 
3
- @datamap(mode='config')
3
+ @datamap.braces.config(recursive=True)
4
4
  class WatcherConfig:
5
5
  __user_config_path__ = 'config/watcher.yaml'
6
6
  __default_config_path__ = 'defaultconfigs/watcher.yaml'
@@ -14,7 +14,12 @@ server:
14
14
 
15
15
  hungerbridge:
16
16
  token: 'CHANGE_ME'
17
- url: 'https://api.example.com:1913'
17
+ url: 'https://api.example.com'
18
+
19
+ discord:
20
+ enabled: False
21
+ token: 'CHANGE_ME'
22
+ url: 'https://bot.example.com/webhook'
18
23
 
19
24
  logger:
20
25
  enabled: True
@@ -9,22 +9,22 @@
9
9
  # <red> <green> <yellow> <reset>
10
10
  #
11
11
  # 2. GlobalConfig (config)
12
- # Provides server-wide configuration values. Syntax: {field}
12
+ # Provides server-wide configuration values. Syntax: {{field}}
13
13
  # Examples:
14
- # {server_name}
15
- # {panel_url}
14
+ # {{server_name}}
15
+ # {{panel_url}}
16
16
  #
17
17
  # 3. MessagesConfig (keys)
18
- # Provides message templates. Syntax: {field}
18
+ # Provides message templates. Syntax: {{field}}
19
19
  # Examples:
20
- # {prefix}
21
- # {broadcast_restart_at}
20
+ # {{prefix}}
21
+ # {{broadcast_restart_at}}
22
22
  #
23
23
  # 4. WatcherConfig (config)
24
- # Provides thresholds, weights, and timing values. Syntax: {field}
24
+ # Provides thresholds, weights, and timing values. Syntax: {{field}}
25
25
  # Examples:
26
- # {threshold_ram}
27
- # {low_gap_minutes}
26
+ # {{threshold_ram}}
27
+ # {{low_gap_minutes}}
28
28
  #
29
29
  # 5. TimeMap (dynamic)
30
30
  # Provides live timestamps. Syntax: %field%
@@ -41,11 +41,11 @@
41
41
  prefix: '<aqua>[Server Watcher]'
42
42
  bullet: '-'
43
43
 
44
- broadcast_restart_at: '{prefix} The server will restart at {time} CDT.'
44
+ broadcast_restart_at: '{{prefix}} The server will restart at {{time}} CDT.'
45
45
 
46
46
  broadcast_templates:
47
- minutes: '{prefix} Restart in {n} minute{s}!'
48
- seconds: '{prefix} <red>Restarting in {n} second{s}!'
47
+ minutes: '{{prefix}} Restart in {{n}} minute{{s}}!'
48
+ seconds: '{{prefix}} <red>Restarting in {{n}} second{{s}}!'
49
49
 
50
50
  broadcast_minutes: {}
51
51
  broadcast_seconds: {}
@@ -55,25 +55,25 @@ logging:
55
55
  status_check: 'Checking server status...'
56
56
  validation_fail: 'Validation FAILED.'
57
57
  validation_ok: 'All validation checks succeeded.'
58
- sampling_start: 'Starting sampling process. This should take about {duration} seconds...'
58
+ sampling_start: 'Starting sampling process. This should take about {{duration}} seconds...'
59
59
  shutdown: 'Shutting down ServerWatcher.'
60
60
  immediate_restart: 'Restarting immediately.'
61
61
  no_restart: 'The server does not need to restart.'
62
62
  scheduled: 'Restart needed, but anti-restart factors outweigh it.'
63
- gap_low: 'Gap {gap}. Scheduling restart in 2 hours.'
64
- gap_high: 'Gap {gap}. Scheduling restart in 1 hour.'
63
+ gap_low: 'Gap {{gap}}. Scheduling restart in 2 hours.'
64
+ gap_high: 'Gap {{gap}}. Scheduling restart in 1 hour.'
65
65
 
66
66
  reasons:
67
67
  pro_splash: 'PRO-RESTART REASONS:'
68
68
  anti_splash: 'ANTI-RESTART REASONS:'
69
69
 
70
70
  restart_soon: 'The server is set to restart soon'
71
- ram: 'RAM usage ({ram}) is higher than {threshold} GB'
72
- cpu: 'CPU usage ({cpu}) is higher than {threshold}%'
73
- uptime: 'Uptime {uptime} exceeds {threshold}h'
74
- tps: 'TPS {tps} is lower than {threshold}'
75
- low_uptime: 'Uptime {uptime} is shorter than 30m'
76
- players: 'There {verb} {count} {plural} online' # produces: 'There are 2 players online' or 'There is 1 player online'
71
+ ram: 'RAM usage ({{ram}}) is higher than {{threshold}} GB'
72
+ cpu: 'CPU usage ({{cpu}}) is higher than {{threshold}}%'
73
+ uptime: 'Uptime {{uptime}} exceeds {{threshold}}h'
74
+ tps: 'TPS {{tps}} is lower than {{threshold}}'
75
+ low_uptime: 'Uptime {{uptime}} is shorter than 30m'
76
+ players: 'There {{verb}} {{count}} {{plural}} online' # produces: 'There are 2 players online' or 'There is 1 player online'
77
77
 
78
78
  pro_restart_number: 'Pro-restart: '
79
79
  anti_restart_number: 'Anti-restart:'
@@ -0,0 +1,77 @@
1
+ @command('stats') # removed requires_children=True, the DSL should interpret no logic as requiring children
2
+ def stats(self):
3
+ '''
4
+ Retrieve and print server statistics
5
+ '''
6
+
7
+
8
+ @stats.child('get') # removed requires_arguments=False, the DSL should interpret logic for both as supporting both args and noargs. that and having arg=None. If it didn't support arguments it would just be self right? And if it required arguments it would have arg, not arg=None right?
9
+ def stats_get(self, arg=None):
10
+ '''
11
+ Retrieve and print all or specific server statistics
12
+ '''
13
+ # the below will render as not having indents correct? or not?
14
+ __args__ = '''
15
+ ram: [rounding] [--raw]
16
+ cpu: [rounding]
17
+ uptime: [rounding] [mode]
18
+ players
19
+ version
20
+ platform
21
+ '''
22
+ self.watcher.server.refresh()
23
+
24
+ if arg is None:
25
+ return # will add support later for showing all stats, but this acts as a placeholder for the DLS to know it supports optional arguments.
26
+
27
+ gb = not raw()
28
+ fmt = not raw()
29
+
30
+ unit = ''
31
+ match arg:
32
+ case 'ram':
33
+ value = self.watcher.server.getRAM(rounding=rounding(), gb=gb)
34
+ name = 'RAM'
35
+ unit = ' GB' if gb else ' MB'
36
+ case 'cpu':
37
+ value = self.watcher.server.getCPU(rounding=rounding())
38
+ name = 'CPU'
39
+ unit = '%'
40
+ case 'uptime':
41
+ value = self.watcher.server.getUptime(formatted=fmt)
42
+ name = 'Uptime'
43
+ unit = '' if fmt else 'ms'
44
+ case 'tps':
45
+ value = self.watcher.server.getTPS(rounding=rounding(), mode=mode())
46
+ name = 'TPS'
47
+ case 'players':
48
+ value = self.watcher.server.getPlayers()
49
+ name = 'Players'
50
+ case 'version':
51
+ value = self.watcher.server.version
52
+ name = 'Minecraft version'
53
+ case 'platform':
54
+ value = self.watcher.server.platform
55
+ name = 'Server platform'
56
+ case _:
57
+ return self.safePrint('Unknown stat')
58
+
59
+ self.bprint(f'{name}: {value}{unit}')
60
+
61
+
62
+ @stats.get.param('rounding', type=int, default=2)
63
+ def rounding(value):
64
+ '''The decimal place to round to''' # yes, descriptions need to be supported for flags and params too.
65
+ return value
66
+
67
+
68
+ @stats.get.param('mode', type=str, default='current')
69
+ def mode(value):
70
+ '''The mode for TPS. Accepted: current, 1m, 5m, tick_time'''
71
+ return value
72
+
73
+
74
+ @stats.get.flag('raw')
75
+ def raw():
76
+ '''Return the raw value instead of the calculated or formatted string'''
77
+ return True