Exemple #1
0
 async def __call__(
     self, type_: str = EventType(), text: str = EventPlainText()
 ) -> bool:
     return (
         type_ == "message"
         and (text.casefold() if self.ignorecase else text) in self.msg
     )
Exemple #2
0
async def _(msg: str = EventPlainText(), to_me: bool = EventToMe()):
    def split_command(msg):
        for command in commands:
            if command in msg:
                prefix, suffix = re.split(command, msg)
                return prefix, suffix
        return "", ""

    msg = msg.strip().strip(".>,?!。,()()[]【】")
    prefix_words = ["这", "这个", "那", "那个", "你", "我", "他", "它"]
    suffix_words = ["意思", "梗", "玩意", "鬼"]
    prefix, suffix = split_command(msg)
    if (not prefix or prefix
            in prefix_words) or (suffix and suffix not in suffix_words):
        what.block = False
        await what.finish()
    keyword = prefix

    if to_me:
        res = await get_content(keyword)
    else:
        res = await get_content(keyword, sources=["jiki", "nbnhhsh"])

    if res:
        what.block = True
        await what.finish(res)
    else:
        what.block = False
        await what.finish()
Exemple #3
0
 async def __call__(
     self, type: str = EventType(), text: str = EventPlainText()) -> Any:
     if type != "message":
         return False
     return bool(
         re.search(
             f"(?:{'|'.join(re.escape(prefix) for prefix in self.msg)})$",
             text,
             re.IGNORECASE if self.ignorecase else 0,
         ))
Exemple #4
0
async def continue_receive(
    matcher: Matcher, event: MessageEvent, msg: str = EventPlainText()
):
    msg = msg.strip()
    if msg:
        for word in end_word:
            if word in msg.lower():
                await matcher.finish()
        if msg:
            reply = await get_reply(msg, event)
            await handle_reply(matcher, reply, event)
Exemple #5
0
async def first_receive(
    matcher: Matcher, event: MessageEvent, msg: str = EventPlainText()
):
    if event.reply:
        await chat.finish()
    if not filter_msg(msg):
        await chat.finish()

    if msg:
        reply = await get_reply(msg, event)
    else:
        reply = random.choice(null_reply)

    await handle_reply(matcher, reply, event)
Exemple #6
0
async def _parse_group_idx(state: T_State, event_msg: str = EventPlainText()):
    if not isinstance(state["group_idx"], Message):
        return
    group_number_idx: Optional[dict[int, int]] = state.get("group_number_idx")
    assert group_number_idx
    try:
        assert event_msg != "取消", "userAbort"
        idx = int(event_msg)
        assert idx in group_number_idx.keys(), "idxNotInList"
        state["group_idx"] = idx
    except AssertionError as AE:
        errType = AE.args[0]
        if errType == "userAbort":
            await group_manage_matcher.finish("已取消")
        elif errType == "idxNotInList":
            await group_manage_matcher.reject("请输入正确序号")
Exemple #7
0
 async def __call__(
     self, type: str = EventType(), text: str = EventPlainText()) -> bool:
     if type != "message":
         return False
     return bool(text and any(keyword in text for keyword in self.keywords))
Exemple #8
0
def filter_msg(msg: str = EventPlainText()):
    for p in filter_patterns:
        if re.search(p, msg):
            return False
    return True
Exemple #9
0
 async def handler(filename: str = EventPlainText()):
     filename = filename.strip().strip("[").strip("]")
     await handle_emoji(matcher, dirname, filename)
Exemple #10
0
async def event_plain_text(text: str = EventPlainText()) -> str:
    return text
Exemple #11
0
async def _check_command(event_msg: str = EventPlainText()):
    if event_msg not in {"添加订阅", "查询订阅", "删除订阅", "取消"}:
        await group_manage_matcher.reject("请输入正确的命令")
    return