Implement GuardDen Discord moderation bot
Features: - Core moderation: warn, kick, ban, timeout, strike system - Automod: banned words filter, scam detection, anti-spam, link filtering - AI moderation: Claude/OpenAI integration, NSFW detection, phishing analysis - Verification system: button, captcha, math, emoji challenges - Rate limiting system with configurable scopes - Event logging: joins, leaves, message edits/deletes, voice activity - Per-guild configuration with caching - Docker deployment support Bug fixes applied: - Fixed await on session.delete() in guild_config.py - Fixed memory leak in AI moderation message tracking (use deque) - Added error handling to bot shutdown - Added error handling to timeout command - Removed unused Literal import - Added prefix validation - Added image analysis limit (3 per message) - Fixed test mock for SQLAlchemy model
This commit is contained in:
48
tests/test_utils.py
Normal file
48
tests/test_utils.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for utility functions."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from guardden.cogs.moderation import parse_duration
|
||||
|
||||
|
||||
class TestParseDuration:
|
||||
"""Tests for the parse_duration function."""
|
||||
|
||||
def test_parse_seconds(self) -> None:
|
||||
"""Test parsing seconds."""
|
||||
assert parse_duration("30s") == timedelta(seconds=30)
|
||||
assert parse_duration("1s") == timedelta(seconds=1)
|
||||
|
||||
def test_parse_minutes(self) -> None:
|
||||
"""Test parsing minutes."""
|
||||
assert parse_duration("5m") == timedelta(minutes=5)
|
||||
assert parse_duration("30m") == timedelta(minutes=30)
|
||||
|
||||
def test_parse_hours(self) -> None:
|
||||
"""Test parsing hours."""
|
||||
assert parse_duration("1h") == timedelta(hours=1)
|
||||
assert parse_duration("24h") == timedelta(hours=24)
|
||||
|
||||
def test_parse_days(self) -> None:
|
||||
"""Test parsing days."""
|
||||
assert parse_duration("7d") == timedelta(days=7)
|
||||
assert parse_duration("1d") == timedelta(days=1)
|
||||
|
||||
def test_parse_weeks(self) -> None:
|
||||
"""Test parsing weeks."""
|
||||
assert parse_duration("2w") == timedelta(weeks=2)
|
||||
assert parse_duration("1w") == timedelta(weeks=1)
|
||||
|
||||
def test_invalid_format(self) -> None:
|
||||
"""Test invalid duration formats."""
|
||||
assert parse_duration("invalid") is None
|
||||
assert parse_duration("") is None
|
||||
assert parse_duration("10") is None
|
||||
assert parse_duration("abc") is None
|
||||
|
||||
def test_case_insensitive(self) -> None:
|
||||
"""Test that parsing is case insensitive."""
|
||||
assert parse_duration("1H") == timedelta(hours=1)
|
||||
assert parse_duration("30M") == timedelta(minutes=30)
|
||||
Reference in New Issue
Block a user