This repository has been archived by the owner on Aug 2, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathplugin.h
60 lines (52 loc) · 2.74 KB
/
plugin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "cqhttp/core/common.h"
#include "cqhttp/core/context.h"
#include "cqhttp/core/event.h"
namespace cqhttp {
/**
* Lifecycle:
*
* +-------------------------------------------------+
* | hook_initialize |
* | + |
* | | enabled by user |
* | v |
* | hook_coolq_start |
* | hook_enable+-----------+ |
* | + | disabled by user |
* | | coolq closed v |
* | v hook_disable |
* | hook_disable + |
* | hook_coolq_exit | coolq closed |
* | v |
* | hook_coolq_exit |
* +-------------------------------------------------+
*
* The lifecycle here is NOT quite the same as one in "cqsdk" module,
* because "cqhttp::Application" class will generate a fake "disable" event
* if necessary at exit, which means "hook_enable" and "hook_disable" methods
* are guaranteed to be called as a pair, so plugins can safely start
* their services in "hook_enable" and stop in "hook_disable" and have no need
* to care about the "coolq_*" events.
*/
struct Plugin {
Plugin() = default;
virtual ~Plugin() = default;
virtual std::string name() const = 0;
virtual void hook_initialize(Context &ctx) { ctx.next(); }
virtual void hook_enable(Context &ctx) { ctx.next(); }
virtual void hook_disable(Context &ctx) { ctx.next(); }
virtual void hook_coolq_start(Context &ctx) { ctx.next(); }
virtual void hook_coolq_exit(Context &ctx) { ctx.next(); }
virtual void hook_before_event(EventContext<cq::Event> &ctx) { ctx.next(); }
virtual void hook_message_event(EventContext<cq::MessageEvent> &ctx) { ctx.next(); }
virtual void hook_notice_event(EventContext<cq::NoticeEvent> &ctx) { ctx.next(); }
virtual void hook_request_event(EventContext<cq::RequestEvent> &ctx) { ctx.next(); }
virtual void hook_meta_event(EventContext<cqhttp::MetaEvent> &ctx) { ctx.next(); }
virtual void hook_after_event(EventContext<cq::Event> &ctx) { ctx.next(); }
virtual void hook_before_action(ActionContext &ctx) { ctx.next(); }
virtual void hook_missed_action(ActionContext &ctx) { ctx.next(); }
virtual void hook_after_action(ActionContext &ctx) { ctx.next(); }
virtual bool good() const { return true; }
};
} // namespace cqhttp