Skip to content

Commit

Permalink
[FEATURE]: integrate the events with queues
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Jan 25, 2024
1 parent 3793bf3 commit b82c256
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 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 @@ -29,7 +29,7 @@
"homepage": "https://github.com/Behzad-rabiei/tc-discordBot#readme",
"dependencies": {
"@sentry/node": "^7.51.2",
"@togethercrew.dev/db": "^3.0.24",
"@togethercrew.dev/db": "^3.0.28",
"@togethercrew.dev/tc-messagebroker": "^0.0.44",
"babel-jest": "^29.5.0",
"bullmq": "^3.14.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setupRabbitMQHandlers } from './rabbitmq/RabbitMQHandler';
import { commandService, eventService } from './services';
import './queue/workers/cronWorker';
import './queue/workers/channelMessageWorker';
import './queue/workers/directMessageWorker';

async function app() {
await connectToMongoDB();
Expand Down
3 changes: 2 additions & 1 deletion src/rabbitmq/events/sendMessageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createPrivateThreadAndSendMessage } from '../../functions/thread';
import parentLogger from '../../config/logger';
import { platformService } from '../../database/services';
import sendDirectMessage from '../../functions/sendDirectMessage';
import { addDirectMessage } from '../../queue/queues/directMessage';

const logger = parentLogger.child({ module: `${Event.DISCORD_BOT.SEND_MESSAGE}` });

Expand All @@ -29,7 +30,7 @@ const notifyUserAboutAnalysisFinish = async (
const upperTextChannel = rawPositionBasedSortedTextChannels[0];

try {
sendDirectMessage({ discordId, message });
addDirectMessage(discordId, message)
} catch (error) {
// can not send DM to the user
// Will create a private thread and notify him/her about the status if useFallback is true
Expand Down
4 changes: 3 additions & 1 deletion src/rabbitmq/events/sendMessageToChannel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Event, MBConnection } from '@togethercrew.dev/tc-messagebroker';
import parentLogger from '../../config/logger';
import { channelService } from '../../services';
import { addChannelMessage } from '../../queue/queues/channelMessage'
const logger = parentLogger.child({ module: `${Event.DISCORD_BOT.SEND_MESSAGE}` });

export async function handleSendMessageToChannel(msg: any) {
Expand All @@ -13,9 +14,10 @@ export async function handleSendMessageToChannel(msg: any) {
const channels = saga.data['channels'];
const message = saga.data['message'];

// IS THIS CORRECT WAY?
await saga.next(async () => {
for await (const channel of channels) {
await channelService.sendChannelMessage(channel, message)
addChannelMessage(channel, message)
}
});

Expand Down

0 comments on commit b82c256

Please sign in to comment.