Skip to content

Commit

Permalink
Make token file and persistence directory configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcisioe committed Mar 29, 2024
1 parent 3eb2fda commit e548eea
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions arromba_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,37 @@ def handle_error(update, context: CallbackContext) -> None:
update.message.reply_text(str(context.error))


def get_data_dir() -> Path:
if 'ARROMBA_DATA_DIR' in environ:
return Path(environ['ARROMBA_DATA_DIR'])

return Path.home() / f".local/share/{__package__}"


def get_persistence() -> BasePersistence:
data_dir = Path.home() / f".local/share/{__package__}"
data_dir = get_data_dir()
data_dir.mkdir(parents=True, exist_ok=True)

assert __package__ is not None

filename = data_dir / __package__
return PicklePersistence(str(filename))


def get_token_from_file(token_file_path: Path) -> str:
with token_file_path.open() as f:
return f.read().strip()


def get_token():
if 'ARROMBA_TOKEN_FILE' in environ:
return get_token_from_file(Path(environ['ARROMBA_TOKEN_FILE']))

return environ['TOKEN']


def main() -> None:
token = environ["TOKEN"]
token = get_token()
updater = Updater(token, persistence=get_persistence())
dispatcher = updater.dispatcher

Expand Down

0 comments on commit e548eea

Please sign in to comment.