Exemplo n.º 1
0
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]))
Exemplo n.º 2
0
# This file is part of TeamDerUntergang project,
# and licensed under GNU Affero General Public License v3.
# See the GNU Affero General Public License for more details.
#
# All rights reserved. See COPYING, AUTHORS.
#

from re import sub
from urllib.parse import quote

from pylast import LastFMNetwork, User, md5
from sedenbot import HELP, environ
from sedenecem.core import edit, get_translation, sedenify

# =================== CONSTANT ===================
LASTFM_API = environ.get('LASTFM_API', None)
LASTFM_SECRET = environ.get('LASTFM_SECRET', None)
LASTFM_USERNAME = environ.get('LASTFM_USERNAME', None)
LASTFM_PASSWORD_PLAIN = environ.get('LASTFM_PASSWORD', None)
LASTFM_PASS = md5(LASTFM_PASSWORD_PLAIN)
if LASTFM_API and LASTFM_SECRET and LASTFM_USERNAME and LASTFM_PASS:
    lastfm = LastFMNetwork(
        api_key=LASTFM_API,
        api_secret=LASTFM_SECRET,
        username=LASTFM_USERNAME,
        password_hash=LASTFM_PASS,
    )
else:
    lastfm = None
# ================================================
Exemplo n.º 3
0
            return

        edit(message,
             get_translation('envGetValue', ['`', '**', items[0], value]))
    elif action[0] == 'rem':
        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:
            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():