refactor(config): share config path resolution and JSON loading via ConfigFile - #165
Merged
Merged
Conversation
…onfigFile Config, AccessManager, SourcemodConfig and TriggerManager each repeated the same four lines of config_folder/config_filename/config_filepath resolution, and three of them repeated the same json.load(..., object_pairs_hook= OrderedDict) call. Extracted a ConfigFile base that owns both, and made the four classes inherit it. Logger names are unchanged because logging.getLogger(self.__class__.__name__) still resolves to the subclass. Error-handling semantics are deliberately left exactly as they were: Config and SourcemodConfig still catch ValueError and return 1, AccessManager and TriggerManager still propagate. Unifying those is a behavior decision (fail fast vs tolerate) that belongs in its own change, not smuggled into a dedup refactor. Bumps VERSION to 1.8.18. Closes #153 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Dolly132 <109222243+Dolly132@users.noreply.github.com>
Rushaway
commented
Sep 5, 2026
Rushaway
left a comment
Member
Author
There was a problem hiding this comment.
Self-review: two judgment calls worth your eyes. (1) I did not subclass Config as the issue suggested -- two of these classes already hold a Config as self.config, so that would have collided; a separate ConfigFile base avoids it. (2) I kept the inconsistent error handling exactly as-is and split it to a follow-up issue, because making a config typo newly refuse to start the bot is an operator-facing behavior change, not a refactor. Verified equivalence against the real config files and against malformed input per class.
This was referenced Sep 5, 2026
Dolly132
added a commit
to Dolly132/torchlight
that referenced
this pull request
Sep 6, 2026
Dolly132
approved these changes
Sep 6, 2026
Dolly132
left a comment
Collaborator
There was a problem hiding this comment.
Tested, works fine as intended.
This was referenced Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Config,AccessManager,SourcemodConfigandTriggerManagereach repeated the same four lines ofconfig_folder/config_filename/config_filepathresolution, and three of them repeated the samejson.load(..., object_pairs_hook=OrderedDict)call.ConfigFilebase inConfig.pythat owns path resolution plus aload_json(ordered=...)helper, and made all four inherit from it.logging.getLogger(self.__class__.__name__)still resolves to the subclass.Composition vs inheritance
The issue suggested "compose or subclass
Config". SubclassingConfigitself would have been wrong here —SourcemodConfigandTriggerManageralready take aConfiginstance and store it asself.config, so inheritingConfigwould have madeself.configmean two different things in the same object. Hence a separateConfigFilebase holding only the file concern.Error handling deliberately left alone
The issue also noted the inconsistent error handling. I did not unify it here:
Config/SourcemodConfigstill catchValueErrorand return1,AccessManager/TriggerManagerstill propagate. Picking one is a behavior decision affecting server operators, so it's split out into #164 rather than smuggled into a dedup refactor.Closes #153
Test plan
config/with identical results: 16 config keys, 1 admin, 21 SM flags, 11 voice triggers.Config,AccessManager,SourcemodConfig,TriggerManager).OrderedDictbehavior preserved where it applied.Config→1,SourcemodConfig→1,AccessManager→ raises,TriggerManager→ raises.🤖 Generated with Claude Code