Пример #1
0
async def alarm(session: CommandSession):
    time: datetime = session.get("time")
    target: str = session.get("target")

    # 过滤时间
    now = datetime.now()
    # 过去的时间
    if time <= now:
        session.finish(render_expression(EXPR_COULD_NOT))

    time_str = time.strftime("%Y-%m-%d %H:%M:%S")
    await add_job(
        remind,
        trigger="date",
        run_date=time,
        id=make_job_id(
            PLUGIN_NAME,
            session.event,
            (random_string(1, string.ascii_lowercase) +
             random_string(7, string.ascii_lowercase + string.digits)),
        ),
        args=[target, session.event],
        kwargs={"remark": target},
    )
    cmd, current_arg = CommandManager().parse_command(session.bot, target)
    if cmd:
        tmp_session = CommandSession(session.bot,
                                     session.event,
                                     cmd,
                                     current_arg=current_arg)
        if await cmd.run(tmp_session, dry=True):
            await add_scheduled_commands(
                ScheduledCommand(cmd.name, current_arg),
                job_id=make_job_id(
                    PLUGIN_NAME,
                    session.event,
                    (random_string(1, string.ascii_lowercase) +
                     random_string(7, string.ascii_lowercase + string.digits)),
                ),
                event=session.event,
                trigger="date",
                run_date=time,
                replace_existing=True,
            )

    session.finish(
        render_expression(
            EXPR_OK, time=time_str, action=target, escape_args=False) +
        f"\n提醒创建成功:\n"
        f"> 提醒时间:{time_str}\n"
        f"> 内容:{target}")
Пример #2
0
async def dataload(session, bot):
    selfid = session.self_id
    for cmd in CommandManager().commands:
        if 'dataload' not in cmd and 'load' in repr(cmd):
            await call_command(bot, session.event, cmd)
    mods_config = datastorage.load('data')
    for k in groupdict[selfid].keys():
        try:
            groupdict[selfid][k]['mods_config'].update(
                mods_config[str(selfid)]['group'][str(k)])
        except KeyError:
            pass
    for k in frienddict[selfid].keys():
        try:
            frienddict[selfid][k]['mods_config'].update(
                mods_config[str(selfid)]['private'][str(k)])
        except KeyError:
            pass
    await session.send(M('所有信息读取完成'))
Пример #3
0
async def datasave(session, bot):
    selfid = session.self_id
    for cmd in CommandManager().commands:
        if 'datasave' not in cmd and 'save' in repr(cmd):
            await call_command(bot, session.event, cmd)
    try:
        mods_config = {}
        for selfid in groupdict.keys():
            mods_config[str(selfid)] = {
                'group':
                {k: v['mods_config']
                 for k, v in groupdict[selfid].items()},
                'private':
                {k: v['mods_config']
                 for k, v in frienddict[selfid].items()},
            }
        datastorage.save('data', mods_config)
        await session.send(M('所有信息保存完成'))
    except Exception as e:
        await session.send(M('保存出现错误,请检查日志'))
        raise e
Пример #4
0
import random
from datetime import timedelta

import nonebot
from nonebot import on_command, message_preprocessor, Message, MessageSegment
from nonebot.message import _check_calling_me_nickname
try:        # TODO: drop support for nonebot v1.5
    from nonebot.command import parse_command
except:     # TODO: bump dependence to nonebot v1.6
    from nonebot.command import CommandManager
    parse_command = CommandManager().parse_command

from hoshino import logger, util, Service, R

bot = nonebot.get_bot()
BLANK_MESSAGE = Message(MessageSegment.text(''))

@message_preprocessor
async def black_filter(bot, ctx, plugin_manager=None):  # plugin_manager is new feature of nonebot v1.6
    first_msg_seg = ctx['message'][0]
    if first_msg_seg.type == 'hb':
        return  # pass normal Luck Money Pack to avoid abuse
    if ctx['message_type'] == 'group' and Service.check_block_group(ctx['group_id']) \
       or Service.check_block_user(ctx['user_id']):
        ctx['message'] = BLANK_MESSAGE


def _check_hbtitle_is_cmd(ctx, title):
    ctx = ctx.copy()    # 复制一份,避免影响原有的ctx
    ctx['message'] = Message(title)
    _check_calling_me_nickname(bot, ctx)