|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
import argparse
|
|
|
|
|
import asyncio
|
|
|
|
|
import dataclasses
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
import aiohttp.web
|
|
|
|
|
import jinja2
|
|
|
|
@ -73,11 +74,11 @@ async def format_events(config, src, dest):
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
event = await src.get()
|
|
|
|
|
print(event)
|
|
|
|
|
logging.debug("Formatting message: %s", event)
|
|
|
|
|
try:
|
|
|
|
|
template = env.from_string(TEMPLATES[event["event_name"]])
|
|
|
|
|
except KeyError:
|
|
|
|
|
print("Unknown message type:", event["event_name"])
|
|
|
|
|
logging.info("Unknown message type: %s", event["event_name"])
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
rendered = template.render(**event)
|
|
|
|
@ -107,7 +108,8 @@ async def run_app(config, dest):
|
|
|
|
|
async def webhook(request):
|
|
|
|
|
tokens = request.query.getall("token", [])
|
|
|
|
|
if config.webhook_token not in tokens:
|
|
|
|
|
raise aiohttp.web.HTTPForbidden("Invalid token")
|
|
|
|
|
logging.warning("Invalid tokens: %s", tokens)
|
|
|
|
|
raise aiohttp.web.HTTPForbidden("Invalid tokens")
|
|
|
|
|
event = await request.json()
|
|
|
|
|
await dest.put(event)
|
|
|
|
|
|
|
|
|
@ -123,6 +125,8 @@ async def run_app(config, dest):
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument("-c", "--config-file", default="config.yaml")
|
|
|
|
|
|
|
|
|
@ -136,6 +140,8 @@ async def main():
|
|
|
|
|
events = asyncio.Queue()
|
|
|
|
|
formatted = asyncio.Queue()
|
|
|
|
|
|
|
|
|
|
logging.info("Started Kanbot")
|
|
|
|
|
|
|
|
|
|
tasks = (
|
|
|
|
|
asyncio.create_task(run_app(config, events)),
|
|
|
|
|
asyncio.create_task(format_events(config, events, formatted)),
|
|
|
|
|