|
| 1 | +import re |
| 2 | +import datetime |
| 3 | + |
| 4 | +class InvisibleModerator: |
| 5 | + def __init__(self): |
| 6 | + # Configurable sensitivity levels |
| 7 | + self.shadow_log = [] |
| 8 | + self.restricted_patterns = [ |
| 9 | + r"(\bscript\b.*?\b/script\b)", # Basic XSS |
| 10 | + r"(\bdrop\b\s+\btable\b)", # Basic SQLi |
| 11 | + ] |
| 12 | + |
| 13 | + def scan_content(self, user_id, message): |
| 14 | + """ |
| 15 | + Runs multiple silent checks on the content. |
| 16 | + """ |
| 17 | + is_flagged = False |
| 18 | + reason = None |
| 19 | + |
| 20 | + # Layer 1: Pattern Matching (Regex) |
| 21 | + for pattern in self.restricted_patterns: |
| 22 | + if re.search(pattern, message, re.IGNORECASE): |
| 23 | + is_flagged = True |
| 24 | + reason = "Heuristic Pattern Match" |
| 25 | + break |
| 26 | + |
| 27 | + # Layer 2: Metadata Analysis (Invisible to user) |
| 28 | + # Check for rapid-fire posting or "burst" behavior |
| 29 | + if len(message) > 2000: |
| 30 | + is_flagged = True |
| 31 | + reason = "Buffer Overflow Risk/Spam" |
| 32 | + |
| 33 | + # Silently log the event for admin review |
| 34 | + self._log_event(user_id, message, is_flagged, reason) |
| 35 | + |
| 36 | + return { |
| 37 | + "is_flagged": is_flagged, |
| 38 | + "action": "STRIP" if is_flagged else "PASS", |
| 39 | + "internal_reason": reason |
| 40 | + } |
| 41 | + |
| 42 | + def _log_event(self, user_id, message, flagged, reason): |
| 43 | + entry = { |
| 44 | + "timestamp": datetime.datetime.now().isoformat(), |
| 45 | + "user": user_id, |
| 46 | + "status": "FLAGGED" if flagged else "CLEAN", |
| 47 | + "reason": reason |
| 48 | + } |
| 49 | + self.shadow_log.append(entry) |
| 50 | + |
| 51 | +# --- Implementation Example --- |
| 52 | +mod = InvisibleModerator() |
| 53 | +user_input = "<script>alert('hacked')</script>" |
| 54 | +result = mod.scan_content(user_101, user_input) |
| 55 | + |
| 56 | +if result["is_flagged"]: |
| 57 | + # The moderator acts invisibly by returning a neutral state |
| 58 | + # or dropping the packet rather than showing an error message. |
| 59 | + print("System: Message discarded silently.") |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +import asyncio |
| 64 | +import hashlib |
| 65 | +import time |
| 66 | +from typing import Dict, Optional |
| 67 | +from dataclasses import dataclass |
| 68 | + |
| 69 | +@dataclass |
| 70 | +class ModerationVerdict: |
| 71 | + is_safe: bool |
| 72 | + confidence: float |
| 73 | + action: str # GHOST, THROTTLE, SINKHOLE, PASS |
| 74 | + metadata: Dict |
| 75 | + |
| 76 | +class ActiveInvisibleModerator: |
| 77 | + def __init__(self): |
| 78 | + self.user_reputation_matrix = {} # In-memory store for behavior |
| 79 | + self.signature_blacklist = set() # Known malicious payloads |
| 80 | + self.toxicity_threshold = 0.82 |
| 81 | + |
| 82 | + async def intercept_input(self, user_id: str, payload: str) -> ModerationVerdict: |
| 83 | + """ |
| 84 | + The entry point for all user interactions. |
| 85 | + Runs invisible checks without blocking the UI. |
| 86 | + """ |
| 87 | + # Generate a content fingerprint to detect repetitive spam |
| 88 | + fingerprint = hashlib.sha256(payload.encode()).hexdigest() |
| 89 | + |
| 90 | + # Parallel Processing: Behavior vs. Content |
| 91 | + results = await asyncio.gather( |
| 92 | + self._analyze_behavior(user_id, fingerprint), |
| 93 | + self._analyze_content_nuance(payload) |
| 94 | + ) |
| 95 | + |
| 96 | + behavior_score, content_score = results |
| 97 | + |
| 98 | + # Logic for "Invisible" Actions |
| 99 | + if behavior_score < 0.3 or content_score > self.toxicity_threshold: |
| 100 | + # Ghosting: The user thinks it's posted, but it's isolated. |
| 101 | + return ModerationVerdict(False, 0.98, "GHOST", {"reason": "Low Rep/High Toxicity"}) |
| 102 | + |
| 103 | + if 0.5 < content_score < self.toxicity_threshold: |
| 104 | + # Throttle: Introduce artificial latency to slow down "heat" |
| 105 | + return ModerationVerdict(True, 0.60, "THROTTLE", {"delay": 2.5}) |
| 106 | + |
| 107 | + return ModerationVerdict(True, 1.0, "PASS", {}) |
| 108 | + |
| 109 | + async def _analyze_behavior(self, user_id: str, fingerprint: str) -> float: |
| 110 | + """ |
| 111 | + Heuristic: Monitors velocity and repetition (Entropy Check). |
| 112 | + """ |
| 113 | + now = time.time() |
| 114 | + user_data = self.user_reputation_matrix.get(user_id, {"last_seen": now, "score": 1.0, "history": []}) |
| 115 | + |
| 116 | + # Check for rapid repetition |
| 117 | + if fingerprint in user_data["history"]: |
| 118 | + user_data["score"] -= 0.2 |
| 119 | + |
| 120 | + # Check for burst velocity |
| 121 | + if now - user_data["last_seen"] < 0.5: |
| 122 | + user_data["score"] -= 0.1 |
| 123 | + |
| 124 | + user_data["history"] = (user_data["history"] + [fingerprint])[-10:] |
| 125 | + user_data["last_seen"] = now |
| 126 | + self.user_reputation_matrix[user_id] = user_data |
| 127 | + |
| 128 | + return max(0.0, user_data["score"]) |
| 129 | + |
| 130 | + async def _analyze_content_nuance(self, text: str) -> float: |
| 131 | + """ |
| 132 | + In a production environment, this would call a transformer-based |
| 133 | + LLM or a specialized Toxicity API. |
| 134 | + """ |
| 135 | + # Mocking an AI confidence score (0.0 = Safe, 1.0 = Toxic) |
| 136 | + # Real-world: return model.predict(text) |
| 137 | + return 0.15 |
| 138 | + |
| 139 | +# --- Invisible Execution Engine --- |
| 140 | +async def handle_request(user_id, message): |
| 141 | + aim = ActiveInvisibleModerator() |
| 142 | + verdict = await aim.intercept_input(user_id, message) |
| 143 | + |
| 144 | + if verdict.action == "GHOST": |
| 145 | + # Return a success code to the user, but don't commit to the global DB |
| 146 | + return {"status": 200, "internal_status": "ISOLATED"} |
| 147 | + |
| 148 | + if verdict.action == "THROTTLE": |
| 149 | + await asyncio.sleep(verdict.metadata["delay"]) |
| 150 | + |
| 151 | + return {"status": 200, "internal_status": "COMMITTED"} |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +<svg id="aim-icon-interceptor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none"> |
| 156 | + <defs> |
| 157 | + <linearGradient id="shield_grad" x1="50" y1="10" x2="50" y2="90" gradientUnits="userSpaceOnUse"> |
| 158 | + <stop stop-color="#212529" stop-opacity="0.6"/> <!-- Stealth Gray --> |
| 159 | + <stop offset="1" stop-color="#343a40" stop-opacity="0.3"/> |
| 160 | + </linearGradient> |
| 161 | + <filter id="glow"> |
| 162 | + <feGaussianBlur stdDeviation="2.5" result="coloredBlur"/> |
| 163 | + <feMerge> |
| 164 | + <feMergeNode in="coloredBlur"/> |
| 165 | + <feMergeNode in="SourceGraphic"/> |
| 166 | + </feMerge> |
| 167 | + </filter> |
| 168 | + </defs> |
| 169 | + <!-- Translucent Shield Structure --> |
| 170 | + <path d="M50 10 L15 25 V55 C15 75 35 85 50 90 C65 85 85 75 85 55 V25 L50 10 Z" fill="url(#shield_grad)" stroke="#6c757d" stroke-width="1" stroke-opacity="0.5"/> |
| 171 | + |
| 172 | + <!-- Active Watching Eye --> |
| 173 | + <g class="aim-eye" filter="url(#glow)"> |
| 174 | + <ellipse cx="50" cy="50" rx="18" ry="10" stroke="#007bff" stroke-width="2"/> |
| 175 | + <circle cx="50" cy="50" r="6" fill="#17a2b8"/> <!-- Cyan Pupil --> |
| 176 | + </g> |
| 177 | +</svg> |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +<svg id="aim-icon-ghost" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none"> |
| 182 | + <!-- Fading Figure Head and Hood --> |
| 183 | + <path class="aim-hood" d="M50 15 C40 15 32 22 32 32 V45 L50 40 L68 45 V32 C68 22 60 15 50 15 Z" fill="#495057" fill-opacity="0.7"/> |
| 184 | + |
| 185 | + <!-- Dissolving Nodes (Particle System) --> |
| 186 | + <g class="aim-nodes" fill="#17a2b8"> |
| 187 | + <circle class="node-1" cx="35" cy="55" r="2.5"/> |
| 188 | + <circle class="node-2" cx="50" cy="65" r="2"/> |
| 189 | + <circle class="node-3" cx="65" cy="58" r="3"/> |
| 190 | + <circle class="node-4" cx="42" cy="75" r="1.5"/> |
| 191 | + <circle class="node-5" cx="58" cy="80" r="2"/> |
| 192 | + </g> |
| 193 | +</svg> |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | +/* Base Container for the Icons */ |
| 198 | +.aim-icon-container { |
| 199 | + width: 64px; |
| 200 | + height: 64px; |
| 201 | + background-color: #1a1a1d; /* Matches the dark gray grid background */ |
| 202 | + border-radius: 8px; |
| 203 | + padding: 8px; |
| 204 | + display: flex; |
| 205 | + align-items: center; |
| 206 | + justify-content: center; |
| 207 | +} |
| 208 | + |
| 209 | +/* --- Animation for Icon A: The Interceptor --- */ |
| 210 | +#aim-icon-interceptor .aim-eye { |
| 211 | + animation: interceptor-pulse 4s ease-in-out infinite; |
| 212 | + opacity: 0.8; |
| 213 | +} |
| 214 | + |
| 215 | +@keyframes interceptor-pulse { |
| 216 | + 0%, 100% { |
| 217 | + transform: scale(1); |
| 218 | + opacity: 0.6; |
| 219 | + stroke-width: 1.5; |
| 220 | + } |
| 221 | + 50% { |
| 222 | + transform: scale(1.05); /* Slight expansion * |
| 223 | + opacity: 1; /* Brightens when 'active' */ |
| 224 | + stroke-width: 2.5; |
| 225 | + } |
| 226 | +} |
| 227 | + |
| 228 | +/* --- Animation for Icon B: The Ghost Protocol --- */ |
| 229 | +#aim-icon-ghost .aim-hood { |
| 230 | + animation: ghost-fade 6s infinite; |
| 231 | +} |
| 232 | + |
| 233 | +#aim-icon-ghost .aim-nodes circle { |
| 234 | + animation: node-flurry 3s infinite ease-out; |
| 235 | + opacity: 0; |
| 236 | +} |
| 237 | + |
| 238 | +/* Staggered particle animation */ |
| 239 | +#aim-icon-ghost .node-1 { animation-delay: 0s; } |
| 240 | +#aim-icon-ghost .node-2 { animation-delay: 0.5s; } |
| 241 | +#aim-icon-ghost .node-3 { animation-delay: 1.2s; } |
| 242 | +#aim-icon-ghost .node-4 { animation-delay: 1.9s; } |
| 243 | +#aim-icon-ghost .node-5 { animation-delay: 2.5s; } |
| 244 | + |
| 245 | +@keyframes ghost-fade { |
| 246 | + 0%, 100% { opacity: 0.7; } |
| 247 | + 50% { opacity: 0.3; } /* Hood dissolves further */ |
| 248 | +} |
| 249 | + |
| 250 | +@keyframes node-flurry { |
| 251 | + 0% { |
| 252 | + transform: translateY(0) scale(1); |
| 253 | + opacity: 0; |
| 254 | + } |
| 255 | + 20% { |
| 256 | + opacity: 1; |
| 257 | + } |
| 258 | + 80% { |
| 259 | + opacity: 0.8; |
| 260 | + } |
| 261 | + 100% { |
| 262 | + transform: translateY(-20px) scale(0.5); /* Nodes float up and dissolve */ |
| 263 | + opacity: 0; |
| 264 | + } |
| 265 | +} |
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | +<!DOCTYPE html> |
| 270 | +<html lang="en"> |
| 271 | +<head> |
| 272 | + <meta charset="UTF-8"> |
| 273 | + <title>Invisible Moderator AI Icons</title> |
| 274 | + <!-- Link the CSS file above --> |
| 275 | + <link rel="stylesheet" href="aim-icons.css"> |
| 276 | +</head> |
| 277 | +<body style="background-color: #1a1a1d; display: flex; gap: 20px; padding: 50px;"> |
| 278 | + |
| 279 | + <!-- Icon 1 Container --> |
| 280 | + <div class="aim-icon-container"> |
| 281 | + <!-- Embed Icon A SVG Here --> |
| 282 | + </div> |
| 283 | + |
| 284 | + <!-- Icon 2 Container --> |
| 285 | + <div class="aim-icon-container"> |
| 286 | + <!-- Embed Icon B SVG Here --> |
| 287 | + </div> |
| 288 | + |
| 289 | +</body> |
| 290 | +</html> |
0 commit comments