Skip to content

Commit

Permalink
Merge branch '135-implement-community-centric-version-for-discord-bot…
Browse files Browse the repository at this point in the history
…' of https://github.com/RnDAO/tc-discordBot into 135-implement-community-centric-version-for-discord-bot
  • Loading branch information
Behzad-rabiei committed Dec 5, 2023
2 parents 5d7e202 + 13a4af7 commit 30be1a3
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 177 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ src/config/*.env
/dist
/lib
/node_modules
/lib

#migration
migrate.json
Expand Down
6 changes: 3 additions & 3 deletions src/functions/fetchMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function getNeedDataFromMessage(message: Message, threadInfo?: threadInfo)
channelName: threadInfo?.channelName ? threadInfo?.channelName : '',
threadId: threadInfo?.threadId ? threadInfo?.threadId : null,
threadName: threadInfo?.threadName ? threadInfo?.threadName : null,
isGeneratedByWebhook: message.webhookId ? true : false
isGeneratedByWebhook: message.webhookId ? true : false,
};
} else {
return {
Expand All @@ -83,7 +83,7 @@ async function getNeedDataFromMessage(message: Message, threadInfo?: threadInfo)
channelName: message.channel instanceof TextChannel ? message.channel.name : null,
threadId: null,
threadName: null,
isGeneratedByWebhook: message.webhookId ? true : false
isGeneratedByWebhook: message.webhookId ? true : false,
};
}
}
Expand Down Expand Up @@ -169,10 +169,10 @@ async function fetchMessages(
channelName: channel.parent?.name,
})
: await pushMessagesToArray(connection, messagesToStore, [...fetchedMessages.values()]);
await rawInfoService.createRawInfos(connection, messagesToStore);
options[fetchDirection] = boundaryMessage.id;
fetchedMessages = await channel.messages.fetch(options);
}
await rawInfoService.createRawInfos(connection, messagesToStore);
} catch (err) {
logger.error(
{ guild_id: connection.name, channel_id: channel.id, fetchDirection, err },
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,19 @@ async function app() {
host: config.redis.host,
port: config.redis.port,
password: config.redis.password,
},
}
});
queue.add('cronJob', {}, {
repeat: {
cron: '0 0 * * *', // Run once 00:00 UTC
// cron: '* * * * *', // Run every minute
// every: 10000
},
jobId: 'cronJob', // Optional: Provide a unique ID for the job
attempts: 1, // Number of times to retry the job if it fails
attempts: 0, // Number of times to retry the job if it fails
backoff: {
type: 'exponential',
delay: 1000, // Initial delay between retries in milliseconds
},

} as never);

// Create a worker to process the job
Expand All @@ -220,6 +219,7 @@ async function app() {
port: config.redis.port,
password: config.redis.password,
},
lockDuration: 79200000, // 22 hours
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ import config from '../../config';
import webhookLogic from '../utils/webhookLogic';
import { DatabaseManager } from '@togethercrew.dev/db';

const {
Guilds,
GuildMembers,
GuildMessages,
GuildPresences,
DirectMessages
} = GatewayIntentBits;

const { Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages } = GatewayIntentBits;

export const up = async () => {
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages],
});
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages],
});

await client.login(config.discord.botToken);
await connectDB();
Expand All @@ -30,7 +23,5 @@ export const up = async () => {
};

export const down = async () => {
// TODO: Implement rollback logic if needed
// TODO: Implement rollback logic if needed
};


5 changes: 2 additions & 3 deletions src/migrations/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export const up = async () => {
};

export const down = async () => {
await connectDB()

};
await connectDB();
};
Loading

0 comments on commit 30be1a3

Please sign in to comment.