Skip to content

Commit

Permalink
feat: ignore user data on fetch message and extraction phases
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Dec 31, 2024
1 parent 185c54b commit b627be0
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bot/src/config/guildIgnoredUsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Snowflake } from 'discord.js';
import { Snowflake } from 'discord.js'

type GuildIgnoredUsers = Record<string, Snowflake[]>

Expand Down
8 changes: 4 additions & 4 deletions bot/src/functions/cronJon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PlatformNames } from '@togethercrew.dev/db';
import { PlatformNames } from '@togethercrew.dev/db'

import parentLogger from '../config/logger';
import { platformService } from '../database/services';
import { addGuildExtraction } from '../queue/queues/guildExtraction';
import parentLogger from '../config/logger'
import { platformService } from '../database/services'
import { addGuildExtraction } from '../queue/queues/guildExtraction'

const logger = parentLogger.child({ event: 'CronJob' })

Expand Down
14 changes: 7 additions & 7 deletions bot/src/functions/fetchMembers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Guild, Snowflake } from 'discord.js';
import { Connection, HydratedDocument } from 'mongoose';
import { Guild, Snowflake } from 'discord.js'
import { Connection, HydratedDocument } from 'mongoose'

import { IGuildMember, IPlatform } from '@togethercrew.dev/db';
import { IGuildMember, IPlatform } from '@togethercrew.dev/db'

import parentLogger from '../config/logger';
import { guildMemberService, platformService } from '../database/services';
import { coreService } from '../services';
import { removeIgnoredGuildMembers } from '../utils/guildIgnoredUsers';
import parentLogger from '../config/logger'
import { guildMemberService, platformService } from '../database/services'
import { coreService } from '../services'
import { removeIgnoredGuildMembers } from '../utils/guildIgnoredUsers'

const logger = parentLogger.child({ module: 'FetchMembers' })

Expand Down
18 changes: 9 additions & 9 deletions bot/src/functions/fetchMessages.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable no-unneeded-ternary */
import { Message, Role, Snowflake, TextChannel, ThreadChannel, User } from 'discord.js';
import { Connection, HydratedDocument } from 'mongoose';
import { Message, Role, Snowflake, TextChannel, ThreadChannel, User } from 'discord.js'
import { Connection, HydratedDocument } from 'mongoose'
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import fetch from 'node-fetch';
import fetch from 'node-fetch'

import { IDiscordUser, IPlatform, IRawInfo } from '@togethercrew.dev/db';
import { IDiscordUser, IPlatform, IRawInfo } from '@togethercrew.dev/db'

import config from '../config';
import parentLogger from '../config/logger';
import { platformService, rawInfoService } from '../database/services';
import { channelService, guildService } from '../services';
import { sanitizeRawInfoForIgnoredUsers } from '../utils/guildIgnoredUsers';
import config from '../config'
import parentLogger from '../config/logger'
import { platformService, rawInfoService } from '../database/services'
import { channelService, guildService } from '../services'
import { sanitizeRawInfoForIgnoredUsers } from '../utils/guildIgnoredUsers'

