Add weixin support and adapt to mojo-webqq 2.0

This commit is contained in:
Richard Chien
2016-12-29 23:45:34 +08:00
parent c2433aef13
commit 0af4a3dbdc
13 changed files with 240 additions and 54 deletions

View File

@ -1,6 +1,6 @@
import os
import re
from functools import reduce
from functools import reduce, wraps
import pytz
from apscheduler.schedulers.background import BackgroundScheduler
@ -60,8 +60,22 @@ def _call_commands(job_id, command_list, ctx_msg):
)
def _check_target(func):
@wraps(func)
def wrapper(args_text, ctx_msg, internal=False, *args, **kwargs):
target = get_target(ctx_msg)
if not target:
_send_fail_to_get_target_msg(ctx_msg, internal)
return None
else:
return func(args_text, ctx_msg, internal, *args, **kwargs)
return wrapper
@cr.register('add_job', 'add-job', 'add')
@cr.restrict(full_command_only=True, group_admin_only=True)
@_check_target
def add_job(args_text, ctx_msg, internal=False):
if args_text.strip() in ('', 'help', '-h', '--help') and not internal:
_send_add_job_help_msg(ctx_msg, internal)
@ -150,6 +164,7 @@ def add_job(args_text, ctx_msg, internal=False):
@cr.register('remove_job', 'remove-job', 'remove')
@cr.restrict(full_command_only=True, group_admin_only=True)
@_check_target
def remove_job(args_text, ctx_msg, internal=False):
job_id_without_suffix = args_text.strip()
if not job_id_without_suffix:
@ -167,6 +182,7 @@ def remove_job(args_text, ctx_msg, internal=False):
@cr.register('get_job', 'get-job', 'get')
@cr.restrict(full_command_only=True)
@_check_target
def get_job(args_text, ctx_msg, internal=False):
job_id_without_suffix = args_text.strip()
if not job_id_without_suffix:
@ -190,6 +206,7 @@ def get_job(args_text, ctx_msg, internal=False):
@cr.register('list_jobs', 'list-jobs', 'list')
@cr.restrict(full_command_only=True)
@_check_target
def list_jobs(_, ctx_msg, internal=False):
target = get_target(ctx_msg)
job_id_suffix = '_' + target
@ -219,6 +236,15 @@ def _send_text(text, ctx_msg, internal):
core.echo(text, ctx_msg)
def _send_fail_to_get_target_msg(ctx_msg, internal):
_send_text(
'无法获取 target可能因为不支持当前消息类型不支持微信群组消息'
'或由于延迟还没能加载到用户的固定 ID微信号',
ctx_msg,
internal
)
def _send_add_job_help_msg(ctx_msg, internal):
_send_text(
'此为高级命令!如果你不知道自己在做什么,请不要使用此命令。\n\n'