dc-securex 2.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dc-securex might be problematic. Click here for more details.
- dc_securex-2.3.4/LICENSE +21 -0
- dc_securex-2.3.4/MANIFEST.in +4 -0
- dc_securex-2.3.4/PKG-INFO +593 -0
- dc_securex-2.3.4/README.md +565 -0
- dc_securex-2.3.4/dc_securex.egg-info/PKG-INFO +593 -0
- dc_securex-2.3.4/dc_securex.egg-info/SOURCES.txt +24 -0
- dc_securex-2.3.4/dc_securex.egg-info/dependency_links.txt +1 -0
- dc_securex-2.3.4/dc_securex.egg-info/requires.txt +2 -0
- dc_securex-2.3.4/dc_securex.egg-info/top_level.txt +1 -0
- dc_securex-2.3.4/pyproject.toml +32 -0
- dc_securex-2.3.4/securex/__init__.py +18 -0
- dc_securex-2.3.4/securex/backup/__init__.py +5 -0
- dc_securex-2.3.4/securex/backup/manager.py +617 -0
- dc_securex-2.3.4/securex/client.py +490 -0
- dc_securex-2.3.4/securex/handlers/__init__.py +8 -0
- dc_securex-2.3.4/securex/handlers/channel.py +115 -0
- dc_securex-2.3.4/securex/handlers/member.py +198 -0
- dc_securex-2.3.4/securex/handlers/role.py +111 -0
- dc_securex-2.3.4/securex/handlers/role_monitor.py +160 -0
- dc_securex-2.3.4/securex/handlers/webhook.py +85 -0
- dc_securex-2.3.4/securex/models.py +123 -0
- dc_securex-2.3.4/securex/utils/__init__.py +5 -0
- dc_securex-2.3.4/securex/utils/punishment.py +123 -0
- dc_securex-2.3.4/securex/utils/whitelist.py +129 -0
- dc_securex-2.3.4/setup.cfg +4 -0
- dc_securex-2.3.4/setup.py +42 -0
dc_securex-2.3.4/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SecureX Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dc-securex
|
|
3
|
+
Version: 2.3.4
|
|
4
|
+
Summary: Backend-only Discord anti-nuke protection SDK
|
|
5
|
+
Home-page: https://github.com/yourusername/securex-antinuke-sdk
|
|
6
|
+
Author: SecureX Team
|
|
7
|
+
Author-email: SecureX Team <contact@securex.dev>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/yourusername/securex-antinuke-sdk
|
|
10
|
+
Project-URL: Repository, https://github.com/yourusername/securex-antinuke-sdk
|
|
11
|
+
Project-URL: Issues, https://github.com/yourusername/securex-antinuke-sdk/issues
|
|
12
|
+
Keywords: discord,bot,antinuke,security,protection,sdk
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: discord.py>=2.0.0
|
|
23
|
+
Requires-Dist: aiofiles>=23.0.0
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
|
|
29
|
+
# SecureX SDK - Ultra-Fast Discord Anti-Nuke Protection
|
|
30
|
+
|
|
31
|
+
**Backend-only Discord anti-nuke protection with 5-10ms response time.** You provide the UI, we provide the security logic.
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/dc-securex/)
|
|
34
|
+
[](https://www.python.org/downloads/)
|
|
35
|
+
|
|
36
|
+
## 🚀 Features
|
|
37
|
+
|
|
38
|
+
### Dual-System Architecture (v2.x)
|
|
39
|
+
- ⚡ **Instant Audit Log Workers** - 5-10ms detection & punishment (100x faster than v1.x)
|
|
40
|
+
- 🔄 **Traditional Event Handlers** - Comprehensive restoration from backups
|
|
41
|
+
- 🎯 **15 Violation Types** - Complete coverage of Discord audit log actions
|
|
42
|
+
- 📊 **3 Independent Workers** - Event, Action, and Log processing in parallel
|
|
43
|
+
|
|
44
|
+
### Protection Features
|
|
45
|
+
✅ **Channel Protection** - Instant detection & restoration of unauthorized changes
|
|
46
|
+
✅ **Role Protection** - Instant punishment + backup restoration
|
|
47
|
+
✅ **Member Protection** - Bot banning, role restoration, ban/kick reverting
|
|
48
|
+
✅ **Webhook Protection** - Spam webhook detection & removal
|
|
49
|
+
✅ **Punishment System** - Configurable kick/ban/timeout actions
|
|
50
|
+
✅ **Role Position Monitoring** - 5-second checks with bulk restore
|
|
51
|
+
✅ **Auto-Backup** - Automatic server backups with 10min refresh
|
|
52
|
+
✅ **Whitelist System** - Manage authorized users
|
|
53
|
+
❌ **No UI** - You design your own interface!
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 📋 Prerequisites
|
|
58
|
+
|
|
59
|
+
Before using SecureX SDK, ensure you have the following:
|
|
60
|
+
|
|
61
|
+
### 1. Discord Bot Setup
|
|
62
|
+
- ✅ Discord Application created at [Discord Developer Portal](https://discord.com/developers/applications)
|
|
63
|
+
- ✅ Bot token obtained from your application
|
|
64
|
+
- ✅ Bot invited to your server with proper permissions
|
|
65
|
+
|
|
66
|
+
### 2. Python Environment
|
|
67
|
+
- ✅ Python 3.8 or higher installed
|
|
68
|
+
- ✅ `discord.py` version 2.0 or higher
|
|
69
|
+
- ✅ `aiofiles` version 23.0 or higher (auto-installed with SDK)
|
|
70
|
+
|
|
71
|
+
### 3. Bot Intents (CRITICAL)
|
|
72
|
+
|
|
73
|
+
Enable these intents in **both** Discord Developer Portal AND your code:
|
|
74
|
+
|
|
75
|
+
**Discord Developer Portal:**
|
|
76
|
+
1. Go to your application → Bot → Privileged Gateway Intents
|
|
77
|
+
2. Enable:
|
|
78
|
+
- ✅ SERVER MEMBERS INTENT
|
|
79
|
+
- ✅ MESSAGE CONTENT INTENT (optional, for commands)
|
|
80
|
+
|
|
81
|
+
**Your Code:**
|
|
82
|
+
```python
|
|
83
|
+
intents = discord.Intents.all() # Recommended for full functionality
|
|
84
|
+
|
|
85
|
+
# Or enable specific intents:
|
|
86
|
+
intents = discord.Intents.default()
|
|
87
|
+
intents.guilds = True # Required
|
|
88
|
+
intents.members = True # Required
|
|
89
|
+
intents.bans = True # Required
|
|
90
|
+
intents.webhooks = True # Required
|
|
91
|
+
intents.message_content = True # Optional (for commands)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 4. Bot Permissions (CRITICAL)
|
|
95
|
+
|
|
96
|
+
Your bot **MUST** have these permissions in your Discord server:
|
|
97
|
+
|
|
98
|
+
| Permission | Purpose | Priority |
|
|
99
|
+
|------------|---------|----------|
|
|
100
|
+
| `VIEW_AUDIT_LOG` | **Critical** - Without this, instant detection won't work | 🔴 REQUIRED |
|
|
101
|
+
| `MANAGE_CHANNELS` | Restore deleted/modified channels | 🔴 REQUIRED |
|
|
102
|
+
| `MANAGE_ROLES` | Restore roles and remove dangerous permissions | 🔴 REQUIRED |
|
|
103
|
+
| `BAN_MEMBERS` | Execute ban punishments | 🟡 Required for bans |
|
|
104
|
+
| `KICK_MEMBERS` | Execute kick punishments | 🟡 Required for kicks |
|
|
105
|
+
| `MODERATE_MEMBERS` | Execute timeout punishments | 🟡 Required for timeouts |
|
|
106
|
+
| `MANAGE_WEBHOOKS` | Remove spam webhooks | 🟢 Optional |
|
|
107
|
+
|
|
108
|
+
**Invite Link Generator:**
|
|
109
|
+
```
|
|
110
|
+
https://discord.com/api/oauth2/authorize?client_id=YOUR_BOT_ID&permissions=8&scope=bot
|
|
111
|
+
```
|
|
112
|
+
Replace `YOUR_BOT_ID` with your bot's client ID. Permission value `8` = Administrator (recommended for testing).
|
|
113
|
+
|
|
114
|
+
### 5. Bot Role Position
|
|
115
|
+
|
|
116
|
+
⚠️ **IMPORTANT**: Your bot's role must be **higher** than the roles it needs to manage/restore!
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
Role Hierarchy Example:
|
|
120
|
+
1. Owner
|
|
121
|
+
2. SecureX Bot ← Must be here
|
|
122
|
+
3. Admin
|
|
123
|
+
4. Moderator
|
|
124
|
+
5. Member
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 6. Server Settings
|
|
128
|
+
|
|
129
|
+
Enable audit log in your Discord server (should be on by default):
|
|
130
|
+
- Server Settings → Audit Log → Ensure it's accessible
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 📦 Installation
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pip install dc-securex
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🎯 Quick Start
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import discord
|
|
146
|
+
from discord.ext import commands
|
|
147
|
+
from securex import SecureX
|
|
148
|
+
|
|
149
|
+
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
|
|
150
|
+
sx = SecureX(bot)
|
|
151
|
+
|
|
152
|
+
@bot.event
|
|
153
|
+
async def on_ready():
|
|
154
|
+
# Enable protection with instant punishments
|
|
155
|
+
await sx.enable(
|
|
156
|
+
punishments={
|
|
157
|
+
"role_create": "kick", # Instant kick for role spam
|
|
158
|
+
"channel_delete": "ban", # Instant ban for channel deletion
|
|
159
|
+
"bot_add": "none" # Bot is instantly banned regardless
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
print("✅ SecureX active with 5-10ms response time!")
|
|
163
|
+
|
|
164
|
+
# Register callback for custom logging/UI
|
|
165
|
+
@sx.on_threat_detected
|
|
166
|
+
async def handle_threat(threat):
|
|
167
|
+
print(f"🚨 {threat.type} by {threat.actor_id}")
|
|
168
|
+
print(f" Punishment: {threat.punishment_action}")
|
|
169
|
+
print(f" Prevented: {threat.prevented}, Restored: {threat.restored}")
|
|
170
|
+
|
|
171
|
+
bot.run("YOUR_TOKEN")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 📚 Complete API Reference
|
|
177
|
+
|
|
178
|
+
### Initialization
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
sx = SecureX(
|
|
182
|
+
bot, # Your discord.py Bot instance
|
|
183
|
+
backup_dir="./data/backups", # Where to store backups
|
|
184
|
+
punishments=None, # Default punishments (optional)
|
|
185
|
+
timeout_duration=600, # Timeout duration in seconds
|
|
186
|
+
notify_user=True # DM punishment notifications
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### `enable()` - Activate Protection
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
await sx.enable(
|
|
194
|
+
guild_id=None, # Specific guild (None = all guilds)
|
|
195
|
+
whitelist=None, # List of authorized user IDs
|
|
196
|
+
auto_backup=True, # Enable automatic backups
|
|
197
|
+
role_position_monitoring=True, # 5-second role position checks
|
|
198
|
+
punishments=None, # Override default punishments
|
|
199
|
+
timeout_duration=600, # Timeout duration
|
|
200
|
+
notify_user=True # DM users about punishment
|
|
201
|
+
)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Punishment Configuration
|
|
205
|
+
|
|
206
|
+
**Available Actions:**
|
|
207
|
+
- `"none"` - No punishment (restoration only)
|
|
208
|
+
- `"warn"` - Warning only
|
|
209
|
+
- `"timeout"` - Timeout member
|
|
210
|
+
- `"kick"` - Kick from server
|
|
211
|
+
- `"ban"` - Ban from server
|
|
212
|
+
|
|
213
|
+
**Violation Types (15 total):**
|
|
214
|
+
|
|
215
|
+
| Category | Violation Type | Description |
|
|
216
|
+
|----------|---------------|-------------|
|
|
217
|
+
| **Bot** | `bot_add` | Unauthorized bot addition (always instant ban) |
|
|
218
|
+
| **Channels** | `channel_create` | Mass channel creation |
|
|
219
|
+
| | `channel_delete` | Channel deletion |
|
|
220
|
+
| | `channel_update` | Permission/name changes |
|
|
221
|
+
| **Roles** | `role_create` | Mass role creation |
|
|
222
|
+
| | `role_delete` | Role deletion |
|
|
223
|
+
| | `role_update` | Permission changes |
|
|
224
|
+
| **Members** | `member_kick` | Unauthorized kicks |
|
|
225
|
+
| | `member_ban` | Unauthorized bans |
|
|
226
|
+
| | `member_unban` | Unauthorized unbans |
|
|
227
|
+
| | `member_update` | Role assignment changes |
|
|
228
|
+
| **Webhooks** | `webhook_create` | Webhook spam |
|
|
229
|
+
| | `webhook_delete` | Webhook deletion |
|
|
230
|
+
| | `webhook_update` | Webhook modifications |
|
|
231
|
+
|
|
232
|
+
**Examples:**
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
# Strict mode - Ban for everything
|
|
236
|
+
await sx.enable(
|
|
237
|
+
punishments={
|
|
238
|
+
"channel_delete": "ban",
|
|
239
|
+
"channel_create": "ban",
|
|
240
|
+
"role_delete": "ban",
|
|
241
|
+
"role_create": "ban",
|
|
242
|
+
"member_update": "ban"
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
# Balanced mode - Kick for spam, ban for destruction
|
|
247
|
+
await sx.enable(
|
|
248
|
+
punishments={
|
|
249
|
+
"channel_delete": "ban",
|
|
250
|
+
"role_delete": "ban",
|
|
251
|
+
"channel_create": "kick",
|
|
252
|
+
"role_create": "kick"
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Timeout mode - 10 minute timeouts
|
|
257
|
+
await sx.enable(
|
|
258
|
+
punishments={
|
|
259
|
+
"channel_delete": "timeout",
|
|
260
|
+
"role_update": "timeout"
|
|
261
|
+
},
|
|
262
|
+
timeout_duration=600
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
# Restoration only - No punishments
|
|
266
|
+
await sx.enable() # All violations default to "none"
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Whitelist Management
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
# Add authorized user
|
|
273
|
+
await sx.whitelist.add(guild_id, user_id)
|
|
274
|
+
|
|
275
|
+
# Remove from whitelist
|
|
276
|
+
await sx.whitelist.remove(guild_id, user_id)
|
|
277
|
+
|
|
278
|
+
# Get all whitelisted users
|
|
279
|
+
users = await sx.whitelist.get_all(guild_id) # Returns: List[int]
|
|
280
|
+
|
|
281
|
+
# Check if user is whitelisted
|
|
282
|
+
is_safe = await sx.whitelist.is_whitelisted(guild_id, user_id) # Returns: bool
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Backup Management
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
# Create manual backup
|
|
289
|
+
backup_info = await sx.create_backup(guild_id)
|
|
290
|
+
# Returns: BackupInfo(guild_id, timestamp, channel_count, role_count, ...)
|
|
291
|
+
|
|
292
|
+
# Backups auto-refresh every 10 minutes when protection is enabled
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Threat History
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
# Get recent threats
|
|
299
|
+
threats = await sx.get_recent_threats(guild_id, limit=10)
|
|
300
|
+
# Returns: List[ThreatEvent]
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 📊 Data Models
|
|
306
|
+
|
|
307
|
+
### ThreatEvent
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
@dataclass
|
|
311
|
+
class ThreatEvent:
|
|
312
|
+
type: str # Violation type (e.g., "channel_delete")
|
|
313
|
+
guild_id: int
|
|
314
|
+
actor_id: int # Who committed the violation
|
|
315
|
+
target_id: int # What was affected
|
|
316
|
+
target_name: str
|
|
317
|
+
prevented: bool # Was it stopped?
|
|
318
|
+
restored: bool # Was it restored from backup?
|
|
319
|
+
timestamp: datetime
|
|
320
|
+
details: Dict # Additional context
|
|
321
|
+
punishment_action: str # "none", "warn", "kick", "ban", "timeout"
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Methods:**
|
|
325
|
+
- `threat.to_dict()` - Convert to dictionary
|
|
326
|
+
- `threat.to_json()` - Convert to JSON string
|
|
327
|
+
|
|
328
|
+
### BackupInfo
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
@dataclass
|
|
332
|
+
class BackupInfo:
|
|
333
|
+
guild_id: int
|
|
334
|
+
timestamp: datetime
|
|
335
|
+
channel_count: int
|
|
336
|
+
role_count: int
|
|
337
|
+
backup_path: str
|
|
338
|
+
success: bool
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### RestoreResult
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
@dataclass
|
|
345
|
+
class RestoreResult:
|
|
346
|
+
success: bool
|
|
347
|
+
items_restored: int
|
|
348
|
+
items_failed: int
|
|
349
|
+
errors: List[str]
|
|
350
|
+
duration: float
|
|
351
|
+
details: Dict
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### WhitelistChange
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
@dataclass
|
|
358
|
+
class WhitelistChange:
|
|
359
|
+
guild_id: int
|
|
360
|
+
user_id: int
|
|
361
|
+
action: str # "added" or "removed"
|
|
362
|
+
timestamp: datetime
|
|
363
|
+
moderator_id: int
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 🔔 Event Callbacks
|
|
369
|
+
|
|
370
|
+
Register custom handlers for events:
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
@sx.on_threat_detected
|
|
374
|
+
async def handle_threat(threat: ThreatEvent):
|
|
375
|
+
"""
|
|
376
|
+
Fired when any violation is detected
|
|
377
|
+
Includes: punishment_action field
|
|
378
|
+
"""
|
|
379
|
+
print(f"{threat.type} - Punishment: {threat.punishment_action}")
|
|
380
|
+
|
|
381
|
+
@sx.on_backup_completed
|
|
382
|
+
async def handle_backup(backup: BackupInfo):
|
|
383
|
+
"""Fired when automatic backup completes"""
|
|
384
|
+
print(f"Backup: {backup.channel_count} channels, {backup.role_count} roles")
|
|
385
|
+
|
|
386
|
+
@sx.on_restore_completed
|
|
387
|
+
async def handle_restore(result: RestoreResult):
|
|
388
|
+
"""Fired when restoration completes"""
|
|
389
|
+
print(f"Restored {result.items_restored} items in {result.duration}s")
|
|
390
|
+
|
|
391
|
+
@sx.on_whitelist_changed
|
|
392
|
+
async def handle_whitelist(change: WhitelistChange):
|
|
393
|
+
"""Fired when whitelist is modified"""
|
|
394
|
+
print(f"User {change.user_id} {change.action}")
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## 💡 Advanced Examples
|
|
400
|
+
|
|
401
|
+
### Discord Embed Alerts
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
@sx.on_threat_detected
|
|
405
|
+
async def custom_alert(threat):
|
|
406
|
+
embed = discord.Embed(
|
|
407
|
+
title="🚨 Security Alert",
|
|
408
|
+
description=f"**{threat.type.replace('_', ' ').title()}**",
|
|
409
|
+
color=discord.Color.red(),
|
|
410
|
+
timestamp=threat.timestamp
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
embed.add_field(name="Violator", value=f"<@{threat.actor_id}>", inline=True)
|
|
414
|
+
embed.add_field(name="Target", value=threat.target_name, inline=True)
|
|
415
|
+
embed.add_field(
|
|
416
|
+
name="Status",
|
|
417
|
+
value=f"{'✅ Prevented' if threat.prevented else '❌ Not Prevented'}",
|
|
418
|
+
inline=True
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
if threat.punishment_action and threat.punishment_action != "none":
|
|
422
|
+
embed.add_field(
|
|
423
|
+
name="⚡ Punishment",
|
|
424
|
+
value=f"**{threat.punishment_action.upper()}**",
|
|
425
|
+
inline=False
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
if threat.restored:
|
|
429
|
+
embed.add_field(
|
|
430
|
+
name="🔄 Restoration",
|
|
431
|
+
value="✅ Restored from backup",
|
|
432
|
+
inline=False
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
await log_channel.send(embed=embed)
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Webhook Integration
|
|
439
|
+
|
|
440
|
+
```python
|
|
441
|
+
import aiohttp
|
|
442
|
+
|
|
443
|
+
@sx.on_threat_detected
|
|
444
|
+
async def send_to_webhook(threat):
|
|
445
|
+
async with aiohttp.ClientSession() as session:
|
|
446
|
+
await session.post(
|
|
447
|
+
"https://your-webhook-url.com/alerts",
|
|
448
|
+
json=threat.to_dict()
|
|
449
|
+
)
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Database Logging
|
|
453
|
+
|
|
454
|
+
```python
|
|
455
|
+
@sx.on_threat_detected
|
|
456
|
+
async def log_to_database(threat):
|
|
457
|
+
await db.threats.insert_one({
|
|
458
|
+
"type": threat.type,
|
|
459
|
+
"actor_id": threat.actor_id,
|
|
460
|
+
"target_name": threat.target_name,
|
|
461
|
+
"punishment": threat.punishment_action,
|
|
462
|
+
"prevented": threat.prevented,
|
|
463
|
+
"restored": threat.restored,
|
|
464
|
+
"timestamp": threat.timestamp
|
|
465
|
+
})
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Dynamic Punishment Modes
|
|
469
|
+
|
|
470
|
+
```python
|
|
471
|
+
@bot.command()
|
|
472
|
+
@commands.is_owner()
|
|
473
|
+
async def setmode(ctx, mode: str):
|
|
474
|
+
"""Switch between strict/normal/lenient protection modes"""
|
|
475
|
+
|
|
476
|
+
modes = {
|
|
477
|
+
"strict": {
|
|
478
|
+
"channel_delete": "ban",
|
|
479
|
+
"channel_create": "ban",
|
|
480
|
+
"role_delete": "ban",
|
|
481
|
+
"role_create": "ban",
|
|
482
|
+
"member_update": "ban"
|
|
483
|
+
},
|
|
484
|
+
"normal": {
|
|
485
|
+
"channel_delete": "kick",
|
|
486
|
+
"channel_create": "kick",
|
|
487
|
+
"role_delete": "kick",
|
|
488
|
+
"role_create": "timeout"
|
|
489
|
+
},
|
|
490
|
+
"lenient": {
|
|
491
|
+
"channel_delete": "warn",
|
|
492
|
+
"channel_create": "warn",
|
|
493
|
+
"role_delete": "warn"
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
await sx.enable(punishments=modes.get(mode, {}))
|
|
498
|
+
await ctx.send(f"✅ Protection mode set to **{mode}**")
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
## 🏗️ Architecture Overview
|
|
504
|
+
|
|
505
|
+
### v2.x Dual-System Architecture
|
|
506
|
+
|
|
507
|
+
**System 1: Instant Audit Log Workers (5-10ms)**
|
|
508
|
+
```
|
|
509
|
+
Discord Audit Log Event
|
|
510
|
+
↓ on_audit_log_entry_create (instant)
|
|
511
|
+
↓ Broadcast to 3 queues
|
|
512
|
+
├─ Event Queue → Event Worker (validation)
|
|
513
|
+
├─ Action Queue → Action Worker (punishment)
|
|
514
|
+
└─ Log Queue → Log Worker (callbacks)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**System 2: Traditional Event Handlers (restoration)**
|
|
518
|
+
```
|
|
519
|
+
Discord Event (on_channel_delete, etc.)
|
|
520
|
+
↓ ~500ms delay for audit log
|
|
521
|
+
↓ Check if unauthorized
|
|
522
|
+
↓ Restore from backup
|
|
523
|
+
↓ Trigger callbacks
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
**Key Benefits:**
|
|
527
|
+
- ⚡ Instant punishment (5-10ms) via audit log workers
|
|
528
|
+
- 🔄 Comprehensive restoration via event handlers
|
|
529
|
+
- 🎯 Zero conflicts - completely independent systems
|
|
530
|
+
- 📊 Broadcast queue - 3 workers process in parallel
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
## ⚙️ Requirements
|
|
535
|
+
|
|
536
|
+
### Python & Dependencies
|
|
537
|
+
- Python 3.8+
|
|
538
|
+
- discord.py 2.0+
|
|
539
|
+
- aiofiles 23.0+
|
|
540
|
+
|
|
541
|
+
### Bot Configuration
|
|
542
|
+
|
|
543
|
+
**Intents Required:**
|
|
544
|
+
```python
|
|
545
|
+
intents = discord.Intents.all() # Recommended
|
|
546
|
+
|
|
547
|
+
# Or specific intents:
|
|
548
|
+
intents = discord.Intents(
|
|
549
|
+
guilds=True,
|
|
550
|
+
members=True,
|
|
551
|
+
bans=True,
|
|
552
|
+
webhooks=True,
|
|
553
|
+
guild_messages=True
|
|
554
|
+
)
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Permissions Required:**
|
|
558
|
+
- `MANAGE_CHANNELS` - For restoration
|
|
559
|
+
- `MANAGE_ROLES` - For restoration
|
|
560
|
+
- `BAN_MEMBERS` - For punishments
|
|
561
|
+
- `KICK_MEMBERS` - For punishments
|
|
562
|
+
- `MODERATE_MEMBERS` - For timeouts
|
|
563
|
+
- `VIEW_AUDIT_LOG` - For detection (critical!)
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## 🎨 Why SDK Approach?
|
|
568
|
+
|
|
569
|
+
- 🎨 **Full UI Control** - Design your own embeds, dashboards, webhooks
|
|
570
|
+
- 📦 **Easy Integration** - Just `pip install` and import
|
|
571
|
+
- 🔒 **Battle-Tested Logic** - Proven anti-nuke protection
|
|
572
|
+
- 🚀 **No Boilerplate** - We handle the complex stuff
|
|
573
|
+
- ⚡ **Ultra-Fast** - 5-10ms response time (100x faster than v1.x)
|
|
574
|
+
- 💰 **Reusable** - Use across multiple projects
|
|
575
|
+
- ⚙️ **Configurable** - Every parameter is optional with sensible defaults
|
|
576
|
+
|
|
577
|
+
---
|
|
578
|
+
|
|
579
|
+
## 📄 License
|
|
580
|
+
|
|
581
|
+
MIT License - see [LICENSE](LICENSE) file
|
|
582
|
+
|
|
583
|
+
## 🔗 Links
|
|
584
|
+
|
|
585
|
+
- **PyPI**: [dc-securex](https://pypi.org/project/dc-securex/)
|
|
586
|
+
- **Issues**: Report bugs on GitHub
|
|
587
|
+
- **Documentation**: This README
|
|
588
|
+
|
|
589
|
+
---
|
|
590
|
+
|
|
591
|
+
**Version 2.3.1** - Ultra-fast anti-nuke protection with 5-10ms response time
|
|
592
|
+
|
|
593
|
+
Made with ❤️ for Discord bot developers
|