@globalart/nestcord 1.5.7 → 1.5.8

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.
Files changed (24) hide show
  1. package/dist/pagination/src/builders/base-pagination.builder.d.ts +9 -0
  2. package/dist/pagination/src/builders/base-pagination.builder.js +13 -0
  3. package/dist/pagination/src/{helpers/pagination-builder.helper.d.ts → builders/buttons-padgination.builder.d.ts} +7 -17
  4. package/dist/pagination/src/{helpers/pagination-builder.helper.js → builders/buttons-padgination.builder.js} +14 -23
  5. package/dist/pagination/src/builders/index.d.ts +1 -0
  6. package/dist/pagination/src/builders/index.js +2 -0
  7. package/dist/pagination/src/builders/select-menu-pagination.builder.d.ts +16 -0
  8. package/dist/pagination/src/builders/select-menu-pagination.builder.js +48 -0
  9. package/dist/pagination/src/enums/pagination-action.enum.d.ts +4 -0
  10. package/dist/pagination/src/enums/pagination-action.enum.js +6 -1
  11. package/dist/pagination/src/index.d.ts +0 -1
  12. package/dist/pagination/src/index.js +0 -1
  13. package/dist/pagination/src/interfaces/nestcord-pagination-options.interface.d.ts +9 -5
  14. package/dist/pagination/src/nestcord-pagination.service.d.ts +4 -4
  15. package/dist/pagination/src/nestcord-pagination.service.js +17 -38
  16. package/dist/pagination/src/types/paginator-builder.type.d.ts +4 -0
  17. package/dist/pagination/src/types/paginator-builder.type.js +2 -0
  18. package/dist/stat-reporter/src/interfaces/nestcord-stat-reporter-options.interface.d.ts +11 -16
  19. package/dist/stat-reporter/src/nestcord-stat-reporter.service.js +4 -2
  20. package/package.json +1 -1
  21. package/dist/pagination/src/helpers/index.d.ts +0 -2
  22. package/dist/pagination/src/helpers/index.js +0 -18
  23. /package/dist/pagination/src/{helpers/page-builder.helper.d.ts → builders/page.builder.d.ts} +0 -0
  24. /package/dist/pagination/src/{helpers/page-builder.helper.js → builders/page.builder.js} +0 -0
