Skip to content

Commit

Permalink
Merge pull request #153 from TogetherCrew/145-announcement-feautre
Browse files Browse the repository at this point in the history
145 announcement feautre
  • Loading branch information
Behzad-rabiei authored Jan 17, 2024
2 parents 86e7890 + 33061d6 commit b5c0301
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/rabbitmq/RabbitMQHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions src/rabbitmq/events/sendMessageToChannel.ts
Original file line number Diff line number Diff line change
@@ -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');

}
}

0 comments on commit b5c0301

Please sign in to comment.