|
1 | | -from prettyconf import config |
| 1 | +from typing import NamedTuple, Any |
| 2 | + |
| 3 | +from prettyconf import config as _config |
| 4 | + |
| 5 | + |
| 6 | +_config_registry = [] |
| 7 | + |
| 8 | +class _ConfigItem(NamedTuple): |
| 9 | + name: str |
| 10 | + value: Any |
| 11 | + suppress_log: bool = False |
| 12 | + |
| 13 | + def log(self, logger_method, indent=False): |
| 14 | + value = "***PRIVATE***" if self.suppress_log else self.value |
| 15 | + indentation = ' ' if indent else '' |
| 16 | + logger_method(f"{indentation}{self.name} = {value}") |
| 17 | + |
| 18 | + |
| 19 | +def config(item, cast=lambda v: v, suppress_log=False, **kwargs): |
| 20 | + value = _config(item, cast, **kwargs) |
| 21 | + global _config_registry |
| 22 | + _config_registry.append(_ConfigItem(item, value, suppress_log)) |
| 23 | + return value |
| 24 | + |
| 25 | + |
| 26 | +def log(logger_method): |
| 27 | + logger_method("Bot configuration:") |
| 28 | + for config_item in _config_registry: |
| 29 | + config_item.log(logger_method, indent=True) |
| 30 | + |
2 | 31 |
|
3 | 32 | TELEGRAM_BOT_TOKEN = config( |
4 | 33 | "TELEGRAM_BOT_TOKEN", |
5 | | - default="put here the token of your bot" |
| 34 | + default="put here the token of your bot", |
| 35 | + suppress_log=True |
6 | 36 | ) |
7 | 37 |
|
8 | 38 | # How likely is the bot to be triggered by one of the patterns it recognises. |
|
17 | 47 | POLL_INTERVAL = config('POLL_INTERVAL', int, default=3) |
18 | 48 |
|
19 | 49 | # Bot message for start command |
20 | | -BOT_GREETING = "Hi! I'm a friendly, sligthly psychopath robot" |
| 50 | +BOT_GREETING = config('BOT_GREETING', default="Hi! I'm a friendly, slightly psychopath robot") |
21 | 51 |
|
22 | 52 | # A username longer than this will be considered non-human |
23 | 53 | # - Allowed values: An integer larger than 1 |
|
0 commit comments