@@ -0,0 +1,9 @@
1
+ import { NestCordPaginationOptions } from '../interfaces';
2
+ import { BaseMessageOptions as PageOptions } from 'discord.js';
3
+ export declare abstract class BasePaginationBuilder {
4
+ readonly options: NestCordPaginationOptions;
5
+ customId: string;
6
+ constructor(options: NestCordPaginationOptions);
7
+ setCustomId(value: string): this;
8
+ abstract build(args: unknown): Promise<PageOptions>;
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePaginationBuilder = void 0;
4
+ class BasePaginationBuilder {
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ setCustomId(value) {
9
+ this.customId = value;
10
+ return this;
11
+ }
12
+ }
13
+ exports.BasePaginationBuilder = BasePaginationBuilder;
@@ -1,29 +1,19 @@
1
1
  import { BaseMessageOptions as PageOptions } from 'discord.js';
2
- import { PageBuilder } from './page-builder.helper';
3
- import { ButtonAppearance, NestCordPaginationOptions } from '../interfaces';
2
+ import { ButtonAppearance } from '../interfaces';
3
+ import { BasePaginationBuilder } from './base-pagination.builder';
4
+ import { PageBuilder } from './page.builder';
4
5
  type PagesFactory = (page: number, maxPages: number) => Promise<PageBuilder>;
5
- export declare class PaginationBuilder {
6
- customId: string;
7
- customOptions: string[];
6
+ export declare class ButtonsPaginationBuilder extends BasePaginationBuilder {
8
7
  buttons: ButtonAppearance[][];
9
- private _maxPages;
10
8
  private pages;
9
+ private _maxPages;
11
10
  private pagesFactory;
12
11
  get maxPages(): number;
13
12
  set maxPages(value: number);
14
- /**
15
- * Developer-defined identifier for the button;
16
- */
17
- setCustomId(value: string): this;
18
- setMaxPages(maxPages: number): this;
19
13
  setPages(pages: PageBuilder[]): this;
20
- setPagesFactory(factory: PagesFactory): this;
21
- /**
22
- * Set buttons for the navigation
23
- */
24
14
  setButtons(buttons: ButtonAppearance[][]): this;
25
- private readonly options;
26
- constructor(options: NestCordPaginationOptions);
15
+ setPagesFactory(factory: PagesFactory): this;
16
+ setMaxPages(maxPages: number): this;
27
17
  build(page?: number): Promise<PageOptions>;
28
18
  private createButtons;
29
19
  }
@@ -9,10 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PaginationBuilder = void 0;
12
+ exports.ButtonsPaginationBuilder = void 0;
13
13
  const discord_js_1 = require("discord.js");
14
+ const base_pagination_builder_1 = require("./base-pagination.builder");
14
15
  const assert = require("assert");
15
- class PaginationBuilder {
16
+ class ButtonsPaginationBuilder extends base_pagination_builder_1.BasePaginationBuilder {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.pages = [];
20
+ }
16
21
  get maxPages() {
17
22
  if (this.pages.length) {
18
23
  return this.pages.length;
@@ -22,36 +27,22 @@ class PaginationBuilder {
22
27
  set maxPages(value) {
23
28
  this._maxPages = value;
24
29
  }
25
- /**
26
- * Developer-defined identifier for the button;
27
- */
28
- setCustomId(value) {
29
- this.customId = value;
30
- return this;
31
- }
32
- setMaxPages(maxPages) {
33
- this.maxPages = maxPages;
34
- return this;
35
- }
36
30
  setPages(pages) {
37
31
  this.pages = pages;
38
32
  return this;
39
33
  }
34
+ setButtons(buttons) {
35
+ this.buttons = buttons;
36
+ return this;
37
+ }
40
38
  setPagesFactory(factory) {
41
39
  this.pagesFactory = factory;
42
40
  return this;
43
41
  }
44
- /**
45
- * Set buttons for the navigation
46
- */
47
- setButtons(buttons) {
48
- this.buttons = buttons;
42
+ setMaxPages(maxPages) {
43
+ this.maxPages = maxPages;
49
44
  return this;
50
45
  }
51
- constructor(options) {
52
- this.pages = [];
53
- this.options = options;
54
- }
55
46
  build() {
56
47
  return __awaiter(this, arguments, void 0, function* (page = 1) {
57
48
  page = Math.max(1, Math.min(page, this.maxPages)) || 1;
@@ -85,4 +76,4 @@ class PaginationBuilder {
85
76
  });
86
77
  }
87
78
  }
88
- exports.PaginationBuilder = PaginationBuilder;
79
+ exports.ButtonsPaginationBuilder = ButtonsPaginationBuilder;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { BaseMessageOptions as PageOptions } from 'discord.js';
2
+ import { BasePaginationBuilder } from './base-pagination.builder';
3
+ import { MenuAppearance } from '../interfaces';
4
+ import { PageBuilder } from './page.builder';
5
+ export declare class SelectMenuPaginationBuilder extends BasePaginationBuilder {
6
+ private items;
7
+ private pages;
8
+ setPages(data: {
9
+ pageId: string;
10
+ builder: PageBuilder;
11
+ }[]): this;
12
+ private getPagesMap;
13
+ setSelectMenuItems(value: MenuAppearance[]): this;
14
+ build(page: string): Promise<PageOptions>;
15
+ private createMenuItems;
16
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SelectMenuPaginationBuilder = void 0;
13
+ const discord_js_1 = require("discord.js");
14
+ const base_pagination_builder_1 = require("./base-pagination.builder");
15
+ const assert = require("assert");
16
+ class SelectMenuPaginationBuilder extends base_pagination_builder_1.BasePaginationBuilder {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.items = [];
20
+ this.pages = [];
21
+ }
22
+ setPages(data) {
23
+ this.pages = data;
24
+ return this;
25
+ }
26
+ getPagesMap() {
27
+ return new Map(this.pages.map(({ pageId, builder }) => [pageId, builder]));
28
+ }
29
+ setSelectMenuItems(value) {
30
+ this.items = value;
31
+ return this;
32
+ }
33
+ build(page) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ var _a;
36
+ assert(this.customId, 'Custom id must be set');
37
+ const pageBuilder = this.getPagesMap().get(page);
38
+ assert(pageBuilder, `Page builder not found for page: ${page}`);
39
+ const pageOptions = pageBuilder.build();
40
+ const row = new discord_js_1.ActionRowBuilder().addComponents(this.createMenuItems(this.items));
41
+ return Object.assign(Object.assign({}, pageOptions), { components: [row, ...((_a = pageOptions.components) !== null && _a !== void 0 ? _a : [])] });
42
+ });
43
+ }
44
+ createMenuItems(items) {
45
+ return new discord_js_1.StringSelectMenuBuilder().setCustomId(`nestcord-pagination/${this.customId}`).addOptions(items);
46
+ }
47
+ }
48
+ exports.SelectMenuPaginationBuilder = SelectMenuPaginationBuilder;
@@ -1,3 +1,7 @@
1
+ export declare enum PaginatorTypeEnum {
2
+ BUTTONS = "buttons",
3
+ SELECT_MENU = "select_menu"
4
+ }
1
5
  export declare enum PaginationAction {
2
6
  First = "first",
3
7
  Next = "next",
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PaginationAction = void 0;
3
+ exports.PaginationAction = exports.PaginatorTypeEnum = void 0;
4
+ var PaginatorTypeEnum;
5
+ (function (PaginatorTypeEnum) {
6
+ PaginatorTypeEnum["BUTTONS"] = "buttons";
7
+ PaginatorTypeEnum["SELECT_MENU"] = "select_menu";
8
+ })(PaginatorTypeEnum || (exports.PaginatorTypeEnum = PaginatorTypeEnum = {}));
4
9
  var PaginationAction;
5
10
  (function (PaginationAction) {
6
11
  PaginationAction["First"] = "first";
@@ -1,6 +1,5 @@
1
1
  export * from './enums';
2
2
  export * from './exceptions';
3
3
  export * from './interfaces';
4
- export * from './helpers';
5
4
  export * from './nestcord-pagination.module';
6
5
  export * from './nestcord-pagination.service';
@@ -17,6 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./enums"), exports);
18
18
  __exportStar(require("./exceptions"), exports);
19
19
  __exportStar(require("./interfaces"), exports);
20
- __exportStar(require("./helpers"), exports);
21
20
  __exportStar(require("./nestcord-pagination.module"), exports);
22
21
  __exportStar(require("./nestcord-pagination.service"), exports);
@@ -1,5 +1,5 @@
1
1
  import { ButtonStyle } from 'discord.js';
2
- import { PaginationAction } from '../enums';
2
+ import { PaginationAction, PaginatorTypeEnum } from '../enums';
3
3
  export interface ButtonAppearance {
4
4
  style: ButtonStyle;
5
5
  label: string;
@@ -9,6 +9,13 @@ export interface ButtonAppearance {
9
9
  link?: string;
10
10
  options?: string;
11
11
  }
12
+ export interface MenuAppearance {
13
+ label: string;
14
+ value: string;
15
+ description?: string;
16
+ emoji?: string;
17
+ default?: boolean;
18
+ }
12
19
  export interface ModalAppearance {
13
20
  title?: string;
14
21
  label?: string;
@@ -18,8 +25,5 @@ export type ButtonsAppearance = {
18
25
  [key in PaginationAction]?: Partial<ButtonAppearance>;
19
26
  };
20
27
  export interface NestCordPaginationOptions {
21
- buttons?: ButtonsAppearance;
22
- modal?: ModalAppearance;
23
- allowSkip?: boolean;
24
- allowTraversal?: boolean;
28
+ type: PaginatorTypeEnum;
25
29
  }
@@ -1,11 +1,11 @@
1
- import { PaginationBuilder } from './helpers';
2
1
  import { NestCordPaginationOptions } from './interfaces';
2
+ import { PaginatorTypeEnum } from './enums';
3
+ import { PaginationBuilder } from './types/paginator-builder.type';
3
4
  export declare class NestCordPaginationService {
4
5
  private readonly options;
5
- private static readonly DEFAULT_OPTIONS;
6
6
  private readonly cache;
7
7
  constructor(options: NestCordPaginationOptions);
8
- register(factory: (builder: PaginationBuilder) => PaginationBuilder): PaginationBuilder;
9
- get(customId: string): PaginationBuilder;
8
+ register(paginatorType: PaginatorTypeEnum, factory: (builder: PaginationBuilder<PaginatorTypeEnum>) => PaginationBuilder<PaginatorTypeEnum>): PaginationBuilder<PaginatorTypeEnum>;
9
+ get<T extends PaginatorTypeEnum>(customId: string): PaginationBuilder<T> | undefined;
10
10
  delete(customId: string): boolean;
11
11
  }
@@ -14,20 +14,30 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.NestCordPaginationService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
- const helpers_1 = require("./helpers");
18
17
  const nestcord_pagination_module_definition_1 = require("./nestcord-pagination.module-definition");
19
18
  const enums_1 = require("./enums");
20
- const discord_js_1 = require("discord.js");
19
+ const buttons_padgination_builder_1 = require("./builders/buttons-padgination.builder");
20
+ const select_menu_pagination_builder_1 = require("./builders/select-menu-pagination.builder");
21
21
  let NestCordPaginationService = class NestCordPaginationService {
22
22
  constructor(options) {
23
23
  this.options = options;
24
24
  this.cache = new Map();
25
- this.options = options;
26
25
  }
27
- register(factory) {
28
- const builder = factory(new helpers_1.PaginationBuilder(this.options));
29
- this.cache.set(builder.customId, builder);
30
- return builder;
26
+ register(paginatorType, factory) {
27
+ switch (paginatorType) {
28
+ case enums_1.PaginatorTypeEnum.BUTTONS: {
29
+ const builder = factory(new buttons_padgination_builder_1.ButtonsPaginationBuilder(this.options));
30
+ this.cache.set(builder.customId, builder);
31
+ return builder;
32
+ }
33
+ case enums_1.PaginatorTypeEnum.SELECT_MENU: {
34
+ const builder = factory(new select_menu_pagination_builder_1.SelectMenuPaginationBuilder(this.options));
35
+ this.cache.set(builder.customId, builder);
36
+ return builder;
37
+ }
38
+ default:
39
+ throw new Error(`Unsupported paginator type: ${this.options.type}`);
40
+ }
31
41
  }
32
42
  get(customId) {
33
43
  return this.cache.get(customId);
@@ -37,37 +47,6 @@ let NestCordPaginationService = class NestCordPaginationService {
37
47
  }
38
48
  };
39
49
  exports.NestCordPaginationService = NestCordPaginationService;
40
- NestCordPaginationService.DEFAULT_OPTIONS = {
41
- allowTraversal: false,
42
- allowSkip: false,
43
- buttons: {
44
- [enums_1.PaginationAction.First]: {
45
- label: 'First',
46
- emoji: '⏮️',
47
- style: discord_js_1.ButtonStyle.Primary,
48
- },
49
- [enums_1.PaginationAction.Back]: {
50
- label: 'Previous',
51
- emoji: '⏪',
52
- style: discord_js_1.ButtonStyle.Primary,
53
- },
54
- [enums_1.PaginationAction.Next]: {
55
- label: 'Next',
56
- emoji: '⏩',
57
- style: discord_js_1.ButtonStyle.Primary,
58
- },
59
- [enums_1.PaginationAction.Last]: {
60
- label: 'Last',
61
- emoji: '⏭️',
62
- style: discord_js_1.ButtonStyle.Primary,
63
- },
64
- [enums_1.PaginationAction.Traverse]: {
65
- label: 'Traverse',
66
- emoji: '🔢',
67
- style: discord_js_1.ButtonStyle.Primary,
68
- },
69
- },
70
- };
71
50
  exports.NestCordPaginationService = NestCordPaginationService = __decorate([
72
51
  (0, common_1.Injectable)(),
73
52
  __param(0, (0, common_1.Inject)(nestcord_pagination_module_definition_1.MODULE_OPTIONS_TOKEN)),
@@ -0,0 +1,4 @@
1
+ import { ButtonsPaginationBuilder } from '../builders/buttons-padgination.builder';
2
+ import { SelectMenuPaginationBuilder } from '../builders/select-menu-pagination.builder';
3
+ import { PaginatorTypeEnum } from '../enums';
4
+ export type PaginationBuilder<T extends PaginatorTypeEnum> = T extends PaginatorTypeEnum.BUTTONS ? ButtonsPaginationBuilder : T extends PaginatorTypeEnum.SELECT_MENU ? SelectMenuPaginationBuilder : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,46 +2,41 @@ import { Method, RawAxiosRequestHeaders } from 'axios';
2
2
  import { StatCronExpression } from '../enums';
3
3
  export interface ServiceOption {
4
4
  /**
5
- * Stat service name
6
- * @returns string
5
+ * The name of the stat service.
7
6
  */
8
7
  name: string;
9
8
  /**
10
- * Stat service api url to send the body data
11
- * @returns string;
9
+ * The API URL of the stat service where the body data will be sent.
12
10
  */
13
11
  url: string;
14
12
  /**
15
- * Stat service request method
16
- * @returns RequestMethod
13
+ * The HTTP request method to use for the stat service.
17
14
  */
18
15
  method?: Method;
19
16
  /**
20
- * Stat service body data
21
- * @returns Record<string, unknown>
17
+ * The body data to send to the stat service.
22
18
  */
23
19
  bodyData: Record<string, unknown>;
24
20
  /**
25
- * Stat service header data
26
- * @returns Record<string, unknown>
21
+ * The header data to include in the request to the stat service.
27
22
  */
28
23
  headerData?: RawAxiosRequestHeaders;
29
24
  /**
30
- * Crontab expression
31
- * @returns StatCronExpression
32
- * @returns string
25
+ * The crontab expression that defines the schedule for the stat service.
33
26
  */
34
27
  schedule?: StatCronExpression | string;
35
28
  }
36
29
  export interface NestCordStatReporterOptions {
30
+ /**
31
+ * The list of stat service options.
32
+ */
37
33
  services: ServiceOption[];
38
34
  /**
39
- * If true skip all jobs
35
+ * If true, skip all jobs.
40
36
  */
41
37
  development?: boolean;
42
38
  /**
43
- * Show log
44
- * @returns boolean
39
+ * If true, enable logging.
45
40
  */
46
41
  log?: boolean;
47
42
  }
@@ -48,8 +48,10 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
48
48
  });
49
49
  }
50
50
  isFirstShard() {
51
- var _a, _b;
52
- return ((_b = (_a = this.shard) === null || _a === void 0 ? void 0 : _a.ids) === null || _b === void 0 ? void 0 : _b[0]) === 0 || !this.shard;
51
+ if (!this.shard || !Array.isArray(this.shard.ids)) {
52
+ return false;
53
+ }
54
+ return this.shard.ids[0] === 0;
53
55
  }
54
56
  isProduction() {
55
57
  return !this.options.development;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@globalart/nestcord",
3
3
  "description": "A module for creating Discord bots using NestJS, based on Discord.js",
4
- "version": "1.5.7",
4
+ "version": "1.5.8",
5
5
  "private": false,
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc -p tsconfig.build.json",
@@ -1,2 +0,0 @@
1
- export * from './pagination-builder.helper';
2
- export * from './page-builder.helper';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pagination-builder.helper"), exports);
18
- __exportStar(require("./page-builder.helper"), exports);