def on_show_all_sounds(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `show sounds all` - shows all available sounds""" spath = os.path.join(params.BPATH, 'res', 'sounds') if not os.path.isdir(spath): if not json: utils.printerr(f'Directory "{spath}" doesn\'t exist ... ') else: print( JSON.dumps( {'error': f'Directory "{spath}" doesn\'t exist ... '})) return sounds = [ s for s in os.listdir(spath) if os.path.isfile(os.path.join(spath, s)) and s.split('.')[-1] in params.ALLOWED_EXTS ] if not sounds: if not json: utils.printwrn('No sounds available ... ') else: print(JSON.dumps({'error': 'No sounds available ... '})) return if not json: print('Available sounds:\n - ', end='') print('\n - '.join(sounds)) return print(JSON.dumps({ 'sounds': sounds, }))
def on_show_all_filters(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `show filters all` - shows all available voice-filters""" if not os.path.isdir(os.path.join(params.BPATH, 'lib', 'filters')): utils.printerr('Error: Directory "{}" doesn\'t exist ... '.format( os.path.join(params.BPATH, 'lib', 'filters'))) return fs = [ f[:-3] for f in os.listdir(os.path.join(params.BPATH, 'lib', 'filters')) if os.path.isfile(os.path.join(params.BPATH, 'lib', 'filters', f)) and f != 'filter.py' and f.endswith('.py') ] if not fs: if not json: utils.printwrn('No filters available ... ') else: print(JSON.dumps({ 'error': 'No filters available ... ', })) return if not json: print('Filters: \n - ', end='') print('\n - '.join(fs)) return print(JSON.dumps({ 'filters': fs, }))
def create_conf_prompt() -> None: """ Prompt the user to create a config file. """ with open(os.path.join(params.BPATH, 'lib', 'server', 'conf.json'), 'w') as f: while True: secret_len = input('Enter secret length [default 512 (bits)]: ') if not secret_len.strip(): secret_len = 512 else: try: secret_len = int(secret_len) if secret_len % 8 != 0: utils.printwrn( 'No. bits should be divisible by 8 ... ') continue except ValueError: utils.printerr('Enter a valid number!') continue break secret = secrets.token_bytes(secret_len // 8) f.write(json.dumps(dict(secret=base64.b64encode(secret).decode()))) with open(os.path.join(params.BPATH, 'lib', 'gui', '.tkn'), 'w') as o: root = User.load_root() o.write( jwt.encode({ 'uname': root.uname, }, secret, algorithm='HS256'))
def on_show_interpreters(cmd: pcmd.Command, args: List[str]) -> None: """Callback for `show interpreters` - shows all running interpreters""" if not interpreters: utils.printwrn('No interpreters running ... ') return print('Interpreters: ') for i, p in enumerate(interpreters): print(' #{:02d} | {}'.format(i, str(p)))
def on_show_sounds(cmd: pcmd.Command, args: List[str]) -> None: """Callback for `show sounds` - shows all currently playing sounds""" if not ch.sounds: utils.printwrn('No sounds are playing at the moment ... ') return print('Sounds: ') for i, s in enumerate(ch.get_sounds()): print(' #{:02d} | {}'.format(i, str(s)))
def on_start(cmd: pcmd.Command, args: List[str]) -> None: """Callback for `start` - starts the channel""" global ch if ch.is_alive(): utils.printwrn('Already running ... ') return ch = Channel(ch.transf, ch.ist, ch.ost) try: ch.start() except IOError as e: utils.printerr(e)
def on_stop(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `stop` - stops the channel""" if not ch.is_alive(): if not json: utils.printwrn('Not running ... ') else: print(JSON.dumps({ 'error': 'Not running ... ', })) return ch.kill() if json: print(JSON.dumps({}))
def on_stop_input(cmd: pcmd.Command, args: List[str], indi: int, json: bool) -> None: """Callback for `stop input` - removes an input device""" if not indi in [d.indi for d in ch.get_ists()]: if not json: utils.printwrn('Device isn\'t currently being used ... ') else: print( JSON.dumps({ 'error': 'Device isn\'t currently being used ... ', })) return ch.del_ist(indi) if json: print(JSON.dumps({}))
def start(): """Start the server hosting the static files""" global conf cpath = os.path.join(bpath, 'dist', 'config', 'conf.json') if not os.path.isfile(cpath): utils.printwrn( f'Config file ("{cpath}") missing ... trying to (re)compile GUI ... ' ) os.system(f'cd {bpath} && npm run build') if not os.path.isfile(cpath): utils.printerr(f'Config file "{cpath}" doesn\'t exist ... ') os._exit(1) with open(cpath, 'r') as f: conf = json.load(f) threading.Thread(target=_start).start()
def on_show_sounds(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `show sounds` - shows all currently playing sounds""" if not ch.sounds: if not json: utils.printwrn('No sounds are playing at the moment ... ') else: print( JSON.dumps( {'error': 'No sounds are playing at the moment ... '})) return if not json: print('Sounds: ') for i, s in enumerate(ch.get_sounds()): print(' #{:02d} | {}'.format(i, str(s))) return print( JSON.dumps({ 'sounds': list(map(lambda s: s.toJSON(), ch.get_sounds())), }))
def on_show_running_filters(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `show filters` - shows all running voice-filters""" filters = ch.get_filters() if not filters: if not json: utils.printwrn('No filters running ... ') else: print(JSON.dumps({ 'error': 'No filters running ... ', })) return if not json: print('Filters: ') for i, f in enumerate(filters): print(f' #{i:02d} | {f}') return print(JSON.dumps({ 'filters': list(map(lambda f: f.toJSON(), filters)), }))
def on_start(cmd: pcmd.Command, args: List[str], json: bool) -> None: """Callback for `start` - starts the channel""" global ch if ch.is_alive(): if not json: utils.printwrn('Already running ... ') else: print(JSON.dumps({ 'error': 'Already running ... ', })) return ch = Channel(ch.transf, ch.ist, ch.ost) server.ch = ch try: ch.start() if json: print(JSON.dumps({})) except IOError as e: if not json: utils.printerr(e) else: print(JSON.dumps({ 'error': str(e), }))
def on_stop(cmd: pcmd.Command, args: List[str]) -> None: """Callback for `stop` - stops the channel""" if not ch.is_alive(): utils.printwrn('Not running ... ') return ch.kill()
def on_stop_input(cmd: pcmd.Command, args: List[str], indi: int) -> None: """Callback for `stop input` - removes an input device""" if not indi in [d.indi for d in ch.get_ists()]: utils.printwrn('Device isn\'t currently being used ... ') return ch.del_ist(indi)