👨‍💻 dev burp

development

fukurou

the supreme coder
ADMIN
Python:
import os
from pygame import mixer

class UltraVoiceSkill(Skill):
    def __init__(self):
        super().__init__()
        self.voices_folder = os.path.abspath("voices")
        self._safe_chars = set("abcdefghijklmnopqrstuvwxyz0123456789 _-")  # Allowed chars
        mixer.init()

    def input(self, ear: str, skin: str, eye: str):
        # Fast exit for non-strings or empty input
        if not isinstance(ear, str) or not ear.strip():
            return

        # 1. Lightning-fast sanitization
        clean = ear.strip().lower().replace(" ", "_")
        clean = ''.join(c for c in clean if c in self._safe_chars)
        if not clean:  # Empty after sanitization
            return

        # 2. Secure path construction
        voice_path = os.path.join(self.voices_folder, f"{clean}.mp3")

        # 3. Single validation check
        if (os.path.normpath(voice_path).startswith(self.voices_folder)
            and voice_path.endswith('.mp3')
            and os.path.isfile(voice_path)):
            
            mixer.music.load(voice_path)
            mixer.music.play()
 

fukurou

the supreme coder
ADMIN
Python:
import os
from pygame import mixer

class CachedVoiceSkill(Skill):
    def __init__(self):
        super().__init__()
        self.voices_folder = os.path.abspath("voices")
        self._valid_voices = set()  # Stores pre-sanitized filenames
        self._init_voice_cache()
        mixer.init()

    def _init_voice_cache(self):
        """Preloads valid filenames at startup (runs once)."""
        if os.path.exists(self.voices_folder):
            for f in os.listdir(self.voices_folder):
                if f.endswith('.mp3'):
                    # Store filename without extension for fast lookup
                    self._valid_voices.add(os.path.splitext(f)[0].lower())

    def input(self, ear: str, skin: str, eye: str):
        # Fast exit for empty/non-string input
        if not isinstance(ear, str) or not ear.strip():
            return

        # Sanitize input and check cache (O(1) lookup)
        voice_key = ear.strip().lower().replace(" ", "_")
        if voice_key in self._valid_voices:
            voice_path = os.path.join(self.voices_folder, f"{voice_key}.mp3")
            mixer.music.load(voice_path)
            mixer.music.play()
 

fukurou

the supreme coder
ADMIN
Python:
import os
from pygame import mixer

class UltraLeanVoiceSkill(Skill):
    def __init__(self):
        super().__init__()
        self.voices_folder = "voices"
        self._valid_voices = {  # Pre-sanitized filenames (e.g., "hello_world")
            os.path.splitext(f)[0].lower().replace(" ", "_")
            for f in os.listdir(self.voices_folder)
            if f.endswith('.mp3')
        }
        mixer.init()

    def input(self, ear: str, skin: str, eye: str):
        # Fast exit for empty input (no isinstance() check!)
        if not ear.strip():
            return

        # O(1) lookup in pre-cached set
        voice_key = ear.strip().lower().replace(" ", "_")
        if voice_key in self._valid_voices:
            mixer.music.load(f"{self.voices_folder}/{voice_key}.mp3")
            mixer.music.play()
 
Top