-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1x1.h
253 lines (218 loc) · 7.87 KB
/
v1x1.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#ifndef _V1X1_H
#define _V1X1_H 1
#include <stdint.h>
#define MESSAGE 0
#define SCHEDULER_NOTIFY 1
#define DISCORD_VOICE_STATE 2
#define TWITCH 1
#define DISCORD 2
#define SLACK 3
#define MIXER 4
#define YOUTUBE 5
#define CURSE 6
#define API 7
/* A standard UUID */
struct v1x1_uuid {
uint64_t high;
uint64_t low;
} __attribute__((__packed__));
/* A buffer. Used for strings and the like. */
struct v1x1_buffer {
int32_t length;
void *buf;
} __attribute__((__packed__));
/* A tenant is a grouping of channel_groups */
struct v1x1_tenant {
struct v1x1_uuid id;
struct v1x1_buffer display_name;
} __attribute__((__packed__));
/* A channel_group is a grouping of channels on a given platform */
struct v1x1_channel_group {
struct v1x1_buffer id;
struct v1x1_buffer display_name;
uint8_t platform;
struct v1x1_tenant tenant;
} __attribute__((__packed__));
/* A channel is a named location where messages are broadcast and received */
struct v1x1_channel {
struct v1x1_buffer id;
struct v1x1_buffer display_name;
struct v1x1_channel_group channel_group;
} __attribute__((__packed__));
/* A global_user is a grouping of users that belong to the same person */
struct v1x1_global_user {
struct v1x1_uuid id;
} __attribute__((__packed__));
/* A user is an actor on a given platform */
struct v1x1_user {
struct v1x1_buffer id;
struct v1x1_buffer display_name;
uint8_t platform;
struct v1x1_global_user global_user;
} __attribute__((__packed__));
/* A permission is a string that represents a privilege granted */
struct v1x1_permission {
struct v1x1_buffer node;
} __attribute__((__packed__));
/* A permission_set is a list of permissions granted to a user on a channel */
struct v1x1_permission_set {
int32_t length;
struct v1x1_permission *permissions;
} __attribute__((__packed__));
/* A message is a byte sequence sent from a user to a channel */
struct v1x1_message {
struct v1x1_channel channel;
struct v1x1_user sender;
struct v1x1_buffer text;
struct v1x1_permission_set permissions;
} __attribute__((__packed__));
/* An event_message is an event that is fired when a message is received */
struct v1x1_event_message {
struct v1x1_message message;
} __attribute__((__packed__));
/* An event_scheduler_notify is an event that is triggered by v1x1_schedule_once */
struct v1x1_event_scheduler_notify {
struct v1x1_buffer payload;
} __attribute__((__packed__));
/* A discord_voice_state is the state of a user's voice connection on the discord platform */
struct v1x1_discord_voice_state {
struct v1x1_buffer guild_id;
struct v1x1_buffer channel_id;
struct v1x1_buffer user_id;
struct v1x1_buffer session_id;
uint8_t deaf;
uint8_t mute;
uint8_t self_deaf;
uint8_t self_mute;
uint8_t suppress;
} __attribute__((__packed__));
/* An event_discord_voice_state is an event sent when a user's discord_voice_state changes */
struct v1x1_event_discord_voice_state {
struct v1x1_discord_voice_state old_voice_state;
struct v1x1_discord_voice_state new_voice_state;
} __attribute__((__packed__));
/* An event is a struct describing the properties of a given change that is observed by v1x1 */
struct v1x1_event {
uint8_t event_type;
union {
struct v1x1_event_message message_event;
struct v1x1_event_scheduler_notify scheduler_notify_event;
struct v1x1_event_discord_voice_state discord_voice_state_event;
} data;
} __attribute__((__packed__));
/**
* Get the size of the current event
* @return size of the current event
*/
extern int32_t v1x1_event_size(void);
/**
* Read the current event into memory.
* @param ptr Location to read the current event into.
* @param len Max length of event to read
* @return non-zero on success
*/
extern int32_t v1x1_read_event(void *ptr, int len);
/**
* Sends a chat message
* @param channel Channel to send message to
* @param message Text of message to send
* @return non-zero on success
*/
extern int32_t v1x1_send_message(struct v1x1_channel *channel, struct v1x1_buffer *message);
/**
* Clear a user's messages from a channel
* @param channel Channel to clear messages from
* @param user User whose messages we should clear
* @param amount Number of messages to clear (if the platform supports it)
* @param reason Reason for clearing messages
* @return non-zero on success
*/
extern int32_t v1x1_purge(struct v1x1_channel *channel, struct v1x1_user *user, int32_t amount, struct v1x1_buffer *reason);
/**
* Makes a user be quiet
* @param channel Channel where user is not being quiet
* @param user User to make quiet
* @param length Duration (in seconds) to make user quiet for
* @param reason Reason for making user quiet
* @return non-zero on success
*/
extern int32_t v1x1_timeout(struct v1x1_channel *channel, struct v1x1_user *user, int32_t length, struct v1x1_buffer *reason);
/**
* Stop making a user be quiet
* @param channel Channel where the user has been made to be quiet
* @param user User who has been made to be quiet
* @return non-zero on success
*/
extern int32_t v1x1_untimeout(struct v1x1_channel *channel, struct v1x1_user *user);
/**
* Temporarily remove a user from a channel
* @param channel Channel from which to remove the user
* @param user User to be removed
* @param reason Reason for removing the user
* @return non-zero on success
*/
extern int32_t v1x1_kick(struct v1x1_channel *channel, struct v1x1_user *user, struct v1x1_buffer *reason);
/**
* Less temporarily remove a user from a channel
* @param channel Channel from which to remove the user
* @param user User to be removed
* @param length Duration (in seconds) before the user can come back, 0 for indefinite (if supported)
* @param reason Reason for removing the user
* @return non-zero on success
*/
extern int32_t v1x1_ban(struct v1x1_channel *channel, struct v1x1_user *user, int32_t length, struct v1x1_buffer *reason);
/**
* Punish user in the minimal way supported by the platform
* @param channel Channel where the user should be punished
* @param user User to be punished
* @param length Duration (in seconds) to punish the user for (if supported)
* @param reason Reason for punishing the user
* @return non-zero on success
*/
extern int32_t v1x1_punish(struct v1x1_channel *channel, struct v1x1_user *user, int32_t length, struct v1x1_buffer *reason);
/**
* Generates a SCHEDULER_NOTIFY event after a given duration
* @param minutes Duration (in minutes) to wait before delivering the SCHEDULER_NOTIFY event
* @param payload Payload to send in the SCHEDULER_NOTIFY event
* @return non-zero on success
*/
extern int32_t v1x1_schedule_once(int32_t minutes, struct v1x1_buffer *payload);
/**
* Writes a value to the key-value store
* @param key Location to write the value
* @param val Value to write
* @return non-zero on success
*/
extern int32_t v1x1_kvstore_write(struct v1x1_buffer *key, struct v1x1_buffer *val);
/**
* Checks if a value exists in the key-value store at a given key
* @param key Location to look for value
* @return non-zero if key has a value
*/
extern int32_t v1x1_kvstore_has_key(struct v1x1_buffer *key);
/**
* Get the length of a value at a given key in the key-value store
* @param key Location to look for value
* @return Length of value, -1 if key doesn't have a value
*/
extern int32_t v1x1_kvstore_length(struct v1x1_buffer *key);
/**
* Reads a value from the key-value store
* @param key Location to read the value
* @param val Buffer to write the value to
* @return non-zero on success
*/
extern int32_t v1x1_kvstore_read(struct v1x1_buffer *key, struct v1x1_buffer *val);
/**
* Deletes a value from the key-value store
* @param key Location to delete
* @return non-zero on success
*/
extern int32_t v1x1_kvstore_delete(struct v1x1_buffer *key);
/**
* Logs a message
* @param message Message to be logged
* @return non-zero on success
*/
extern int32_t v1x1_log(struct v1x1_buffer *message);
#endif