Skip to content

Commit

Permalink
[FEATURE]: add announcement events
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Jan 17, 2024
1 parent 6d3770f commit 33061d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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 33061d6

Please sign in to comment.