template<class T, class C>
class dpp::collector< T, C >
Collects objects from events during a specified time period.
This template must be specialised. There are premade specialisations which you can use such as dpp::reaction_collector and dpp::message_collector. For these specialised instances all you need to do is derive a simple class from them which implements collector::completed().
A collector will run for the specified number of seconds, attaching itself to the given event. During this time any events pass through the collector and collector::filter(). This function can return a pointer to an object to allow a copy of that object to be stored to a vector, or it can return nullptr to do nothing with that object. For example a collector attached to on_message_create would receive an event with the type message_create_t, and from this may decide to extract the message_create_t::msg structure, returning a pointer to it, or instead may choose to return a nullptr.
When either the predetermined timeout is reached, or the collector::cancel() method is called, or the collector is destroyed, the collector::completed() method is called, which will be passed a list of collected objects in the order they were collected.
- Template Parameters
-
T | parameter type of the event this collector will monitor |
C | object type this collector will store |
template<class T , class C >
Filter the list of elements.
Every time an event is fired on the collector, this method wil be called to determine if we should add an object to the list or not. This function can then process the element
value, extract the parts which are to be saved to a list (e.g. a dpp::message out of a dpp::message_create_t) and return it as the return value. Returning a value of nullptr causes no object to be stored.
Here is an example of how to filter messages which have specific text in them. This should be used with the specialised type dpp::message_collector
if (m.
msg.
content.find(
"something i want") != std::string::npos) {
} else {
return nullptr;
}
}
virtual const C * filter(const T &element)=0
Filter the list of elements.
Create message.
Definition: dispatcher.h:1358
message msg
message that was created (sent).
Definition: dispatcher.h:1367
Represents messages sent and received on Discord.
Definition: message.h:1127
std::string content
Definition: message.h:1137
- Parameters
-
element | The event data to filter |
- Returns
- const C* Returned object or nullptr