Skip to content

Commit d687402

Browse files
authored
feat: add spam detection event and cache handling command (#3)
* 🌟 feat: expand client intents for moderation * 🌟 feat: add message utils * 🌟 feat: add time constants for easier time calculations * 🌟 feat: add spam detection channel and role IDs to environment configuration * 🌟 feat: implement spam detection utilities for message filtering * 🌟 feat: implement MessageCache with LRU eviction and message management * 🌟 feat: add logging functionality for spam detection events * πŸ”¨ refactor: fix typo contants -> constants * 🌟 feat: implement action handlers for spam detection with message deletion and user muting * πŸ”¨ refactor: remove console log from default log function * πŸ”¨ refactor(app): update high frequency action to not delete messages and set mute duration to 30 minutes * 🌟 feat: add rules configuration for spam detection * 🌟 feat: add MAX_RULE_TIMEFRAME constant for spam detection rules * 🌟 feat: implement checkRules and checkRule functions for spam detection * 🌟 feat: add messages cache command with stats, clear, and remove expired options * 🌟 feat: implement spam detection event for message creation * 🌟 feat: add spam detection event to the events list * 🌟 feat: add messagesCacheCommand to the commands list * 🌟 feat: add permission checks for messages cache command execution * πŸ”¨ refactor: update swap function parameter names for clarity * πŸ”¨ refactor: change variable name in getUserMessages filter from msg -> message * πŸ”¨ refactor: rename variable msg -> message * πŸ”¨ refactor: use a function block instead of 1 line return in createStatComponent function * πŸ”¨ refactor: remove WEEK and MONTH constants * πŸ”¨ refactor: rename variable msg to message for consistency * πŸ”¨ refactor: rename variable msg to message for consistency * 🌟 feat: add handleSpoilerHackAction and integrate into rules * πŸ”¨ refactor: consolidate role check conditions for clarity * πŸ”¨ refactor: rename messagesMd to logMessagesFormatters for clarity * πŸ”¨ refactor: ename variable msg to message * 🚨 test: add unit tests for stripCode, stripEmoji, and replaceSpoilerHack functions
1 parent 6ab78ab commit d687402

20 files changed

Lines changed: 1050 additions & 4 deletions

File tree

β€Ž.env.local.exampleβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
DISCORD_TOKEN=your_bot_token_here
77
CLIENT_ID=your_client_id_here
88
SERVER_ID=your_server_id_here
9+
SPAM_DETECTION_CHANNEL_ID=your_channel_id_here
10+
ROLE_REGULAR_ID=your_regular_role_id_here
911

1012
# Database Configuration (Optional - uncomment and add to config.ts when needed)
1113
# DATABASE_URL=postgresql://user:password@localhost:5432/botdb

β€Ž.github/workflows/deploy.ymlβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ jobs:
8383
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
8484
CLIENT_ID=${{ secrets.CLIENT_ID }}
8585
SERVER_ID=${{ secrets.SERVER_ID }}
86+
SPAM_DETECTION_CHANNEL_ID=${{ secrets.SPAM_DETECTION_CHANNEL_ID }}
87+
ROLE_REGULAR_ID=${{ secrets.ROLE_REGULAR_ID }}
8688
EOF
8789
8890
echo "🐳 Stopping existing containers..."

β€ŽREADME.mdβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ A TypeScript Discord bot built with Discord.js v14, designed for server moderati
4141
DISCORD_TOKEN=your_bot_token_here
4242
CLIENT_ID=your_client_id_here
4343
SERVER_ID=your_guild_id_here
44+
SPAM_DETECTION_CHANNEL_ID=your_spam_detection_channel_id_here
45+
ROLE_REGULAR_ID=your_regular_role_id_here
4446
```
4547

4648
4. **Build and run**

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:ci": "rm -rf dist && NODE_ENV=production tsc --outDir dist",
99
"start:ci": "NODE_ENV=production node dist/index.js ",
1010
"dev": "NODE_ENV=development tsx --watch src/index.ts",
11-
"test": "tsx --test **/*.test.ts",
11+
"test": "tsx --test src/**/*.test.ts tests/*.test.ts",
1212
"lint": "biome lint .",
1313
"lint:fix": "biome lint --fix .",
1414
"format": "biome format --write .",

0 commit comments

Comments
Β (0)