fix & refactor: centralize event logging, add DB indexes, fix mute timeout, role menu & owner permission bugs
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 20s
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 20s
This commit is contained in:
@@ -17,8 +17,9 @@ The bot uses a **Modular Command & Event Loading** pattern with **ESM (ECMAScrip
|
||||
8. **Reminder System:** Periodic reminder checking with `target_time` tracking.
|
||||
9. **Auto-Response System:** Trigger word detection for automatic replies (cached).
|
||||
10. **Welcome/Goodbye System:** Guild member add/remove events with customizable messages.
|
||||
11. **Logging System:** Configurable event logging (messages, roles, moderation, etc.).
|
||||
11. **Logging System:** Configurable event logging (messages, roles, moderation, etc.) via centralized `EventLogger`.
|
||||
12. **Role Selection System:** Self-service role assignment via select menus with support for exclusive categories and max-role limits.
|
||||
13. **Centralized Event Logger:** Kapsel event logs into `EventLogger.sendLog()` to eliminate duplicated logging logic across event files.
|
||||
|
||||
## 📁 Project Structure
|
||||
|
||||
@@ -34,7 +35,8 @@ pixelpoebel/
|
||||
│ └── structures/
|
||||
│ ├── ExtendedClient.ts # Typed client with DB property
|
||||
│ ├── Command.ts
|
||||
│ ├── Database.ts # Database with Transaction & Surgical Caching
|
||||
│ ├── Database.ts # Database with Transaction, Indexes & Surgical Caching
|
||||
│ ├── EventLogger.ts # Centralized event logging helper
|
||||
│ ├── TwitchManager.ts # Batch Polling & Transaction logic
|
||||
│ ├── TwitchMonitor.ts # IRC Monitoring & Webhook reuse
|
||||
│ ├── TwitchCache.ts # IRC Message FIFO Cache
|
||||
@@ -53,7 +55,7 @@ pixelpoebel/
|
||||
|
||||
### 1. Database with Surgical Caching
|
||||
|
||||
The database uses WAL mode and foreign keys. Caching is surgical (clears specific guild entries when possible).
|
||||
The database uses WAL mode, foreign keys, and performance indexes for frequent lookups. Caching is surgical (clears specific guild entries when possible).
|
||||
|
||||
```typescript
|
||||
// src/structures/Database.ts
|
||||
@@ -63,7 +65,7 @@ export class DB {
|
||||
static init() {
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('foreign_keys = ON');
|
||||
// ... Table creation ...
|
||||
// ... Table creation & indexes ...
|
||||
}
|
||||
|
||||
static run(query: string, ...params: any[]) {
|
||||
@@ -144,6 +146,11 @@ if (process.env.AUTO_DEPLOY !== 'false') {
|
||||
2. **Foreign Keys:** Always enable `foreign_keys = ON` to maintain data integrity.
|
||||
3. **Type Safety:** Use `ExtendedClient` instead of `any` for the client instance.
|
||||
4. **Webhook Reuse:** Map `WebhookClient` instances to their monitor keys to prevent leaks.
|
||||
5. **Partial Message Handling:** In `messageDelete` and `messageUpdate` events, always check for null `author` property to avoid runtime crashes on uncached partial messages.
|
||||
5. **Partial Message Handling:** In `messageDelete` and `messageUpdate` events, always handle partial messages safely (e.g. `message.author` or `message.content` may be missing for uncached messages).
|
||||
6. **Centralized Settings Cache:** Always use `client.DB.getSettings(guildId)` instead of raw SQLite select queries for `guild_settings` to leverage central caching and automatic default generation.
|
||||
7. **Category Role Selection Limits:** Do not count general guild roles when checking role selection limits; filter the user's role list using only the specific role IDs registered under that category.
|
||||
8. **Event Logger Centralization:** Use `EventLogger.sendLog(client, guildId, event, embed)` for logging server events instead of inline/duplicated helper functions.
|
||||
9. **Discord Timeout Limit:** Discord API limits timeouts to maximum 28 days (`2419200000 ms`). Never pass `null` to `member.timeout(durationMs)` when muting.
|
||||
10. **Role Menu Error Handling:** Always wrap `member.roles.add` and `member.roles.remove` in `try/catch` blocks in interaction listeners to handle permission/hierarchy errors gracefully.
|
||||
11. **Select Menu Emoji Handling:** Never pass an empty string `''` to `setEmoji()`. Only call `setEmoji()` when a valid, non-empty emoji string is provided.
|
||||
12. **Team Application Owner Support:** When checking bot owner status, check `process.env.BOT_OWNER_ID` or test if `client.application.owner` is a `Team` object with `owner.members.has(userId)`.
|
||||
|
||||
Reference in New Issue
Block a user