Skip to content

OnText handler

Arius Bronte edited this page Feb 23, 2020 · 3 revisions

Basic usage

Trigerred at the word "ping" and replies with the word "pong".

commands.OnText("^ping$", "pong");

Trigerred at the word "ping" and sends randomly from the array word.

commands.OnText("^ping$", new[] {"pong1", "pong2", "pong3"});

*applies to all triggers.

Triggered on all incoming messages or if no command is found. Is not required.

commands.OnText("command not found");
// or
commands.OnText(new[] {"command not found", "what?", "use help command!"});

Options

You can set regex options.

commands.OnText(("^pInG$", RegexOptions.IgnoreCase), "pong");

You can configure the logic for a specific conversation.

commands.OnText((2_000_000_000 + 1, "^ping$"), "pong for 1");
commands.OnText((2_000_000_000 + 2, "^ping$"), "pong for 2");
commands.OnText((2_000_000_000 + 3, "^pong$"), "ping");

You can combine all options.

commands.OnText((2_000_000_000 + 1, "^ping$", RegexOptions.IgnoreCase), "pong");

Extended

You can set your own trigger processing logic.

commands.OnText("^ping$", async (api, message, token) =>
{
    await api.Messages.SendAsync(new MessagesSendParams
    {
        PeerId = message.Message.PeerId.Value,
        Message = "pong",
        RandomId = random.Next(int.MinValue, int.MaxValue)
    });
});

*applies to all triggers.

Clone this wiki locally