5.2.12 โ€ข Published 3 months ago

@discord-nestjs/common v5.2.12

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Common module

๐Ÿงพ Description

This package contains some ready-made templates

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Installation

$ npm install @discord-nestjs/common

Or via yarn

$ yarn add @discord-nestjs/common

๐Ÿ“‘ Overview

โ„น๏ธ Pipes template

SlashCommandPipe fills in the fields DTO from CommandInteraction.

For prefix command use PrefixCommandPipe.

๐Ÿ’ก Example

/* registration-email.dto.ts */

import {City} from '../definitions/city';
import {Param, ParamType, Choice} from '@discord-nestjs/core';

export class RegistrationEmailDto {
  @Param({
    name: 'email',
    description: 'Base user email',
    required: true,
  })
  email: string;

  @Param({description: 'User nickname', required: true})
  name: string;

  @Param({description: 'User age', required: true, type: ParamType.INTEGER})
  age: number;

  @Choice(City)
  @Param({description: 'City of residence', type: ParamType.INTEGER})
  city: City;
}
/* play.command.ts */

import { RegistrationDto } from './registration.dto';
import { Command, IA } from '@discord-nestjs/core';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { CommandInteraction } from 'discord.js';

@Command({
  name: 'reg',
  description: 'User registration',
})
export class BaseInfoCommand
{
  handler(@IA(SlashCommandPipe) dto: RegistrationEmailDto): string {
    // dto instance must have the following fields: email, name, age, city
  }
}

ValidationPipe validate the resulting DTO based on class-validator. If the DTO is invalid then an exception will be thrown, which can be caught by the filter from the package @discord-nestjs/core.

Also, suitable for prefix commands.

for validation, you need to install package class-validator

๐Ÿ’ก Example

/* registration-email.dto.ts */

import {Param, ParamType} from '@discord-nestjs/core';
import {IsEmail, Length, Max, Min} from 'class-validator';

export class RegistrationEmailDto {
  @IsEmail()
  @Param({
    name: 'email',
    description: 'Base user email',
    required: true,
  })
  email: string;

  @Param({description: 'User nickname', required: true})
  @Length(3, 100)
  name: string;

  @Param({description: 'User age', required: true, type: ParamType.INTEGER})
  @Max(150)
  @Min(18)
  age: number;
}
/* play.command.ts */

import {RegistrationDto} from './registration.dto';
import {Command, IA} from '@discord-nestjs/core';
import {SlashCommandPipe, ValidationPipe, UsePipes} from '@discord-nestjs/common';
import {CommandInteraction} from 'discord.js';

@Command({
  name: 'reg',
  description: 'User registration',
})
@UsePipes(SlashCommandPipe, ValidationPipe)
export class BaseInfoCommand {
  handler(@IA() dto: RegistrationEmailDto): string {
    // dto instance must be valid
  }
}

โ„น๏ธ Mapped types

Intersection type allows you to infer a new type

๐Ÿ’ก Example

import { Param } from '@discord-nestjs/core';

class FullName {
  @Param({
    description: 'Your full name'
  })
  name: string;
}
import { Param } from '@discord-nestjs/core';

class ResidencePlace {
  @Param({
    description: 'City of residence'
  })
  city: string;

  @Param({
    description: 'The street where your house is located'
  })
  street: string;
}
import { DiscordIntersectionType } from '@discord-nestjs/common';

// Must have properties name, city and street
class Profile extends DiscordIntersectionType(FullName, ResidencePlace) {
}
5.2.12

3 months ago

5.2.11

3 months ago

5.2.10

6 months ago

5.2.9

8 months ago

5.2.8

9 months ago

5.2.7

9 months ago

5.2.6

11 months ago

5.2.5

1 year ago

5.2.4

1 year ago

5.2.3

1 year ago

5.2.2

1 year ago

5.2.1

1 year ago

5.2.0

1 year ago

5.1.7

1 year ago

5.1.6

1 year ago

5.1.5

1 year ago

5.1.4

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.0

1 year ago

4.0.7

2 years ago

4.0.8

2 years ago

3.4.0

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.6

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.3.5

2 years ago

3.3.4

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.2.2

2 years ago

2.0.15

2 years ago

2.1.1

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.12

2 years ago

2.1.0

2 years ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.11

2 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.5

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

0.0.2-beta.872

3 years ago

0.0.2-beta.873

3 years ago

0.0.2-beta.871

3 years ago

0.0.2-beta.870

3 years ago

0.0.2-beta.869

3 years ago

0.0.2-beta.868

3 years ago