Skip to content

Commit

Permalink
Bump @discord-nestjs/* packages (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Dec 22, 2023
1 parent 88021b6 commit 2371878
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 160 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"dependencies": {
"@dev-thought/nestjs-github-webhooks": "^1.0.0",
"@discord-nestjs/common": "^4.0.7",
"@discord-nestjs/core": "^4.3.0",
"@discord-nestjs/common": "^5.2.10",
"@discord-nestjs/core": "^5.3.12",
"@nestjs/common": "^8.4.4",
"@nestjs/config": "^2.0.0",
"@nestjs/core": "^8.4.4",
Expand Down
18 changes: 4 additions & 14 deletions services/bots/src/discord/commands/common/info.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { InteractionEvent } from '@discord-nestjs/core';
import { getVersionInfo } from '@lib/common';
import { BlankDto } from '../../discord.const';
import { ChatInputCommandInteraction } from 'discord.js';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';

const version = getVersionInfo(__dirname);
Expand All @@ -15,13 +9,9 @@ const version = getVersionInfo(__dirname);
name: 'info',
description: 'Returns bot information',
})
@UsePipes(TransformPipe)
export class CommandCommonInfo implements DiscordTransformedCommand<any> {
export class CommandCommonInfo {
@CommandHandler()
async handler(
@Payload() handlerDto: BlankDto,
{ interaction }: TransformedCommandExecutionContext,
): Promise<void> {
async handler(@InteractionEvent() interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.reply({
embeds: [
{
Expand Down
24 changes: 11 additions & 13 deletions services/bots/src/discord/commands/common/message.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TransformPipe } from '@discord-nestjs/common';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { InteractionEvent, Param } from '@discord-nestjs/core';
import {
DiscordTransformedCommand,
Param,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { AutocompleteInteraction, EmbedBuilder, Events, InteractionType } from 'discord.js';
AutocompleteInteraction,
ChatInputCommandInteraction,
EmbedBuilder,
Events,
InteractionType,
} from 'discord.js';
import { OptionalUserMentionDto } from '../../discord.const';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';
import { ServiceCommonMessageData } from '../../services/common/message-data';
Expand All @@ -25,17 +25,15 @@ class MessageDto extends OptionalUserMentionDto {
name: 'message',
description: 'Returns a predefined message',
})
@UsePipes(TransformPipe)
export class CommandCommonMessage implements DiscordTransformedCommand<MessageDto> {
export class CommandCommonMessage {
constructor(private serviceCommonMessageData: ServiceCommonMessageData) {}

@CommandHandler()
async handler(
@Payload() handlerDto: MessageDto,
context: TransformedCommandExecutionContext,
@InteractionEvent(SlashCommandPipe) handlerDto: MessageDto,
@InteractionEvent() interaction: ChatInputCommandInteraction,
): Promise<void> {
const { messageKey, userMention } = handlerDto;
const { interaction } = context;
if (messageKey === 'reload') {
await this.serviceCommonMessageData.ensureData(interaction.guildId, true);

Expand Down
18 changes: 4 additions & 14 deletions services/bots/src/discord/commands/common/ping.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { BlankDto } from '../../discord.const';
import { InteractionEvent } from '@discord-nestjs/core';
import { ChatInputCommandInteraction } from 'discord.js';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';

@DiscordCommandClass({
name: 'ping',
description: 'Returns pong',
})
@UsePipes(TransformPipe)
export class CommandCommonPing implements DiscordTransformedCommand<any> {
export class CommandCommonPing {
@CommandHandler()
async handler(
@Payload() handlerDto: BlankDto,
{ interaction }: TransformedCommandExecutionContext,
): Promise<void> {
async handler(@InteractionEvent() interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.reply('pong');
}
}
18 changes: 4 additions & 14 deletions services/bots/src/discord/commands/common/pinned.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { InteractionEvent } from '@discord-nestjs/core';
import { ChatInputCommandInteraction } from 'discord.js';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';
import { BlankDto } from '../../discord.const';

@DiscordCommandClass({
name: 'pinned',
description: 'Returns pinned messages',
})
@UsePipes(TransformPipe)
export class CommandCommonPinned implements DiscordTransformedCommand<any> {
export class CommandCommonPinned {
@CommandHandler()
async handler(
@Payload() handlerDto: BlankDto,
{ interaction }: TransformedCommandExecutionContext,
): Promise<void> {
async handler(@InteractionEvent() interaction: ChatInputCommandInteraction): Promise<void> {
const pinned = await interaction.channel.messages.fetchPinned();

if (pinned.size === 0) {
Expand Down
17 changes: 6 additions & 11 deletions services/bots/src/discord/commands/common/topic.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { InteractionEvent } from '@discord-nestjs/core';
import { ChatInputCommandInteraction } from 'discord.js';
import { OptionalUserMentionDto } from '../../discord.const';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';

@DiscordCommandClass({
name: 'topic',
description: 'Returns the topic of the current channel',
})
@UsePipes(TransformPipe)
export class CommandCommonTopic implements DiscordTransformedCommand<any> {
export class CommandCommonTopic {
@CommandHandler()
async handler(
@Payload() handlerDto: OptionalUserMentionDto,
{ interaction }: TransformedCommandExecutionContext,
@InteractionEvent(SlashCommandPipe) handlerDto: OptionalUserMentionDto,
@InteractionEvent() interaction: ChatInputCommandInteraction,
): Promise<void> {
// @ts-ignore not all channel types have topic
const topic = interaction.channel.topic;
Expand Down
24 changes: 11 additions & 13 deletions services/bots/src/discord/commands/esphome/component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TransformPipe } from '@discord-nestjs/common';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { InteractionEvent, Param } from '@discord-nestjs/core';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
Param,
UsePipes,
} from '@discord-nestjs/core';
AutocompleteInteraction,
ChatInputCommandInteraction,
EmbedBuilder,
Events,
InteractionType,
} from 'discord.js';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';
import { AutocompleteInteraction, EmbedBuilder, Events, InteractionType } from 'discord.js';
import {
ServiceEsphomeComponentData,
sourceWithFallback,
Expand All @@ -27,17 +27,15 @@ class ComponentsDto {
name: 'component',
description: 'Returns information about an component',
})
@UsePipes(TransformPipe)
export class CommandEsphomeComponent implements DiscordTransformedCommand<ComponentsDto> {
export class CommandEsphomeComponent {
constructor(private serviceEsphomeComponentData: ServiceEsphomeComponentData) {}

@CommandHandler()
async handler(
@Payload() handlerDto: ComponentsDto,
context: TransformedCommandExecutionContext,
@InteractionEvent(SlashCommandPipe) handlerDto: ComponentsDto,
@InteractionEvent() interaction: ChatInputCommandInteraction,
): Promise<void> {
const { component } = handlerDto;
const { interaction } = context;
const channel = interaction.channel.id;

if (component === 'reload') {
Expand Down
26 changes: 12 additions & 14 deletions services/bots/src/discord/commands/home-assistant/integration.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TransformPipe } from '@discord-nestjs/common';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { InteractionEvent, Param } from '@discord-nestjs/core';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
Param,
UsePipes,
} from '@discord-nestjs/core';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';
import { AutocompleteInteraction, EmbedBuilder, Events, InteractionType } from 'discord.js';
AutocompleteInteraction,
ChatInputCommandInteraction,
EmbedBuilder,
Events,
InteractionType,
} from 'discord.js';
import { Emoji } from '../../discord.const';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';
import { ServiceHomeassistantIntegrationData } from '../../services/home-assistant/integration-data';

const BETA_CHANNEL_ID = '427516175237382144';
Expand All @@ -35,17 +35,15 @@ class IntegrationDto {
name: 'integration',
description: 'Returns information about an integration',
})
@UsePipes(TransformPipe)
export class CommandHomeassistantIntegration implements DiscordTransformedCommand<IntegrationDto> {
export class CommandHomeassistantIntegration {
constructor(private serviceHomeassistantIntegrationData: ServiceHomeassistantIntegrationData) {}

@CommandHandler()
async handler(
@Payload() handlerDto: IntegrationDto,
context: TransformedCommandExecutionContext,
@InteractionEvent(SlashCommandPipe) handlerDto: IntegrationDto,
@InteractionEvent() interaction: ChatInputCommandInteraction,
): Promise<void> {
const { domain } = handlerDto;
const { interaction } = context;
const channel = interaction.channelId === BETA_CHANNEL_ID ? 'beta' : 'stable';

if (domain === 'reload') {
Expand Down
22 changes: 7 additions & 15 deletions services/bots/src/discord/commands/home-assistant/my.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
DiscordTransformedCommand,
On,
Param,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { SlashCommandPipe } from '@discord-nestjs/common';
import { InteractionEvent, Param } from '@discord-nestjs/core';
import {
ActionRowBuilder,
AutocompleteInteraction,
ChatInputCommandInteraction,
EmbedBuilder,
Events,
ModalActionRowComponentBuilder,
Expand All @@ -18,12 +12,12 @@ import {
TextInputBuilder,
TextInputStyle,
} from 'discord.js';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';
import {
IntegrationData,
ServiceHomeassistantIntegrationData,
} from '../../services/home-assistant/integration-data';
import { ServiceHomeassistantMyRedirectData } from '../../services/home-assistant/my-redirect-data';
import { CommandHandler, DiscordCommandClass, OnDiscordEvent } from '../../discord.decorator';

class MyDto {
@Param({
Expand All @@ -39,20 +33,18 @@ class MyDto {
name: 'my',
description: 'Returns a my link',
})
@UsePipes(TransformPipe)
export class CommandHomeAssistantMy implements DiscordTransformedCommand<MyDto> {
export class CommandHomeAssistantMy {
constructor(
private serviceHomeassistantIntegrationData: ServiceHomeassistantIntegrationData,
private serviceHomeassistantMyRedirectData: ServiceHomeassistantMyRedirectData,
) {}

@CommandHandler()
async handler(
@Payload() handlerDto: MyDto,
context: TransformedCommandExecutionContext,
@InteractionEvent(SlashCommandPipe) handlerDto: MyDto,
@InteractionEvent() interaction: ChatInputCommandInteraction,
): Promise<void> {
const { redirect } = handlerDto;
const { interaction } = context;
if (redirect === 'reload') {
await this.serviceHomeassistantMyRedirectData.ensureData(true);

Expand Down
19 changes: 4 additions & 15 deletions services/bots/src/discord/commands/home-assistant/versions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { EmbedBuilder } from 'discord.js';
import { InteractionEvent } from '@discord-nestjs/core';
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';
import {
DiscordTransformedCommand,
Payload,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { TransformPipe } from '@discord-nestjs/common';
import { BlankDto } from '../../discord.const';

@DiscordCommandClass({
name: 'versions',
description: 'Returns version information',
})
@UsePipes(TransformPipe)
export class CommandHomeAssistantVersions implements DiscordTransformedCommand<any> {
export class CommandHomeAssistantVersions {
@CommandHandler()
async handler(
@Payload() handlerDto: BlankDto,
{ interaction }: TransformedCommandExecutionContext,
): Promise<void> {
async handler(@InteractionEvent() interaction: ChatInputCommandInteraction): Promise<void> {
const [betaResponse, stableResponse] = await Promise.all([
fetch('https://version.home-assistant.io/beta.json'),
fetch('https://version.home-assistant.io/stable.json'),
Expand Down
2 changes: 0 additions & 2 deletions services/bots/src/discord/discord.const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Transform } from 'class-transformer';
import { Param, ParamType } from '@discord-nestjs/core';

export class BlankDto {}

export class OptionalUserMentionDto {
@Transform(({ value }) => (value ? `<@${value}>` : undefined))
@Param({
Expand Down
Loading

0 comments on commit 2371878

Please sign in to comment.