Skip to content

Commit 2f4d9d0

Browse files
committed
fix: validate config for wildcard groups and default users, update effective groups logic
1 parent d2ab96b commit 2f4d9d0

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ function validateConfig(cfg: AppConfig): void {
145145
throw new Error('At least one group must have users configured');
146146
}
147147

148+
const hasWildcardGroup = cfg.groups.some(g => g.users?.some(u => u.username === '*'));
149+
const hasDefaultUsers = (cfg.users || []).length > 0;
150+
if (hasWildcardGroup && !hasDefaultUsers) {
151+
throw new Error('Groups use wildcard "*" but no top-level users are configured');
152+
}
153+
148154
if (cfg.discord.enabled) {
149155
if (!cfg.discord.token) {
150156
throw new Error('Discord is enabled but token is missing');
@@ -215,7 +221,15 @@ export function getConfig(): AppConfig {
215221

216222
export function getEffectiveGroups(): GroupConfig[] {
217223
const cfg = getConfig();
218-
return cfg.groups || [];
224+
const defaultUsers = cfg.users || [];
225+
const groups = cfg.groups || [];
226+
return groups.map(g => {
227+
if (!g.users) return g;
228+
const hasWildcard = g.users.some(u => u.username === '*');
229+
if (!hasWildcard) return g;
230+
const filtered = g.users.filter(u => u.username !== '*');
231+
return { ...g, users: [...filtered, ...defaultUsers] };
232+
});
219233
}
220234

221235
export function getAllMonitoredUsers(): Array<{ username: string; groups: string[] }> {
@@ -282,6 +296,7 @@ export function saveConfig(newConfig: AppConfig): void {
282296
rawConfigData.pollIntervalMinutes = newConfig.pollIntervalMinutes;
283297
rawConfigData.maxPostsPerFetch = newConfig.maxPostsPerFetch;
284298
rawConfigData.maxTweetAgeMinutes = newConfig.maxTweetAgeMinutes;
299+
rawConfigData.users = newConfig.users;
285300
rawConfigData.groups = newConfig.groups;
286301

287302
const ext = path.extname(loadedConfigPath).toLowerCase();

0 commit comments

Comments
 (0)