Skip to content

Commit

Permalink
[CI]: working on the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Jan 28, 2024
1 parent 67341fd commit c9aba11
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"dist",
"__tests__/",
"jest.config.js",
"*.yml"
"*.yml",
"mongo-init.js",
"bable.config.js",
]
}
2 changes: 2 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ services:
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=pass
volumes:
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js
healthcheck:
test: echo 'db.stats().ok' | mongosh localhost:27017/test --quiet
interval: 60s
Expand Down
12 changes: 12 additions & 0 deletions mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
db.createUser({
user: 'root',
pwd: 'pass',
roles: [
{
role: 'readWrite',
db: 'RnDAO',
},
],
});

db.createCollection("myCollection"); // This will create the RnDAO database
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:ci": "jest --ci --detectOpenHandles",
"lint": "eslint **/*.ts",
"lint-fix": "eslint --fix **/*.ts",
"format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
"format": "prettier --write \"src/**/*.ts\" \"types/*.ts\" \"__tests__/**/*.ts\"",
"migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\"",
"migrate:up": "migrate --migrations-dir=\"./lib/migrations/db\" up",
"migrate:down": "migrate --migrations-dir=\"./lib/migrations/db\" down"
Expand Down
26 changes: 14 additions & 12 deletions src/rabbitmq/events/sendMessageEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Channel, ChannelType, Snowflake, TextChannel } from 'discord.js';
/* eslint-disable @typescript-eslint/consistent-type-assertions */
import { type Channel, ChannelType, type Snowflake, type TextChannel } from 'discord.js';
import { Event, MBConnection } from '@togethercrew.dev/tc-messagebroker';
import { coreService } from '../../services';
import { createPrivateThreadAndSendMessage } from '../../functions/thread';
Expand All @@ -11,7 +12,7 @@ const logger = parentLogger.child({ module: `${Event.DISCORD_BOT.SEND_MESSAGE}`
const notifyUserAboutAnalysisFinish = async (
discordId: string,
info: { guildId: Snowflake; message: string; useFallback: boolean },
) => {
): Promise<void> => {
const client = await coreService.DiscordBotManager.getClient();

// related issue https://github.com/RnDAO/tc-discordBot/issues/68
Expand All @@ -21,7 +22,7 @@ const notifyUserAboutAnalysisFinish = async (
const channels = await guild.channels.fetch();

const arrayChannels = Array.from(channels, ([name, value]) => ({ ...value } as Channel));
const textChannels = arrayChannels.filter((channel) => channel.type == ChannelType.GuildText) as TextChannel[];
const textChannels = arrayChannels.filter((channel) => channel.type === ChannelType.GuildText) as TextChannel[];
const rawPositionBasedSortedTextChannels = textChannels.sort((textChannelA, textChannelB) =>
textChannelA.rawPosition > textChannelB.rawPosition ? 1 : -1,
);
Expand All @@ -33,27 +34,28 @@ const notifyUserAboutAnalysisFinish = async (
// can not send DM to the user
// Will create a private thread and notify him/her about the status if useFallback is true
if (useFallback)
createPrivateThreadAndSendMessage(upperTextChannel, {
await createPrivateThreadAndSendMessage(upperTextChannel, {
threadName: 'TogetherCrew Status',
message: `<@${discordId}> ${message}`,
});
}
};

export async function handleSendMessageEvent(msg: any) {
export async function handleSendMessageEvent(msg: any): Promise<void> {
try {
logger.info({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE, sagaId: msg.content.uuid }, 'is running');
if (!msg) return;
if (msg === undefined || msg === null) return;

const { content } = msg;
const saga = await MBConnection.models.Saga.findOne({ sagaId: content.uuid });
const platformId = saga.data['platformId'];
const platformId = saga.data.platformId;
const platform = await platformService.getPlatform({ _id: platformId });
const discordId = saga.data['discordId'];
const message = saga.data['message'];
const useFallback = saga.data['useFallback'];
if (platform) {
await saga.next(() =>
const discordId = saga.data.discordId;
const message = saga.data.message;
const useFallback = saga.data.useFallback;
if (platform !== null) {
await saga.next(async () =>
// eslint-disable-next-line @typescript-eslint/return-await
notifyUserAboutAnalysisFinish(discordId, { guildId: platform.metadata?.id, message, useFallback }),
);
}
Expand Down
10 changes: 5 additions & 5 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { type Collection } from 'discord.js';

declare module 'discord.js' {
interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<string, any>;
}
}
interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<string, any>;
}
}

0 comments on commit c9aba11

Please sign in to comment.