2016-12-26 14:19:12 +08:00
|
|
|
import os
|
2016-12-02 22:24:19 +08:00
|
|
|
|
|
|
|
from flask import Flask, request
|
|
|
|
|
2017-02-15 15:52:18 +08:00
|
|
|
from little_shit import SkipException, load_plugins
|
2016-12-08 21:58:49 +08:00
|
|
|
from filter import apply_filters
|
2017-02-15 15:52:18 +08:00
|
|
|
from msg_src_adapter import get_adapter
|
2016-12-02 22:24:19 +08:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
2017-02-15 15:52:18 +08:00
|
|
|
@app.route('/<string:via>/<string:login_id>', methods=['POST'], strict_slashes=False)
|
|
|
|
def _handle_via_account(via: str, login_id: str):
|
2016-12-02 22:24:19 +08:00
|
|
|
ctx_msg = request.json
|
2017-02-15 15:52:18 +08:00
|
|
|
ctx_msg['via'] = via
|
|
|
|
ctx_msg['login_id'] = login_id
|
2016-12-29 23:45:34 +08:00
|
|
|
return _main(ctx_msg)
|
|
|
|
|
|
|
|
|
|
|
|
def _main(ctx_msg: dict):
|
2016-12-02 22:24:19 +08:00
|
|
|
try:
|
2017-02-15 15:52:18 +08:00
|
|
|
adapter = get_adapter(ctx_msg.get('via'), ctx_msg.get('login_id'))
|
|
|
|
if not adapter:
|
|
|
|
raise SkipException
|
|
|
|
ctx_msg = adapter.unitize_context(ctx_msg)
|
2016-12-08 21:58:49 +08:00
|
|
|
if not apply_filters(ctx_msg):
|
|
|
|
raise SkipException
|
2016-12-02 22:24:19 +08:00
|
|
|
except SkipException:
|
|
|
|
# Skip this message
|
|
|
|
pass
|
2016-12-26 14:19:12 +08:00
|
|
|
|
2016-12-02 22:24:19 +08:00
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-02-15 15:52:18 +08:00
|
|
|
load_plugins('msg_src_adapters')
|
|
|
|
load_plugins('filters')
|
2016-12-08 21:58:49 +08:00
|
|
|
app.run(host=os.environ.get('HOST', '0.0.0.0'), port=os.environ.get('PORT', '8080'))
|