forked from vbatts/maubot
Add log viewer to mbc
This commit is contained in:
parent
ecc1843119
commit
6f06eec3cc
5 changed files with 141 additions and 17 deletions
|
@ -13,9 +13,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Tuple, Optional
|
||||
import json
|
||||
import os
|
||||
|
||||
from colorama import Fore
|
||||
|
||||
config = {
|
||||
"servers": {},
|
||||
"default_server": None,
|
||||
|
@ -23,6 +26,25 @@ config = {
|
|||
configdir = os.environ.get("XDG_CONFIG_HOME", os.path.join(os.environ.get("HOME"), ".config"))
|
||||
|
||||
|
||||
def get_default_server() -> Tuple[Optional[str], Optional[str]]:
|
||||
try:
|
||||
server: str = config["default_server"]
|
||||
except KeyError:
|
||||
server = None
|
||||
if server is None:
|
||||
print(f"{Fore.RED}Default server not configured.{Fore.RESET}")
|
||||
return None, None
|
||||
return server, get_token(server)
|
||||
|
||||
|
||||
def get_token(server: str) -> Optional[str]:
|
||||
try:
|
||||
return config["servers"][server]
|
||||
except KeyError:
|
||||
print(f"{Fore.RED}No access token saved for {server}.{Fore.RESET}")
|
||||
return None
|
||||
|
||||
|
||||
def save_config() -> None:
|
||||
with open(f"{configdir}/maubot-cli.json", "w") as file:
|
||||
json.dump(config, file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue