Configure socket settings through command line
This commit is contained in:
parent
32803d0f2d
commit
2f27d46c61
2 changed files with 8 additions and 12 deletions
18
bot.py
18
bot.py
|
@ -14,8 +14,6 @@ import yaml
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Config:
|
class Config:
|
||||||
listen_addr: str
|
|
||||||
listen_port: int
|
|
||||||
matrix_homeserver: str
|
matrix_homeserver: str
|
||||||
matrix_user: str
|
matrix_user: str
|
||||||
matrix_password: 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):
|
async def webhook(request):
|
||||||
tokens = request.query.getall("token", [])
|
tokens = request.query.getall("token", [])
|
||||||
if config.webhook_token not in tokens:
|
if config.webhook_token not in tokens:
|
||||||
|
@ -132,9 +130,7 @@ async def run_app(config, dest):
|
||||||
|
|
||||||
runner = aiohttp.web.AppRunner(app)
|
runner = aiohttp.web.AppRunner(app)
|
||||||
await runner.setup()
|
await runner.setup()
|
||||||
await aiohttp.web.TCPSite(
|
await aiohttp.web.TCPSite(runner, host, port).start()
|
||||||
runner, config.listen_addr, config.listen_port
|
|
||||||
).start()
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
@ -142,11 +138,13 @@ async def main():
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with open(args.config_file) as f:
|
with open(args.config) as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
config = Config(**config)
|
config = Config(**config)
|
||||||
|
@ -154,10 +152,10 @@ async def main():
|
||||||
events = asyncio.Queue()
|
events = asyncio.Queue()
|
||||||
formatted = asyncio.Queue()
|
formatted = asyncio.Queue()
|
||||||
|
|
||||||
logging.info("Started Kanbot")
|
logging.info("Started Kanbot on %s:%d", args.host, args.port)
|
||||||
|
|
||||||
tasks = (
|
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(format_events(config, events, formatted)),
|
||||||
asyncio.create_task(send_notices(config, formatted)),
|
asyncio.create_task(send_notices(config, formatted)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
---
|
---
|
||||||
listen_addr: 0.0.0.0
|
|
||||||
listen_port: 8000
|
|
||||||
matrix_homeserver: https://matrix.org
|
matrix_homeserver: https://matrix.org
|
||||||
matrix_user: "@mykanbot:matrix.org"
|
matrix_user: "@mykanbot:matrix.org"
|
||||||
matrix_password: "CHANGE_ME"
|
matrix_password: "CHANGE_ME"
|
||||||
|
|
Loading…
Reference in a new issue