mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
Add weixin support and adapt to mojo-webqq 2.0
This commit is contained in:
35
app.py
35
app.py
@ -9,14 +9,28 @@ from filter import apply_filters
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/', methods=['POST'])
|
||||
def _index():
|
||||
@app.route('/qq/', methods=['POST'])
|
||||
def _handle_qq_message():
|
||||
ctx_msg = request.json
|
||||
ctx_msg['via'] = 'qq'
|
||||
return _main(ctx_msg)
|
||||
|
||||
|
||||
@app.route('/wx/', methods=['POST'])
|
||||
def _handle_wx_message():
|
||||
ctx_msg = request.json
|
||||
ctx_msg['via'] = 'wx'
|
||||
return _main(ctx_msg)
|
||||
|
||||
|
||||
def _main(ctx_msg: dict):
|
||||
_preprocess_ctx_msg(ctx_msg)
|
||||
try:
|
||||
if ctx_msg.get('msg_class') != 'recv':
|
||||
if ctx_msg.get('post_type') != 'receive_message':
|
||||
raise SkipException
|
||||
if not apply_filters(ctx_msg):
|
||||
raise SkipException
|
||||
print(ctx_msg)
|
||||
except SkipException:
|
||||
# Skip this message
|
||||
pass
|
||||
@ -24,6 +38,21 @@ def _index():
|
||||
return '', 204
|
||||
|
||||
|
||||
def _preprocess_ctx_msg(ctx_msg: dict):
|
||||
if 'group_uid' in ctx_msg:
|
||||
ctx_msg['group_uid'] = str(ctx_msg['group_uid'])
|
||||
if 'sender_uid' in ctx_msg:
|
||||
ctx_msg['sender_uid'] = str(ctx_msg['sender_uid'])
|
||||
if 'sender_id' in ctx_msg:
|
||||
ctx_msg['sender_id'] = str(ctx_msg['sender_id'])
|
||||
if 'discuss_id' in ctx_msg:
|
||||
ctx_msg['discuss_id'] = str(ctx_msg['discuss_id'])
|
||||
if 'group_id' in ctx_msg:
|
||||
ctx_msg['group_id'] = str(ctx_msg['group_id'])
|
||||
if 'id' in ctx_msg:
|
||||
ctx_msg['id'] = str(ctx_msg['id'])
|
||||
|
||||
|
||||
def _load_filters():
|
||||
filter_mod_files = filter(
|
||||
lambda filename: filename.endswith('.py') and not filename.startswith('_'),
|
||||
|
Reference in New Issue
Block a user