Skip to content

Commit 30a1d16

Browse files
committed
Update tags, add reminders
- Update tags -> Add `{ocr}` and `{translate}` -> Implement usage stats (finally) - Update commands that have languaige parameters -> Add `random` as a language which will pick a random one - Add `.remind` and `/reminder create` -> WIP so the list/delete commands aren't implemented yet (sorry)
1 parent 4dc862e commit 30a1d16

37 files changed

+1133
-70
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
],
1010
"dependencies": {
1111
"@sentry/node": "^6.4.1",
12-
"detritus-client": "^0.17.0-beta.0",
12+
"chrono-node": "^2.3.8",
13+
"detritus-client": "^0.17.0-beta.1",
1314
"emoji-aware": "^3.0.5",
1415
"juration": "^0.1.1",
1516
"moment": "^2.29.1",

src/api/endpoints.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const Api = Object.freeze({
1818
AUDIO_TOOLS_IDENTIFY:
1919
'/audio/tools/identify',
2020

21+
CHANNEL:
22+
'/channels/:channelId',
23+
2124
COMMANDS:
2225
'/commands',
2326

@@ -175,6 +178,11 @@ export const Api = Object.freeze({
175178
ME:
176179
'/users/@me',
177180

181+
REMINDERS:
182+
'/reminders',
183+
REMINDER:
184+
'/reminders/:reminderId',
185+
178186
SEARCH_DUCKDUCKGO:
179187
'/search/duckduckgo',
180188
SEARCH_DUCKDUCKGO_IMAGES:
@@ -222,13 +230,19 @@ export const Api = Object.freeze({
222230
'/tags/random',
223231
TAGS_SERVER:
224232
'/tags/servers/:serverId',
233+
TAG_USE:
234+
'/tags/:tagId/use',
225235

226236
USER:
227237
'/users/:userId',
228238
USER_COMMANDS:
229239
'/users/:userId/commands',
230240
USER_COMMAND:
231241
'/users/:userId/commands/:command',
242+
USER_REMINDERS:
243+
'/users/:userId/reminders',
244+
USER_REMINDERS_EXPIRED:
245+
'/users/:userId/reminders/expired',
232246
USER_TAGS:
233247
'/users/:userId/tags',
234248

src/api/index.ts

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
GuildSettingsLogger,
2020
GuildSettingsPrefix,
2121
} from './structures/guildsettings';
22-
import { User } from './structures/user';
22+
import { UserFull } from './structures/user';
2323
import { RestOptions, RestResponses } from './types';
2424

2525
export { request } from './raw';
@@ -111,6 +111,23 @@ export async function createGuildPrefix(
111111
}
112112

113113

114+
export async function createReminder(
115+
context: RequestContext,
116+
options: RestOptions.CreateReminder,
117+
) {
118+
return raw.createReminder(context, options);
119+
}
120+
121+
122+
export async function createTagUse(
123+
context: RequestContext,
124+
tagId: string,
125+
options: RestOptions.CreateTagUse,
126+
) {
127+
return raw.createTagUse(context, tagId, options);
128+
}
129+
130+
114131
export async function createUserCommand(
115132
context: RequestContext,
116133
userId: string,
@@ -121,6 +138,15 @@ export async function createUserCommand(
121138
}
122139

123140

141+
export async function deleteChannel(
142+
context: RequestContext,
143+
channelId: string,
144+
options: RestOptions.DeleteChannel,
145+
) {
146+
return raw.deleteChannel(context, channelId, options);
147+
}
148+
149+
124150
export async function deleteGuildAllowlist(
125151
context: RequestContext,
126152
guildId: string,
@@ -190,6 +216,14 @@ export async function deleteGuildPrefix(
190216
}
191217

192218

219+
export async function deleteReminder(
220+
context: RequestContext,
221+
reminderId: string,
222+
) {
223+
return raw.deleteReminder(context, reminderId);
224+
}
225+
226+
193227
export async function deleteTag(
194228
context: RequestContext,
195229
options: RestOptions.DeleteTag,
@@ -215,18 +249,19 @@ export async function editGuildSettings(
215249
return settings;
216250
}
217251

252+
218253
export async function editUser(
219254
context: RequestContext,
220255
userId: string,
221256
options: RestOptions.EditUser,
222257
): Promise<RestResponses.EditUser> {
223258
const data = await raw.editUser(context, userId, options);
224-
let user: User;
259+
let user: UserFull;
225260
if (UserStore.has(userId)) {
226-
user = UserStore.get(userId) as User;
261+
user = UserStore.get(userId)!;
227262
user.merge(data);
228263
} else {
229-
user = new User(data);
264+
user = new UserFull(data);
230265
UserStore.set(user.id, user);
231266
}
232267
return user;
@@ -250,6 +285,14 @@ export async function fetchGuildSettings(
250285
}
251286

252287

288+
export async function fetchReminders(
289+
context: RequestContext,
290+
options: RestOptions.FetchReminders,
291+
) {
292+
return raw.fetchReminders(context, options);
293+
}
294+
295+
253296
export async function fetchTag(
254297
context: RequestContext,
255298
options: RestOptions.FetchTag,
@@ -280,12 +323,12 @@ export async function fetchUser(
280323
userId: string,
281324
): Promise<RestResponses.FetchUser> {
282325
const data = await raw.fetchUser(context, userId);
283-
let user: User;
326+
let user: UserFull;
284327
if (UserStore.has(userId)) {
285-
user = UserStore.get(userId) as User;
328+
user = UserStore.get(userId)!;
286329
user.merge(data);
287330
} else {
288-
user = new User(data);
331+
user = new UserFull(data);
289332
UserStore.set(user.id, user);
290333
}
291334
return user;
@@ -806,12 +849,12 @@ export async function putUser(
806849
options: RestOptions.PutUser,
807850
): Promise<RestResponses.PutUser> {
808851
const data = await raw.putUser(context, userId, options);
809-
let user: User;
852+
let user: UserFull;
810853
if (UserStore.has(userId)) {
811-
user = UserStore.get(userId) as User;
854+
user = UserStore.get(userId)!;
812855
user.merge(data);
813856
} else {
814-
user = new User(data);
857+
user = new UserFull(data);
815858
UserStore.set(user.id, user);
816859
}
817860
return user;

src/api/raw.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface RequestContext {
2020
channelId?: string,
2121
client: ShardClient,
2222
guildId?: string,
23+
inDm?: boolean,
2324
user?: Structures.User,
2425
}
2526

@@ -51,6 +52,7 @@ export async function request(
5152
const bareUser = JSON.stringify({
5253
avatar: user.avatar,
5354
discriminator: user.discriminator,
55+
channel_id: (context.inDm) ? context.channelId : undefined,
5456
bot: user.bot,
5557
id: user.id,
5658
username: user.username,
@@ -188,6 +190,50 @@ export async function createGuildPrefix(
188190
}
189191

190192

193+
export async function createReminder(
194+
context: RequestContext,
195+
options: RestOptions.CreateReminder,
196+
): Promise<RestResponsesRaw.CreateReminder> {
197+
const body = {
198+
channel_id: options.channelId,
199+
content: options.content,
200+
guild_id: options.guildId,
201+
is_all_day: options.isAllDay,
202+
message_id: options.messageId,
203+
timestamp_end: options.timestampEnd,
204+
timestamp_start: options.timestampStart,
205+
};
206+
return request(context, {
207+
body,
208+
route: {
209+
method: HTTPMethods.POST,
210+
path: Api.REMINDERS,
211+
},
212+
});
213+
}
214+
215+
216+
export async function createTagUse(
217+
context: RequestContext,
218+
tagId: string,
219+
options: RestOptions.CreateTagUse,
220+
): Promise<RestResponsesRaw.CreateTagUse> {
221+
const body = {
222+
timestamp: options.timestamp,
223+
user_id: options.userId,
224+
};
225+
const params = {tagId};
226+
return request(context, {
227+
body,
228+
route: {
229+
method: HTTPMethods.POST,
230+
path: Api.TAG_USE,
231+
params,
232+
},
233+
});
234+
}
235+
236+
191237
export async function createUserCommand(
192238
context: RequestContext,
193239
userId: string,
@@ -214,6 +260,24 @@ export async function createUserCommand(
214260
}
215261

216262

263+
export async function deleteChannel(
264+
context: RequestContext,
265+
channelId: string,
266+
options: RestOptions.DeleteChannel,
267+
): Promise<RestResponsesRaw.DeleteChannel> {
268+
return request(context, {
269+
query: {
270+
guild_id: options.guildId,
271+
},
272+
route: {
273+
method: HTTPMethods.DELETE,
274+
path: Api.CHANNEL,
275+
params: {channelId},
276+
},
277+
});
278+
}
279+
280+
217281
export async function deleteGuildAllowlist(
218282
context: RequestContext,
219283
guildId: string,
@@ -302,6 +366,20 @@ export async function deleteGuildPrefix(
302366
}
303367

304368

369+
export async function deleteReminder(
370+
context: RequestContext,
371+
reminderId: string,
372+
): Promise<RestResponsesRaw.DeleteReminder> {
373+
return request(context, {
374+
route: {
375+
method: HTTPMethods.DELETE,
376+
path: Api.REMINDER,
377+
params: {reminderId},
378+
},
379+
});
380+
}
381+
382+
305383
export async function deleteTag(
306384
context: RequestContext,
307385
options: RestOptions.DeleteTag,
@@ -352,6 +430,7 @@ export async function editUser(
352430
): Promise<RestResponsesRaw.EditUser> {
353431
const body = {
354432
blocked: options.blocked,
433+
channel_id: options.channelId,
355434
locale: options.locale,
356435
opt_out_content: options.optOutContent,
357436
};
@@ -382,6 +461,28 @@ export async function fetchGuildSettings(
382461
}
383462

384463

464+
export async function fetchReminders(
465+
context: RequestContext,
466+
options: RestOptions.FetchReminders = {},
467+
): Promise<RestResponsesRaw.FetchReminders> {
468+
const query = {
469+
after: options.after,
470+
before: options.before,
471+
guild_id: options.guildId,
472+
limit: options.limit,
473+
timestamp_max: options.timestampMax,
474+
timestamp_min: options.timestampMin,
475+
};
476+
return request(context, {
477+
query,
478+
route: {
479+
method: HTTPMethods.GET,
480+
path: Api.REMINDERS,
481+
},
482+
});
483+
}
484+
485+
385486
export async function fetchTag(
386487
context: RequestContext,
387488
options: RestOptions.FetchTag,
@@ -1671,6 +1772,7 @@ export async function putUser(
16711772
const body = {
16721773
avatar: options.avatar,
16731774
bot: options.bot,
1775+
channel_id: options.channelId,
16741776
discriminator: options.discriminator,
16751777
locale: options.locale,
16761778
username: options.username,

0 commit comments

Comments
 (0)