-
Notifications
You must be signed in to change notification settings - Fork 3
Light, camera and action
tostc edited this page Jan 2, 2021
·
2 revisions
In this chapter we take a look to the new action system of the framework. We learn how to create and use action, so let's get started.
Actions are not a part of the Discord API, but an event system of the framework. These actions are an advanced version of the event callbacks of the controller interface. With the help of actions you can triggered by a given event on a specific channel, which can also be filtered, but later more.
MyAction.hpp
#ifndef MYACTION_HPP
#define MYACTION_HPP
#include <models/Action.hpp>
#include <iostream>
using namespace std;
class CMyAction : public DiscordBot::CAction<GuildMember>
{
public:
CMyAction() : CAction(ActionType::USER_JOIN | ActionType::USER_LEAVE) {}
// Important this must be the same type as given as template parameter.
// |
// V
void FireAction(DiscordBot::ActionType Type, Channel c, GuildMember val)
{
// Prints the nick or username of the user, who has triggered the event.
if(Type == ActionType::USER_JOIN)
cout << (val->Nick != "" ? val->Nick.load() : val->UserRef->Username.load()) << " is no in " << c->Name << endl;
else
{
cout << (val->Nick != "" ? val->Nick.load() : val->UserRef->Username.load()) << " has leaved " << c->Name << endl;
}
}
~CMyAction() {}
};
#endif