From 6d3770f9aaacbb4d6def2e702b231d21bcb61079 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:13:44 +0330 Subject: [PATCH 1/2] [NPM]: update the message broker lib --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index c5db9de0..3c9c5704 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@sentry/node": "^7.51.2", "@togethercrew.dev/db": "^3.0.24", - "@togethercrew.dev/tc-messagebroker": "^0.0.43", + "@togethercrew.dev/tc-messagebroker": "^0.0.44", "babel-jest": "^29.5.0", "bullmq": "^3.14.0", "discord.js": "^14.12.1", @@ -3052,9 +3052,9 @@ } }, "node_modules/@togethercrew.dev/tc-messagebroker": { - "version": "0.0.43", - "resolved": "https://registry.npmjs.org/@togethercrew.dev/tc-messagebroker/-/tc-messagebroker-0.0.43.tgz", - "integrity": "sha512-XajYiL1Dv8FEcHLy+x3HrKxDUHG2eKAx52zfoxCbixJ3u9gY6OQfgTmeiDtfbJmaaGL/QRIMGn49Fq9umDf9Kw==", + "version": "0.0.44", + "resolved": "https://registry.npmjs.org/@togethercrew.dev/tc-messagebroker/-/tc-messagebroker-0.0.44.tgz", + "integrity": "sha512-iOeZlAJ3r1/9HlHpFSwTWVOOL5jYCM/8QekG2SjrJulWmAmlrxI27ZLh/KeEV+5cJNtYGBErIRLuwTcZa/im2g==", "dependencies": { "@types/amqplib": "^0.10.1", "@types/uuid": "^9.0.1", @@ -9203,9 +9203,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/msgpackr": { - "version": "1.9.9", - "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.9.9.tgz", - "integrity": "sha512-sbn6mioS2w0lq1O6PpGtsv6Gy8roWM+o3o4Sqjd6DudrL/nOugY+KyJUimoWzHnf9OkO0T6broHFnYE/R05t9A==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.10.1.tgz", + "integrity": "sha512-r5VRLv9qouXuLiIBrLpl2d5ZvPt8svdQTl5/vMvE4nzDMyEX4sgW5yWhuBBj5UmgwOTWj8CIdSXn5sAfsHAWIQ==", "optionalDependencies": { "msgpackr-extract": "^3.0.2" } diff --git a/package.json b/package.json index 79121362..1d79836f 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "dependencies": { "@sentry/node": "^7.51.2", "@togethercrew.dev/db": "^3.0.24", - "@togethercrew.dev/tc-messagebroker": "^0.0.43", + "@togethercrew.dev/tc-messagebroker": "^0.0.44", "babel-jest": "^29.5.0", "bullmq": "^3.14.0", "discord.js": "^14.12.1", From 33061d60024772592833b01c103494c994ba69ca Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:18:15 +0330 Subject: [PATCH 2/2] [FEATURE]: add announcement events --- src/rabbitmq/RabbitMQHandler.ts | 2 ++ src/rabbitmq/events/sendMessageToChannel.ts | 26 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/rabbitmq/events/sendMessageToChannel.ts diff --git a/src/rabbitmq/RabbitMQHandler.ts b/src/rabbitmq/RabbitMQHandler.ts index f13f18d1..f75c76cc 100644 --- a/src/rabbitmq/RabbitMQHandler.ts +++ b/src/rabbitmq/RabbitMQHandler.ts @@ -6,10 +6,12 @@ import { handleInteractionResponseCreate } from './events/interactionResponseCre import { handleInteractionResponseEdit } from './events/interactionResponseEdit'; import { handleInteractionResponseDelete } from './events/interactionResponseDelete'; import { handleFollowUpMessageCreate } from './events/FollowUpMessageCreate'; +import { handleSendMessageToChannel } from './events/sendMessageToChannel'; export function setupRabbitMQHandlers() { RabbitMQ.onEvent(Event.DISCORD_BOT.FETCH, handleFetchEvent); RabbitMQ.onEvent(Event.DISCORD_BOT.SEND_MESSAGE, handleSendMessageEvent); + RabbitMQ.onEvent(Event.DISCORD_BOT.SEND_MESSAGE_TO_CHANNEL, handleSendMessageToChannel); RabbitMQ.onEvent(Event.DISCORD_BOT.FETCH_MEMBERS, handleFetchMembersEvent); RabbitMQ.onEvent(Event.DISCORD_BOT.INTERACTION_RESPONSE.CREATE, handleInteractionResponseCreate); RabbitMQ.onEvent(Event.DISCORD_BOT.INTERACTION_RESPONSE.EDIT, handleInteractionResponseEdit); diff --git a/src/rabbitmq/events/sendMessageToChannel.ts b/src/rabbitmq/events/sendMessageToChannel.ts new file mode 100644 index 00000000..e76ce21e --- /dev/null +++ b/src/rabbitmq/events/sendMessageToChannel.ts @@ -0,0 +1,26 @@ +import { Event, MBConnection } from '@togethercrew.dev/tc-messagebroker'; +import parentLogger from '../../config/logger'; +import { channelService } from '../../services'; +const logger = parentLogger.child({ module: `${Event.DISCORD_BOT.SEND_MESSAGE}` }); + +export async function handleSendMessageToChannel(msg: any) { + try { + logger.info({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE_TO_CHANNEL }, 'is running'); + if (!msg) return; + + const { content } = msg; + const saga = await MBConnection.models.Saga.findOne({ sagaId: content.uuid }); + + const channels = saga.data['channels']; + const message = saga.data['message']; + + for (let i = 0; i < channels.length; i++) { + await channelService.sendChannelMessage(channels[i], message) + } + + logger.info({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE_TO_CHANNEL }, 'is done'); + } catch (error) { + logger.error({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE_TO_CHANNEL, error }, 'is failed'); + + } +} \ No newline at end of file