def manage_env(client, message): action = extract_args(message).split(' ', 1) if action[0] == 'list': pass elif len(action) < 2 or action[0] not in [ 'get', 'set', 'rem', 'copy', 'move' ]: edit(message, f"`{get_translation('wrongCommand')}`") return heroku_mode = False if HEROKU_KEY: heroku_mode = True heroku = from_key(HEROKU_KEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: edit( message, f'`{get_translation("updateHerokuVariables", ["HEROKU_APPNAME "])}`' ) for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app heroku_env = app.config() break if heroku_app is None: edit( message, f'`{get_translation("updateHerokuVariables", ["HEROKU_APPNAME "])}`' ) return reload_env() if action[0] == 'set': items = action[1].split(' ', 1) if len(items) < 2 or len( items[1]) < 1 or items[0].upper() in ENV_RESTRICTED_KEYS: edit(message, f"`{get_translation('wrongCommand')}`") return key, value = items key = key.upper() if heroku_mode: heroku_env[key] = value else: set_local_env(key, value) edit(message, get_translation('envSetSuccess', ['`', '**', key])) sleep(2) restart(client, message) elif action[0] == 'get': items = action[1].split(' ', 1) if len(items[0]) < 1 or items[0].upper() in ENV_RESTRICTED_KEYS: edit(message, f"`{get_translation('wrongCommand')}`") return items[0] = items[0].upper() if heroku_mode and items[0] in heroku_env: value = heroku_env[items[0]] elif not heroku_mode and (value := environ.get(items[0], None)): pass else: edit(message, get_translation('envNotFound', ['`', '**', items[0]])) return edit(message, get_translation('envGetValue', ['`', '**', items[0], value]))
return items[0] = items[0].upper() if heroku_mode and items[0] in heroku_env: del heroku_env[items[0]] elif not heroku_mode and (value := environ.get(items[0], None)): unset_local_env(items[0]) else: edit(message, get_translation('envNotFound', ['`', '**', items[0]])) return edit(message, get_translation('envRemSuccess', ['`', '**', items[0]])) sleep(2) restart(client, message) elif action[0] in ['copy', 'move']: items = action[1].split(' ', 1) if len(items) < 2 or len(items[0]) < 1 or items[0].upper( ) in ENV_RESTRICTED_KEYS or items[1].upper( ) in ENV_RESTRICTED_KEYS or items[0].upper() == items[1].upper(): edit(message, f"`{get_translation('wrongCommand')}`") return items[0] = items[0].upper() items[1] = items[1].upper() if heroku_mode and items[0] in heroku_env: value = heroku_env[items[0]] elif not heroku_mode and (value := environ.get(items[0], None)):