示例#1
0
def create_conf_prompt() -> None:
    """
    Prompt the user to create a config file.
    """
    with open(os.path.join(params.BPATH, 'figaro', '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, 'figaro', 'gui', '.tkn'),
                  'w') as o:
            root = User.load_root()
            o.write(
                jwt.encode({
                    'uname': root.uname,
                }, secret, algorithm='HS256').decode())
示例#2
0
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,
    }))
示例#3
0
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)))
示例#4
0
文件: cmd.py 项目: swipswaps/figaro
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({}))
示例#5
0
文件: cmd.py 项目: swipswaps/figaro
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({}))
示例#6
0
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()
示例#7
0
文件: cmd.py 项目: swipswaps/figaro
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())),
    }))
示例#8
0
文件: cmd.py 项目: swipswaps/figaro
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)),
    }))
示例#9
0
文件: cmd.py 项目: swipswaps/figaro
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), }))
示例#10
0
文件: cmd.py 项目: swipswaps/figaro
def on_show_all_filters(cmd: pcmd.Command, args: List[str], json: bool) -> None:
    """Callback for `show filters all` - shows all available voice-filters"""
    filters.manager.collectPlugins()
    plugins = filters.get_names()
    if not plugins:
        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(plugins))
        return
    print(JSON.dumps({
        'filters': [{
            'name': p,
            'html': filters.get(p).plugin_object.html().strip(),
        } for p in plugins],
    }))