Skip to content

Commit

Permalink
[FEATURE]: add javascript usage for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Sep 20, 2023
1 parent 967d7a5 commit 3354739
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/migrations/utils/webhookLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ async function fetchMessagesBetweenOldestAndNewest(
) {
try {
let allMessages: Message[] = [];
logger.info(
{ guild_id: connection.name, channel_id: channel.id },
'Fetching channel messages is running'
);
const options: FetchOptions = { limit: 100 };
options.after = oldestRawInfo.messageId;
let fetchedMessages = await channel.messages.fetch(options);
Expand All @@ -38,10 +42,16 @@ async function fetchMessagesBetweenOldestAndNewest(
'Fetching channel messages failed'
);
}
logger.info(
{ guild_id: connection.name, channel_id: channel.id },
'Fetching channel messages is done'
);
}

async function migrateIsGeneratedByWebhook(connection: Connection, channel: TextChannel) {
try {
logger.info({ guild_id: connection.name, channel_id: channel.id }, 'Migration for isGeneratedByWebhook is running');

// Fetch oldest rawInfo from DB
const oldestChannelRawInfo = await rawInfoService.getOldestRawInfo(connection, {
channelId: channel?.id,
Expand Down Expand Up @@ -149,6 +159,8 @@ async function migrateIsGeneratedByWebhook(connection: Connection, channel: Text
}
}

logger.info({ guild_id: connection.name, channel_id: channel.id }, 'Migration for isGeneratedByWebhook is done');

} catch (err) {
logger.error({ guild_id: connection.name, channel_id: channel.id, err }, 'Migration for isGeneratedByWebhook failed');
}
Expand All @@ -162,6 +174,7 @@ async function migrateIsGeneratedByWebhook(connection: Connection, channel: Text
* @param {Snowflake} guildId - The identifier of the guild to extract information from.
*/
async function runRawInfoMigration(connection: Connection, client: Client, guildId: Snowflake) {
logger.info({ guild_id: guildId }, 'Migration is running');
try {
const guild = await client.guilds.fetch(guildId);
const channels = await channelService.getChannels(connection, {});
Expand All @@ -175,6 +188,7 @@ async function runRawInfoMigration(connection: Connection, client: Client, guild
} catch (err) {
logger.error({ guild_id: guildId, err }, 'Migration is failed');
}
logger.info({ guild_id: guildId }, 'Migration is done');
}

export default runRawInfoMigration;

0 comments on commit 3354739

Please sign in to comment.