|
|
|
@ -14,8 +14,6 @@ import yaml
|
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
|
class Config:
|
|
|
|
|
listen_addr: str
|
|
|
|
|
listen_port: int
|
|
|
|
|
matrix_homeserver: str
|
|
|
|
|
matrix_user: str
|
|
|
|
|
matrix_password: str
|
|
|
|
@ -118,7 +116,7 @@ async def send_notices(config, src):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def run_app(config, dest):
|
|
|
|
|
async def run_app(config, dest, host, port):
|
|
|
|
|
async def webhook(request):
|
|
|
|
|
tokens = request.query.getall("token", [])
|
|
|
|
|
if config.webhook_token not in tokens:
|
|
|
|
@ -132,9 +130,7 @@ async def run_app(config, dest):
|
|
|
|
|
|
|
|
|
|
runner = aiohttp.web.AppRunner(app)
|
|
|
|
|
await runner.setup()
|
|
|
|
|
await aiohttp.web.TCPSite(
|
|
|
|
|
runner, config.listen_addr, config.listen_port
|
|
|
|
|
).start()
|
|
|
|
|
await aiohttp.web.TCPSite(runner, host, port).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
@ -142,11 +138,13 @@ async def main():
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument("-c", "--config-file", default="config.yaml")
|
|
|
|
|
parser.add_argument("-c", "--config", default="config.yaml")
|
|
|
|
|
parser.add_argument("--host", default="0.0.0.0")
|
|
|
|
|
parser.add_argument("--port", type=int, default=8000)
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
with open(args.config_file) as f:
|
|
|
|
|
with open(args.config) as f:
|
|
|
|
|
config = yaml.safe_load(f)
|
|
|
|
|
|
|
|
|
|
config = Config(**config)
|
|
|
|
@ -154,10 +152,10 @@ async def main():
|
|
|
|
|
events = asyncio.Queue()
|
|
|
|
|
formatted = asyncio.Queue()
|
|
|
|
|
|
|
|
|
|
logging.info("Started Kanbot")
|
|
|
|
|
logging.info("Started Kanbot on %s:%d", args.host, args.port)
|
|
|
|
|
|
|
|
|
|
tasks = (
|
|
|
|
|
asyncio.create_task(run_app(config, events)),
|
|
|
|
|
asyncio.create_task(run_app(config, events, args.host, args.port)),
|
|
|
|
|
asyncio.create_task(format_events(config, events, formatted)),
|
|
|
|
|
asyncio.create_task(send_notices(config, formatted)),
|
|
|
|
|
)
|
|
|
|
|