From 8c2197a0d7b74cd8ffe761670aca4213039a7aff Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 9 May 2022 16:42:31 -0400 Subject: fix new ircrobots stuff --- config.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 958c095..e69528d 100644 --- a/config.py +++ b/config.py @@ -1,20 +1,22 @@ from dataclasses import dataclass -from os.path import expanduser -from re import compile as re_compile -from typing import List, Pattern, Tuple +from mastodon import Mastodon +from typing import Tuple, Dict import yaml + @dataclass class Config(object): - server: Tuple[str, int, bool] + server: Tuple[str, int, bool] nickname: str username: str realname: str - password: str - channel: str + channel: str sasl: Tuple[str, str] + mastodon_accounts: Dict[str, Mastodon] + assigned_channels: Dict[str, str] + def load(filepath: str): with open(filepath) as file: @@ -22,22 +24,34 @@ def load(filepath: str): nickname = config_yaml["nickname"] - server = config_yaml["server"] + server = config_yaml["server"] hostname, port_s = server.split(":", 1) - tls = False + tls = False if port_s.startswith("+"): - tls = True + tls = True port_s = port_s.lstrip("+") port = int(port_s) + accounts = {} + channels = {} + for acct in config_yaml["mastodon"]: + accounts[acct["name"]] = Mastodon( + client_id=acct["client_id"], + client_secret=acct["client_secret"], + access_token=acct["access_token"], + api_base_url=acct["api_base_url"], + ) + if "channel" in acct: + channels[acct["channel"]] = acct["name"] + return Config( (hostname, port, tls), nickname, config_yaml.get("username", nickname), config_yaml.get("realname", nickname), - config_yaml["password"], config_yaml["channel"], (config_yaml["sasl"]["username"], config_yaml["sasl"]["password"]), + mastodon_accounts=accounts, + assigned_channels=channels, ) - -- cgit 1.4.1