Skip to content

Condiments

immmdreza edited this page Jul 3, 2021 · 2 revisions

Welcome to the most fun part of Flamingo!

Condiments are containers for incoming updates. and they are used when you are handling your update in callback function!

As you already know, callback function takes an ICondiment<T> as parameter, where T is incoming update type ( Message, CallbackQuery and ... ).

They contain may useful properties:

  • InComing : incoming update type ( Message, CallbackQuery and ... )
  • Flamingo : the FlamingoCore it self ( Which contains Bot, BotInfo and ... )
  • StringQuery : If update has a main text ( Text or Caption in Message, Data in CallbackQuery and ... )
  • QueryArgs : StringQuery as args
  • Chat, Sender, SenderId
  • MatchCollection : if you have a regex filter!

And maybe more!

Methods

But the most fun part is methods! not normal methods But Extensions

So if you want to see a full list of methods for an ICondiment, just add following namespace:

using Flamingo.Condiments.Extensions;

Now you have all ( they are mostly available for message and callback query for now ).

You can refer to example to see some usage of them

For messages

ReplyText(), RespondText(), Delete(), Forward(), Pin() and more

Extension methods returns ICondiment<Message> instead of Message, so you can use extension methods on them again!

GetRequireArgs()

This is a very useful extension method that works on string query args:

// - Query data args has been made using "callbackDataSpliter" at "InitBot"
if (cdmt.GetRequireArgs(
    out string mode, out int level, 1))
/*  ^                ^              ^
    |                |              |
    |_ First arg of callback data as string
                        |_ Second arg of callback data as int
                                    |_ Start index ( set 1 to skip "data" itself)
    */
{ }

WaitFor<T>()

This methods helps you create a quick await-able incoming handler

Build you own

With the power that condiments bring to you, can make a lot of custom extension methods for them to be used in callback functions

/// <summary>
/// Extension method to pin the message
/// </summary>
public static async Task Pin(this ICondiment<Message> Cdmt,
    bool disableNotify = true,
    CancellationToken cancellationToken = default)
{
    await Cdmt.Flamingo.BotClient.PinChatMessageAsync(
        Cdmt.Chat.Id, Cdmt.InComing.MessageId,
        disableNotify, cancellationToken);
}

Condiments can help you save a lot of time, space and clicking keyboard times!

Flamingo Framework written in pure c#, install from Nuget

Clone this wiki locally