-
Notifications
You must be signed in to change notification settings - Fork 0
Filters
Filters are a great and important part of handlers which are required if you want to specify what exact kind of update and their properties value should be.
Filters are generic classes and they can help you choose from properties of any object. But when they come to be used in handlers their Generic parameter should be an ICondiment<T>
where T is an update type like ICondiment<Message>.
Filters has been built using base Class FilterBase<T>. so if you need to build a filter for a message handler u should use FilterBase<ICondiment<Message>>. you use this as a base class to create a custom Filter class Or you can create an instance of it directly.
The most important part of filters is that they can be combined! you can combine them using bitwise operators ( &|~ ).
-
&asAND -
|asOR -
~asNOT
There are a batch of ready to use filters that are already created for some update types. You can find these under following namespaces:
using Flamingo.Filters.MessageFilters // for message filter
using Flamingo.Filters.CallbackQueryFilters // for callback query
using Flamingo.Filters.InlineQueryFilters // for inline query
...
...
// and for other updatesIf you can't find the filter you want yet, then make it yourself! There're base classes for each update that helps you create filter. Find them under:
using Flamingo.Filters
MessageFilter // to create your own message filter
CallbackQueryFilter // to create your own callback queries filter
InlineQueryFilter // to create your own inline queries filter
...
...These can be used as base classes or directly.
var myFunFilter = new MessageFilter(x=> x.StringQuery == "fun");
// x is an ICondiment<Message>and a custom filter just created.
Create you filter class first
public class FunMessageFilter : MessageFilter
{
// x is an ICondiment<Message>
public FunMessageFilter(string funText)
: base(x=> x.StringQuery == funText)
{ }
}Use it
var myFunFilter = new FunMessageFilter("fun"); Easy yeah?