Add TwitchMonitor IRC chat logging module
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 21s
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 21s
This commit is contained in:
@@ -12,12 +12,13 @@ The bot uses a **Modular Command & Event Loading** pattern with **ESM (ECMAScrip
|
||||
3. **Interface-Driven Commands:** All commands implement `Command` interface.
|
||||
4. **SQLite Database:** Persistent data storage with `better-sqlite3`.
|
||||
5. **Twitch Monitoring:** Periodic API polling with Stream ID tracking.
|
||||
6. **Reminder System:** Periodic reminder checking with target_time tracking.
|
||||
7. **Auto-Response System:** Trigger word detection for automatic replies.
|
||||
8. **Welcome/Goodbye System:** Guild member add/remove events with customizable messages.
|
||||
9. **Logging System:** Configurable event logging (messages, roles, moderation, etc.).
|
||||
10. **Role Selection System:** Self-service role assignment via select menus.
|
||||
11. **Grouped Commands:** Admin/Owner/Trigger/Timer commands grouped under subcommands.
|
||||
6. **TwitchMonitor IRC:** TMI.js-based IRC chat monitoring for mod events.
|
||||
7. **Reminder System:** Periodic reminder checking with target_time tracking.
|
||||
8. **Auto-Response System:** Trigger word detection for automatic replies.
|
||||
9. **Welcome/Goodbye System:** Guild member add/remove events with customizable messages.
|
||||
10. **Logging System:** Configurable event logging (messages, roles, moderation, etc.).
|
||||
11. **Role Selection System:** Self-service role assignment via select menus.
|
||||
12. **Grouped Commands:** Admin/Owner/Trigger/Timer commands grouped under subcommands.
|
||||
|
||||
## 📁 Project Structure
|
||||
|
||||
@@ -31,6 +32,7 @@ pixelpoebel/
|
||||
│ │ ├── ping.ts
|
||||
│ │ ├── help.ts
|
||||
│ │ ├── twitch.ts
|
||||
│ │ ├── twitchmonitor.ts # Twitch IRC chat monitoring
|
||||
│ │ ├── rolesetup.ts # Self-service role selection
|
||||
│ │ ├── trigger.ts # Auto-responses
|
||||
│ │ ├── timer.ts # Reminders
|
||||
@@ -54,6 +56,8 @@ pixelpoebel/
|
||||
│ ├── Command.ts
|
||||
│ ├── Database.ts
|
||||
│ ├── TwitchManager.ts
|
||||
│ ├── TwitchMonitor.ts
|
||||
│ ├── TwitchCache.ts
|
||||
│ ├── ReminderManager.ts
|
||||
│ └── Deployer.ts
|
||||
├── data/ # SQLite database (volume mounted)
|
||||
@@ -136,7 +140,7 @@ CREATE TABLE dm_users (
|
||||
last_seen DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- twitch_monitors
|
||||
-- twitch_monitors (Stream notifications)
|
||||
CREATE TABLE twitch_monitors (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
guild_id TEXT,
|
||||
@@ -148,6 +152,16 @@ CREATE TABLE twitch_monitors (
|
||||
UNIQUE(guild_id, channel_name)
|
||||
);
|
||||
|
||||
-- twitch_monitor_channels (IRC chat logging)
|
||||
CREATE TABLE twitch_monitor_channels (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
guild_id TEXT NOT NULL,
|
||||
twitch_channel TEXT NOT NULL,
|
||||
discord_channel_id TEXT NOT NULL,
|
||||
webhook_url TEXT,
|
||||
UNIQUE(guild_id, twitch_channel)
|
||||
);
|
||||
|
||||
-- auto_responses
|
||||
CREATE TABLE auto_responses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -355,12 +369,61 @@ if (wasOffline || (monitor.last_status === 'online' && isNewStream)) {
|
||||
}
|
||||
```
|
||||
|
||||
### 9. Configurable Warn System
|
||||
### 9. TwitchMonitor IRC Chat Logging
|
||||
|
||||
**Database Schema:**
|
||||
- `warn_threshold`: Number of warns before action
|
||||
- `warn_action`: 'none', 'kick', 'mute', 'ban'
|
||||
- `warn_mute_duration`: Duration in seconds for mute
|
||||
**Overview:** Uses TMI.js to connect to Twitch IRC as a "lurker" (read-only) and logs moderation events to Discord via webhooks.
|
||||
|
||||
**Architecture:**
|
||||
```typescript
|
||||
// Singleton pattern for IRC connection
|
||||
class TwitchMonitor {
|
||||
private static instance: TwitchMonitor | null = null;
|
||||
private client: tmi.Client;
|
||||
private cache: TwitchCache; // In-memory FIFO ring buffer (default: 1000 messages)
|
||||
private monitors: Map<string, MonitorChannel>;
|
||||
}
|
||||
```
|
||||
|
||||
**TwitchCache (In-Memory Ring Buffer):**
|
||||
```typescript
|
||||
interface ChatMessage {
|
||||
channel: string; // twitch channel
|
||||
user: string;
|
||||
text: string;
|
||||
timestamp: number;
|
||||
msgId: string;
|
||||
}
|
||||
|
||||
class TwitchCache {
|
||||
private buffer: ChatMessage[] = [];
|
||||
private maxSize: number = 1000;
|
||||
|
||||
push(msg: ChatMessage): void { /* FIFO - shift oldest when full */ }
|
||||
getLastN(user: string, channel: string, n: number): ChatMessage[] { /* for ban context */ }
|
||||
getByMsgId(msgId: string): ChatMessage | undefined { /* for delete restore */ }
|
||||
}
|
||||
```
|
||||
|
||||
**Events Logged:**
|
||||
| Event | Discord Embed |
|
||||
|-------|--------------|
|
||||
| `ban` | 🔨 Ban - mit letzten 5 Nachrichten als Kontext |
|
||||
| `timeout` | ⏱️ Timeout |
|
||||
| `messagedeleted` | 🗑️ Delete - ~~text~~ (aus Cache wiederhergestellt) |
|
||||
| `cheer` | 💰 Bits |
|
||||
| `subscription` | 🅿️ Sub |
|
||||
|
||||
**Mod-Icon:** `https://static-cdn.jtvnw.net/jtv_user_pictures/a736384e-8a1d-40ed-8a7a-808a23a15476-profile_image-300x300.png`
|
||||
|
||||
**Commands:**
|
||||
```typescript
|
||||
/twitchmonitor add <twitch_channel> <discord_channel> // Admin
|
||||
/twitchmonitor remove <twitch_channel> // Admin
|
||||
/twitchmonitor list // Public
|
||||
/twitchmonitor help // Public
|
||||
```
|
||||
|
||||
### 10. Configurable Warn System
|
||||
|
||||
**Auto-Action Logic:**
|
||||
```typescript
|
||||
@@ -487,6 +550,7 @@ docker-compose up -d --build
|
||||
| `/ping` | – | Public |
|
||||
| `/help` | – | Public |
|
||||
| `/twitch` | online, add, remove, list, listall, help | Public/Admin |
|
||||
| `/twitchmonitor` | add, remove, list, help | Admin |
|
||||
| `/rolesetup` | create, add, edit, remove, delete, config, list | Admin |
|
||||
| `/trigger` | add, remove, list, help | Public/Admin |
|
||||
| `/timer` | add, remove, list, listall, help | Public/Admin |
|
||||
|
||||
Reference in New Issue
Block a user