const logger = parentLogger.child({ module: 'FetchMessages' })
interface threadInfo {
Expand Down
22 changes: 12 additions & 10 deletions bot/src/migrations/db/deleteSpecificUserData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dotenv/config';
import 'dotenv/config'

import mongoose from 'mongoose';
import mongoose from 'mongoose'

import { DatabaseManager, Platform } from '@togethercrew.dev/db';
import { DatabaseManager, Platform, PlatformNames } from '@togethercrew.dev/db'

import config from '../../config';
import parentLogger from '../../config/logger';
import config from '../../config'
import parentLogger from '../../config/logger'

const logger = parentLogger.child({ event: 'deleteSpecificUserData' })

Expand All @@ -20,17 +20,19 @@ const connectToMongoDB = async () => {

export const up = async () => {
try {
// const PLATFORM_ID = '675aea1f2b104f11ad1f5417'
// const GUILD_ID = '675aea1f2b104f11ad1f5417'
// const SPECIFIC_DISCORD_ID = '641449673818898472'

const PLATFORM_ID = '67728c686be658065fae38c2'
const GUILD_ID = '980858613587382322'
const SPECIFIC_DISCORD_ID = '681946187490000900'
await connectToMongoDB()

const platform = await Platform.findById(PLATFORM_ID)
const platform = await Platform.findOne({
name: PlatformNames.Discord,
'metadata.id': GUILD_ID,
})
logger.info(`platform info:${platform}`)

const guildConnection = await DatabaseManager.getInstance().getGuildDb(platform?.metadata?.id)
const guildConnection = await DatabaseManager.getInstance().getGuildDb(GUILD_ID)

const deleteGuildMemberResult = await guildConnection.models.GuildMember.deleteOne({
discordId: SPECIFIC_DISCORD_ID,
Expand Down
10 changes: 5 additions & 5 deletions bot/src/queue/handlers/guildMemberAddHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Snowflake } from 'discord.js';
import { Snowflake } from 'discord.js'

import { DatabaseManager, IGuildMember } from '@togethercrew.dev/db';
import { DatabaseManager, IGuildMember } from '@togethercrew.dev/db'

import parentLogger from '../../config/logger';
import { guildMemberService } from '../../database/services';
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers';
import parentLogger from '../../config/logger'
import { guildMemberService } from '../../database/services'
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers'

const logger = parentLogger.child({ event: 'GuildMemberAddHandler' })

Expand Down
10 changes: 5 additions & 5 deletions bot/src/queue/handlers/guildMemberRemoveHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Snowflake } from 'discord.js';
import { Snowflake } from 'discord.js'

import { DatabaseManager } from '@togethercrew.dev/db';
import { DatabaseManager } from '@togethercrew.dev/db'

import parentLogger from '../../config/logger';
import { guildMemberService } from '../../database/services';
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers';
import parentLogger from '../../config/logger'
import { guildMemberService } from '../../database/services'
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers'

const logger = parentLogger.child({ event: 'GuildMemberRemoveHandler' })

Expand Down
10 changes: 5 additions & 5 deletions bot/src/queue/handlers/guildMemberUpdateHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Snowflake } from 'discord.js';
import { Snowflake } from 'discord.js'

import { DatabaseManager, IGuildMember } from '@togethercrew.dev/db';
import { DatabaseManager, IGuildMember } from '@togethercrew.dev/db'

import parentLogger from '../../config/logger';
import { guildMemberService } from '../../database/services';
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers';
import parentLogger from '../../config/logger'
import { guildMemberService } from '../../database/services'
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers'

const logger = parentLogger.child({ event: 'GuildMemberUpdateHandler' })

Expand Down
8 changes: 4 additions & 4 deletions bot/src/queue/handlers/userUpdateHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DatabaseManager } from '@togethercrew.dev/db';
import { DatabaseManager } from '@togethercrew.dev/db'

import parentLogger from '../../config/logger';
import { guildMemberService, platformService } from '../../database/services';
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers';
import parentLogger from '../../config/logger'
import { guildMemberService, platformService } from '../../database/services'
import { isUserIgnoredForGuild } from '../../utils/guildIgnoredUsers'

interface IdataToStore {
username: string
Expand Down
8 changes: 4 additions & 4 deletions bot/src/queue/workers/guildExtractionWorker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Job, Worker } from 'bullmq';
import { Job, Worker } from 'bullmq'

import { redisConfig } from '../../config/queue';
import guildExtraction from '../../functions/guildExtraction';
import { WorkerFactory } from './index';
import { redisConfig } from '../../config/queue'
import guildExtraction from '../../functions/guildExtraction'
import { WorkerFactory } from './index'

export const guildExtractionWorker = new Worker(
'guildExtractionQueue',
Expand Down
8 changes: 4 additions & 4 deletions bot/src/utils/guildIgnoredUsers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// services/ignoreUsers.service.ts
import { Snowflake } from 'discord.js';
import { Snowflake } from 'discord.js'

import { DatabaseManager, Platform } from '@togethercrew.dev/db';
import { DatabaseManager, Platform } from '@togethercrew.dev/db'

import { Guild_IGNORED_USERS } from '../config/guildIgnoredUsers';
import parentLogger from '../config/logger';
import { Guild_IGNORED_USERS } from '../config/guildIgnoredUsers'
import parentLogger from '../config/logger'

const logger = parentLogger.child({ event: 'guildIgnoreUsers' })

Expand Down

0 comments on commit b627be0

Please sign in to comment.