Skip to content

Commit 6f71cb1

Browse files
authored
Fix ticket/verification/reactroles stability, panel health, and dashboard helpers. (#117)
Restore broken ticket handlers, fix ticket button errors, add panel status guards with repost UX, startup health/sync jobs, database module split, CI tests, and shared dashboard session helper.
1 parent bbd1a06 commit 6f71cb1

21 files changed

Lines changed: 2269 additions & 933 deletions

File tree

.github/workflows/tests.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
- mitchwork
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
cache: npm
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run tests
29+
run: npm test

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ docker pull ghcr.io/codebymitch/titanbot:main
184184

185185
### Running in multiple servers (optional)
186186

187-
Most users run TitanBot on a **single server** with `GUILD_ID` set (default tutorial setup). If you want slash commands to work in **every server** the bot is invited to, opt in with:
187+
Most users run TitanBot on a **single server** with `GUILD_ID` set (default tutorial setup). If you want commands to work in **every server** the bot is invited to, opt in with:
188188

189189
```env
190190
MULTI_GUILD=true
@@ -206,9 +206,9 @@ Notes for multi-server mode:
206206
psql -c "GRANT ALL PRIVILEGES ON DATABASE titanbot TO titanbot;"
207207
```
208208

209-
5. **Test Database Connection**
209+
5. **Verify Database Setup**
210210
```bash
211-
npm run test-postgres
211+
npm run migrate:check
212212
```
213213

214214
6. **Start the Bot**

roadmap.txt

Lines changed: 31 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,59 @@
1-
TitanBot Roadmap / Structure Overview
1+
TitanBot Roadmap / Structure Overview
22

33
Goal
44
- Keep this as a practical map of the codebase.
55
- Show main folders and important files only (not every file).
6-
- Document all implemented systems and features.
76

87
Root
98
- index.js -> process entry point
10-
- package.json -> scripts, dependencies, project metadata (v2.0.0)
9+
- package.json -> scripts, dependencies, project metadata
1110
- README.md -> setup and usage docs
1211
- SECURITY.md -> security policy
1312
- scripts/ -> utility/maintenance scripts (backup, restore, migrate)
1413
- logs/ -> runtime log output
1514
- src/ -> main bot application code
16-
- tests/ -> test suite (17 tests for core systems)
15+
- tests/ -> unit tests (run via npm test)
1716

1817
src/
1918
- app.js -> creates client, initializes systems, starts web server
2019

21-
- commands/ -> slash command categories (19 feature modules)
22-
- Core/ -> essential bot commands (help, ping, stats, uptime, invite)
23-
- Community/ -> application management system + dashboards
24-
- modules/app_dashboard.js -> interactive applications management UI
20+
- commands/ -> slash command categories by feature
21+
- Core/ -> help, ping, stats, uptime, invite
22+
- Community/ -> application management + dashboards
2523
- Logging/ -> audit logging + event management
26-
- modules/logging_dashboard.js -> logging configuration dashboard
27-
- modules/logging_filter.js -> ignore list management
28-
- modules/logging_setchannel.js -> log channel configuration
29-
- Ticket/ -> support ticket system + management
30-
- modules/ticket_dashboard.js -> ticket system configuration dashboard
24+
- modules/logging_dashboard.js
25+
- modules/logging_setchannel.js
26+
- Ticket/ -> support ticket system + dashboard
3127
- ServerStats/ -> server stats channel system
32-
- Economy/ -> economy system (currency, shop, transactions)
33-
- Moderation/ -> moderation/admin commands (ban, warn, kick, mute)
28+
- Economy/ -> economy system
29+
- Moderation/ -> moderation/admin commands
3430
- Verification/ -> member verification flow
3531
- JoinToCreate/ -> dynamic voice channel creation
3632
- Reaction_roles/ -> automatic role assignment
37-
- Birthday/ -> birthday tracking and announcements
38-
- Fun/ -> entertainment/game commands
39-
- Giveaway/ -> giveaway management system
40-
- Leveling/ -> xp and level system
41-
- Search/ -> search functionality
42-
- Tools/ -> utility tools
43-
- Utility/ -> general utility commands
44-
- Voice/ -> voice channel features
45-
- Welcome/ -> welcome message system
33+
- Birthday/, Fun/, Giveaway/, Leveling/, Search/, Tools/, Utility/, Welcome/
4634

4735
- config/ -> centralized configuration modules
48-
- application.js -> main application config loader
49-
- bot.js -> bot settings, embed colors/theme, presence, feature flags
50-
- postgres.js -> PostgreSQL connection config and pool settings
51-
- schemaVersion.js -> database schema version tracking
52-
- shop/ -> shop item definitions and economy config
53-
54-
- events/ -> Discord event listeners (13 event handlers)
55-
- ready.js -> bot startup initialization
56-
- interactionCreate.js -> slash command/button/modal interaction handler
57-
- messageCreate.js -> message processing and prefix commands
58-
- messageDelete.js -> message deletion logging
59-
- messageUpdate.js -> message edit logging
60-
- guildMemberAdd.js -> new member join handling
61-
- guildMemberRemove.js -> member leave handling
62-
- guildMemberUpdate.js -> member profile change handling
63-
- voiceStateUpdate.js -> voice channel join/leave handling
64-
- roleCreate.js -> role creation logging
65-
- roleDelete.js -> role deletion logging
66-
- userUpdate.js -> user profile change logging
67-
- channelDelete.js -> channel deletion logging
68-
36+
- events/ -> Discord event listeners
6937
- handlers/ -> interaction routing and component handlers
70-
- commandLoader.js -> loads all slash commands at startup
71-
- commands.js -> slash command execution router
38+
- commandLoader.js -> loads slash commands at startup
7239
- events.js -> Discord event listener registration
73-
- interactions.js -> button/select menu/modal interaction router
74-
- interactionHandlers/ -> specific interaction handler modules
75-
- calculateButtons.js -> calculator button interactions
76-
- calculateModals.js -> calculator modal interactions
77-
- countdownButtons.js -> countdown timer button handlers
78-
- counterButtons.js -> counter system button handlers
79-
- giveawayButtons.js -> giveaway participation handlers
80-
- helpButtons.js -> help command buttons
81-
- helpSelectMenus.js -> help command select menus
82-
- loggingButtons.js -> logging dashboard buttons
83-
- reactionRoles.js -> reaction role assignment handlers
84-
- ticketButtons.js -> ticket system button handlers
85-
- todoButtons.js -> todo system button handlers
86-
- verificationButtons.js -> verification button handlers
87-
- wipedataButtons.js -> wipe data confirmation handlers
88-
89-
- interactions/ -> Discord interaction-specific handlers
90-
- buttons/ -> button component response handlers
91-
- modals/ -> modal form submission handlers
92-
- selectMenus/ -> select menu choice handlers
93-
94-
- services/ -> business logic + data operations (22 service modules)
95-
- database.js -> storage abstraction layer
96-
- guildConfig.js -> guild-level settings persistence
97-
- applicationService.js -> application role management
98-
- birthdayService.js -> birthday tracking and notifications
99-
- configService.js -> configuration management
100-
- economy.js -> economy system operations
101-
- economyService.js -> economy service layer
102-
- giveawayService.js -> giveaway management and scheduling
103-
- joinToCreateService.js -> dynamic voice channel creation
104-
- leveling.js -> user leveling system
105-
- loggingService.js -> audit logging service
106-
- moderationService.js -> moderation operations (warnings, bans, etc)
107-
- reactionRoleService.js -> reaction role assignment
108-
- serverstatsService.js -> server statistics tracking
109-
- shopService.js -> economy shop management
110-
- ticket.js -> ticket system operations
111-
- utilityService.js -> utility helper functions
112-
- verificationService.js -> member verification
113-
- voiceService.js -> voice channel operations
114-
- warningService.js -> user warning system
115-
- welcomeService.js -> welcome message system
116-
- xpSystem.js -> experience points calculation
117-
118-
- utils/ -> shared helpers and utilities (20+ utility modules)
119-
- logger.js -> logging system with file rotation
120-
- embeds.js -> standardized embed creation helpers
121-
- components.js -> Discord button/select menu/modal builders
122-
- helpers.js -> general purpose helper functions
123-
- constants.js -> application constants and enums
124-
- errorHandler.js -> custom error handling and error registry
125-
- errorRegistry.js -> error message registry
126-
- permissionGuard.js -> permission checking utilities
127-
- interactionHelper.js -> safe interaction response utilities
128-
- interactionValidator.js -> interaction input validation
129-
- database.js -> database utility functions
130-
- postgresDatabase.js -> PostgreSQL-specific operations
131-
- memoryStorage.js -> in-memory fallback storage
132-
- dateUtils.js -> date/time helper functions
133-
- messageTemplates.js -> message template definitions
134-
- abuseProtection.js -> rate limiting and abuse detection
135-
- commandInputValidation.js -> Zod schema validation
136-
- moderation.js -> moderation utility functions
137-
- economy.js -> economy calculation helpers
138-
- giveaways.js -> giveaway scheduling helpers
139-
- loggingUi.js -> logging dashboard UI builders
140-
- rateLimiter.js -> cooldown and rate limit management
141-
142-
Database Abstraction Layer
143-
- Supports PostgreSQL (primary) with in-memory fallback for development
144-
- Graceful degradation: if PostgreSQL unavailable, bot switches to in-memory mode
40+
- interactions.js -> button/select/modal router
41+
- ticketButtons.js, reactionRoles.js, etc.
42+
43+
- interactions/ -> button, modal, and select menu handlers
44+
- services/ -> business logic + data operations
45+
- utils/ -> shared helpers
46+
- database.js -> facade re-exporting database modules
47+
- database/wrapper.js -> DatabaseWrapper, get/set helpers
48+
- database/keys.js -> Redis-style key builders
49+
- database/tickets.js -> ticket persistence + guild ticket stats
50+
- panelStatus.js -> shared panel message detection
51+
- errorHandler.js, logger.js, embeds.js, etc.
52+
53+
Database
54+
- PostgreSQL (primary) with in-memory fallback for development
55+
- Graceful degradation when PostgreSQL is unavailable
14556

14657
Notes
147-
- This project is modular by feature area: commands -> handlers -> services -> utils
58+
- Modular by feature area: commands -> handlers -> services -> utils
14859
- bot.js is the single source of truth for embed theming/colors and core bot config
149-
- We might not have everything done as mentioned in the roadmap.txt or some new features which is not mentioned in roadmap.txt

src/app.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { checkBirthdays } from './services/birthdayService.js';
1313
import { checkGiveaways } from './services/giveawayService.js';
1414
import { loadCommands, registerCommands as registerSlashCommands } from './handlers/commandLoader.js';
1515
import pkg from '../package.json' with { type: 'json' };
16+
import { EXPECTED_SCHEMA_VERSION, EXPECTED_SCHEMA_LABEL } from './config/schemaVersion.js';
1617

1718
class TitanBot extends Client {
1819
constructor() {
@@ -171,19 +172,33 @@ class TitanBot extends Client {
171172
});
172173

173174
app.get('/ready', (req, res) => {
174-
const dbStatus = this.db?.getStatus?.() || { isDegraded: true };
175+
const dbStatus = this.db?.getStatus?.() || { isDegraded: true, connectionType: 'none' };
175176
const isReady = this.isReady() && !dbStatus.isDegraded;
176177

178+
const metrics = {
179+
guildCount: this.guilds?.cache?.size ?? 0,
180+
commandCount: this.commands?.size ?? 0,
181+
database: {
182+
mode: dbStatus.connectionType,
183+
degraded: dbStatus.isDegraded,
184+
degradedReason: dbStatus.degradedReason ?? null,
185+
},
186+
schemaVersion: EXPECTED_SCHEMA_VERSION,
187+
schemaLabel: EXPECTED_SCHEMA_LABEL,
188+
};
189+
177190
if (isReady) {
178191
return res.status(200).json({
179192
ready: true,
180-
message: 'Bot is ready'
193+
message: 'Bot is ready',
194+
metrics,
181195
});
182196
}
183197

184198
res.status(503).json({
185199
ready: false,
186-
reason: !this.isReady() ? 'Bot not Ready' : 'Database degraded'
200+
reason: !this.isReady() ? 'Bot not Ready' : 'Database degraded',
201+
metrics,
187202
});
188203
});
189204

0 commit comments

Comments
 (0)