-
Notifications
You must be signed in to change notification settings - Fork 0
FilterAttributes
MohammadReza edited this page Jul 21, 2021
·
3 revisions
For now there are some ready to use filter attributes for you. You can find them in following namespaces:
using Flamingo.Attributes.Filters.Messages // for messages
using Flamingo.Attributes.Filters.CallbackQueries // for callback queries
using Flamingo.Attributes.Filters.InlineQueries // for inline queries
...
...
// And other updatesIf you don't see the filter you want, then you should make it your self! It's super easy since we have abstract classes for each update type to help you make your own filter
using Flamingo.Attributes.Filters
MessageFiltersAttribute // to make a filter attribute for message updates
CallbackQueryFiltersAttribute // to make a filter attribute for callback query updates
InlineQueryFiltersAttribute // to make a filter attribute for inline query updates
...
...
// And other updatespublic class ChatTypeFilterAttribute : MessageFiltersAttribute
{
public ChatTypeFilterAttribute(FlamingoChatType chatType)
: base(new ChatTypeFilter<Message>(chatType))
{ }
}See? super easy!
This filter is suppose to filter callback query data and give us callback queries which data is equal to "fun_call"
You need some base information about filters on flamingo.
using Flamingo.Condiments;
using Flamingo.Filters;
using Telegram.Bot.Types;
namespace Flamingo.Attributes.Filters.CallbackQueries
{
public class FunCallbackFilterAttribute : CallbackQueryFiltersAttribute
{
public FunCallbackFilterAttribute()
: base(new FilterBase<ICondiment<CallbackQuery>>(
x => x.StringQuery == "fun_call"
))
{ }
}
}ICondiment<CallbackQuery> is incoming update container which is a real thing for itself!
[InComingCallbackQuery]
[FunCallbackFilter]
public static async Task<bool> MyAttributedCallback(ICondiment<CallbackQuery> cdmt)
{
// handle
}You also use a combination of normal filters when creating a filter attribute
public class CustomFilterAttribute : MessageFiltersAttribute
{
public CustomFilterAttribute(
string command,
FlamingoChatType chatType)
: base(new CommandFilter(command) & new ChatTypeFilter(chatType))
{ }
}As you can see Flamingo is written as flexible as possible!