@duque.edits/sdk 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ class LogManager extends base_1.BaseManager {
18
18
  method: "GET",
19
19
  url: route,
20
20
  });
21
- return response;
21
+ return this.set(response);
22
22
  }
23
23
  async create(data) {
24
24
  const route = this.base_url;
@@ -28,32 +28,40 @@ class LogManager extends base_1.BaseManager {
28
28
  url: route,
29
29
  payload,
30
30
  });
31
- this.set(response);
32
- return response;
33
- }
34
- async createMany(data) {
35
- const route = this.base_url;
36
- const payload = { ...data };
37
- const response = await this.rest.request({
38
- method: "POST",
39
- url: route,
40
- payload,
41
- });
42
- this.set(response);
43
- return response;
31
+ const logEntry = this.set(response);
32
+ this.cache.set(data._id, logEntry);
33
+ this.rest.emit("logEntryCreate", logEntry, this.guild);
34
+ return logEntry;
44
35
  }
36
+ /* async createMany(data: Optional<APILogEntry>[]): Promise<APILogEntry[]> {
37
+ const route = Routes.fields(this.base_url, "bulk");
38
+ const payload = { ...data };
39
+ const response = await this.rest.request<APILogEntry[], typeof payload>({
40
+ method: "POST",
41
+ url: route,
42
+ payload,
43
+ });
44
+
45
+ this.set(response);
46
+ return response;
47
+ } */
45
48
  set(data) {
46
49
  if (!data)
47
50
  return this.cache;
48
51
  if (Array.isArray(data)) {
52
+ this.cache.clear();
49
53
  for (let entry of data) {
50
- this.cache.set(entry._id, entry);
54
+ if (!entry._id)
55
+ continue;
56
+ const logEntry = new structures_1.LogEntry(entry, this);
57
+ this.cache.set(entry._id, logEntry);
51
58
  }
52
59
  return this.cache;
53
60
  }
54
61
  else {
55
- this.cache.set(data._id, data);
56
- return data;
62
+ const logEntry = new structures_1.LogEntry(data, this);
63
+ this.cache.set(data._id, logEntry);
64
+ return logEntry;
57
65
  }
58
66
  }
59
67
  }
package/dist/rest/REST.js CHANGED
@@ -53,15 +53,6 @@ class REST extends events_1.default {
53
53
  await Promise.all([this.guilds.fetch(), this.minesGames.fetch()]);
54
54
  return this;
55
55
  }
