Giter Site home page Giter Site logo

trigger's Introduction

Trigger

此项目隶属于 YiriMirai 的拓展模块。

事件触发器:提供更多处理事件的方式。

目前已经实现的有两种:中断控制器和事件接收控制器。

安装

pip install yiri-mirai-trigger
# 或者使用 poetry
poetry add yiri-mirai-trigger

使用

中断控制器

from mirai_extensions.trigger import Trigger, InterruptControl

inc = InterruptControl(bot)

@bot.on(FriendMessage)
async def on_friend_message(event: FriendMessage):
    if str(event.message_chain).strip() == '你是谁':
        await bot.send(event, '我是 Yiri。你呢?')

        @Trigger(FriendMessage)
        async def trigger(event_new: FriendMessage):
            if event.sender.id == event_new.sender.id:
                msg = str(event.message_chain)
                if msg.startswith('我是'):
                    return msg[2:]

        name = await inc.wait(trigger, timeout=60.)
        if name:
            await bot.send(event, f'你好,{name}。')

事件接收控制器

hdc = HandlerControl(bot)

@Trigger(FriendMessage)
async def trigger(event: FriendMessage):
    msg = str(event.message_chain)
    if msg.startswith('我是'):
        return msg[2:]

@hdc.on(trigger)
async def handler(event: FriendMessage, payload: str):
    ...

更多信息,请参考文档API 文档

开源协议

本项目采用 AGPL-3.0 协议。

请注意,AGPL-3.0 是传染性协议。如果你的项目引用了本项目,请在发布时公开源代码,并同样采用 AGPL-3.0 协议。

trigger's People

Contributors

wybxc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.