56
- /**
57
- * Ping the api
58
- */
59
- async ping() {
60
- return this.request({
61
- url: "/status",
62
- method: "get",
63
- });
64
- }
65
56
  /**
66
57
  * Request Data from a certain url
67
58
  * @param options
@@ -13,7 +13,7 @@ exports.Routes = {
13
13
  delete: (guildId) => `/guilds/${guildId}`,
14
14
  deleteAll: () => `/guilds`,
15
15
  resource: (guildId, resource) => `/guilds/${guildId}/manage/${resource}`,
16
- resources: (guildId, ...resourcess) => `/guilds/${guildId}/manage/${resourcess.join("/")}`,
16
+ resources: (guildId, ...resources) => `/guilds/${guildId}/manage/${resources.join("/")}`,
17
17
  users: {
18
18
  create: (guildId) => `/guilds/${guildId}/users`,
19
19
  update: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
@@ -164,6 +164,29 @@ class Guild {
164
164
  });
165
165
  return this._updateInternals(response);
166
166
  }
167
+ async setChannelIds(type, ...ids) {
168
+ const channel = this.channels.find((c) => c.type === type);
169
+ if (!ids || ids.length === 0)
170
+ return;
171
+ if (!channel) {
172
+ // create new channel if it doesn't exist
173
+ this.channels.push({ type, ids });
174
+ }
175
+ else {
176
+ // merge IDs, remove duplicates
177
+ const chIndex = this.channels.findIndex((ch) => ch.type === type);
178
+ const mergedIds = [...new Set([...ids])];
179
+ this.channels[chIndex] = { ...channel, ids: mergedIds };
180
+ }
181
+ const route = Routes_1.Routes.guilds.get(this.id);
182
+ const payload = { channels: this.channels };
183
+ const response = await this.rest.request({
184
+ method: "PATCH",
185
+ url: route,
186
+ payload,
187
+ });
188
+ return this._updateInternals(response);
189
+ }
167
190
  async removeIdInChannel(type, id) {
168
191
  const chIndex = this.channels.findIndex((c) => c.type === type);
169
192
  if (chIndex !== -1) {
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./guild/Guild"), exports);
18
+ __exportStar(require("./logentry/LogEntry"), exports);
18
19
  __exportStar(require("./match/GuildMatch"), exports);
19
20
  __exportStar(require("./user/GuildUser"), exports);
20
21
  __exportStar(require("./vipmember/VipMember"), exports);
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogEntry = void 0;
4
+ const rest_1 = require("../../rest");
5
+ class LogEntry {
6
+ _id;
7
+ guild_id;
8
+ user_id;
9
+ admin_id;
10
+ object_id;
11
+ type;
12
+ description;
13
+ change;
14
+ before;
15
+ after;
16
+ logs_channel_id;
17
+ createdAt;
18
+ updatedAt;
19
+ manager;
20
+ /** The given guild */
21
+ guild;
22
+ /** The rest client */
23
+ rest;
24
+ constructor(data, manager) {
25
+ this.manager = manager;
26
+ this.guild = manager.guild;
27
+ this._id = data?._id;
28
+ this.guild_id = data?.guild_id;
29
+ this.user_id = data?.user_id;
30
+ this.admin_id = data?.admin_id;
31
+ this.object_id = data?.object_id;
32
+ this.type = data?.type;
33
+ this.description = data?.description;
34
+ this.change = data?.change;
35
+ this.before = data?.before;
36
+ this.after = data?.after;
37
+ this.logs_channel_id = data?.logs_channel_id;
38
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
39
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
40
+ }
41
+ async fetch() {
42
+ const route = rest_1.Routes.guilds.resources(this.guild.id, "logs", this._id);
43
+ const response = await this.rest.request({ url: route, method: "GET" });
44
+ return this._updateInternals(response);
45
+ }
46
+ toJSON() {
47
+ const json = {};
48
+ for (const [key, value] of Object.entries(this)) {
49
+ if (typeof value !== "function") {
50
+ json[key] = value;
51
+ }
52
+ }
53
+ return json;
54
+ }
55
+ _updateInternals(data) {
56
+ for (let key in data) {
57
+ if (key === "id" || key === "createdAt")
58
+ continue;
59
+ if (key in this) {
60
+ this[key] = data[key];
61
+ }
62
+ }
63
+ this.updatedAt = new Date();
64
+ this.manager.cache.set(this._id, this);
65
+ return this;
66
+ }
67
+ }
68
+ exports.LogEntry = LogEntry;
@@ -220,15 +220,15 @@ class GuildUser {
220
220
  const route = Routes_1.Routes.guilds.users.get(this.manager.guild.id, this.id);
221
221
  let payload = {};
222
222
  const numericFields = ["wins", "points", "losses", "mvps", "games", "creations"];
223
- const arrayFields = ["items", "original_channels"];
223
+ const arrayFields = ["items", "original_channels", "adverts"];
224
224
  if (data?.type === "add" || data?.type === "remove") {
225
225
  for (const key in data) {
226
226
  if (key === "type")
227
227
  continue;
228
228
  const value = data[key];
229
229
  if (numericFields.includes(key)) {
230
- const current = this[key];
231
- const num = value;
230
+ const current = (this[key] || 0);
231
+ const num = (value || 0);
232
232
  payload[key] = Math.max(0, data?.type === "add" ? current + num : current - num);
233
233
  }
234
234
  else if (key === "blacklist") {
@@ -1,2 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogEntryTypes = void 0;
4
+ var LogEntryTypes;
5
+ (function (LogEntryTypes) {
6
+ LogEntryTypes["QueueCreated"] = "queue_created";
7
+ LogEntryTypes["QueueShut"] = "queue_shut";
8
+ LogEntryTypes["MatchStarted"] = "match_started";
9
+ LogEntryTypes["MatchUpdated"] = "match_updated";
10
+ LogEntryTypes["MatchClosed"] = "match_closed";
11
+ LogEntryTypes["UserUpdated"] = "user_updated";
12
+ LogEntryTypes["UserManaged"] = "user_managed";
13
+ })(LogEntryTypes || (exports.LogEntryTypes = LogEntryTypes = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "main": "dist/index",
5
5
  "types": "./types/index.d.ts",
6
6
  "typings": "./types/index.d.ts",
@@ -1,11 +1,10 @@
1
- import { Collection, Guild } from "../../structures";
1
+ import { Collection, Guild, LogEntry } from "../../structures";
2
2
  import { Optional } from "../../types";
3
3
  import { APILogEntry } from "../../types/api/APILogEntry";
4
4
  import { BaseManager } from "../base";
5
- export declare class LogManager extends BaseManager<APILogEntry> {
5
+ export declare class LogManager extends BaseManager<LogEntry> {
6
6
  constructor(guild: Guild);
7
- fetch(): Promise<APILogEntry[]>;
8
- create(data: Optional<APILogEntry>): Promise<APILogEntry>;
9
- createMany(data: Optional<APILogEntry>[]): Promise<APILogEntry[]>;
10
- set(data: APILogEntry | APILogEntry[]): APILogEntry | Collection<string, APILogEntry>;
7
+ fetch(): Promise<Collection<string, LogEntry>>;
8
+ create(data: Optional<APILogEntry>): Promise<LogEntry>;
9
+ set(data: APILogEntry | APILogEntry[]): LogEntry | Collection<string, LogEntry>;
11
10
  }
@@ -31,10 +31,6 @@ export declare class REST extends EventEmitter {
31
31
  constructor(options: ClientOptions);
32
32
  /** Initialize the caching sistem */
33
33
  init(): Promise<this>;
34
- /**
35
- * Ping the api
36
- */
37
- ping(): Promise<unknown>;
38
34
  /**
39
35
  * Request Data from a certain url
40
36
  * @param options
@@ -10,7 +10,7 @@ export declare const Routes: {
10
10
  delete: (guildId: string) => string;
11
11
  deleteAll: () => string;
12
12
  resource: (guildId: string, resource: string) => string;
13
- resources: (guildId: string, ...resourcess: string[]) => string;
13
+ resources: (guildId: string, ...resources: string[]) => string;
14
14
  users: {
15
15
  create: (guildId: string) => string;
16
16
  update: (guildId: string, userId: string) => string;
@@ -55,6 +55,7 @@ export declare class Guild {
55
55
  createCode(data: Optional<APICode>): Promise<this>;
56
56
  removeCode(codeId: string): Promise<this>;
57
57
  addIdToChannel(type: GuildChannelsType, id: string | string[]): Promise<this>;
58
+ setChannelIds(type: GuildChannelsType, ...ids: string[]): Promise<this>;
58
59
  removeIdInChannel(type: GuildChannelsType, id: string): Promise<this>;
59
60
  _start(): Promise<this>;
60
61
  _updateInternals(data: Optional<APIGuild>): this;
@@ -1,4 +1,5 @@
1
1
  export * from "./guild/Guild";
2
+ export * from "./logentry/LogEntry";
2
3
  export * from "./match/GuildMatch";
3
4
  export * from "./user/GuildUser";
4
5
  export * from "./vipmember/VipMember";
@@ -0,0 +1,28 @@
1
+ import { LogManager } from "../../managers";
2
+ import { REST } from "../../rest";
3
+ import { APILogEntry, LogEntryTypes, Optional } from "../../types";
4
+ import { Guild } from "../guild/Guild";
5
+ export declare class LogEntry {
6
+ _id: string;
7
+ guild_id: string;
8
+ user_id: string;
9
+ admin_id: string;
10
+ object_id: string;
11
+ type: LogEntryTypes;
12
+ description: string;
13
+ change: string;
14
+ before: any;
15
+ after: any;
16
+ logs_channel_id: string;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ manager: LogManager;
20
+ /** The given guild */
21
+ readonly guild: Guild;
22
+ /** The rest client */
23
+ readonly rest: REST;
24
+ constructor(data: APILogEntry, manager: LogManager);
25
+ fetch(): Promise<LogEntry>;
26
+ toJSON(): Record<string, unknown>;
27
+ _updateInternals(data: Optional<APILogEntry>): this;
28
+ }
@@ -1,3 +1,4 @@
1
+ import { LogEntry } from "../structures";
1
2
  import { Collection } from "../structures/Collection";
2
3
  import { Guild } from "../structures/guild/Guild";
3
4
  import { GuildMatch } from "../structures/match/GuildMatch";
@@ -31,4 +32,5 @@ export interface RestEvents {
31
32
  userDelete: [GuildUser];
32
33
  userUpdate: [GuildUser];
33
34
  usersDelete: [Collection<string, GuildUser>];
35
+ logEntryCreate: [LogEntry, Guild];
34
36
  }
@@ -21,6 +21,7 @@ export interface GuildStatus {
21
21
  logs_queues: "on" | "off";
22
22
  logs_users: "on" | "off";
23
23
  logs_managing: "on" | "off";
24
+ name_hidden: "on" | "off";
24
25
  }
25
26
  export interface GuildModes {
26
27
  on: string[];
@@ -1,9 +1,24 @@
1
+ export declare enum LogEntryTypes {
2
+ QueueCreated = "queue_created",
3
+ QueueShut = "queue_shut",
4
+ MatchStarted = "match_started",
5
+ MatchUpdated = "match_updated",
6
+ MatchClosed = "match_closed",
7
+ UserUpdated = "user_updated",
8
+ UserManaged = "user_managed"
9
+ }
1
10
  export interface APILogEntry {
2
11
  _id: string;
3
12
  guild_id: string;
4
- type: string;
5
13
  user_id: string;
14
+ admin_id: string;
15
+ object_id: string;
16
+ type: LogEntryTypes;
6
17
  description: string;
18
+ change: string;
19
+ logs_channel_id: string;
20
+ before: any;
21
+ after: any;
7
22
  createdAt: Date;
8
23
  updatedAt: Date;
9
24
  }