|
1 |
| -import type { dbYouTube } from "../../types/database"; |
2 |
| - |
3 |
| -import { ChannelType, TextChannel } from "discord.js"; |
| 1 | +import type { dbDiscordTable, dbYouTube } from "../../types/database"; |
4 | 2 |
|
5 | 3 | import { env } from "../../config";
|
6 | 4 | import { getGuildsTrackingChannel, updateVideoId } from "../database";
|
7 |
| -import client from "../.."; |
8 | 5 | import { dbYouTubeGetAllChannelsToTrack } from "../db/youtube";
|
9 | 6 |
|
10 | 7 | import getChannelDetails from "./getChannelDetails";
|
11 | 8 |
|
| 9 | +export const updates = new Map< |
| 10 | + string, |
| 11 | + { |
| 12 | + channelInfo: Awaited<ReturnType<typeof getChannelDetails>>; |
| 13 | + discordGuildsToUpdate: dbDiscordTable[]; |
| 14 | + } |
| 15 | +>(); |
| 16 | + |
12 | 17 | export default async function fetchLatestUploads() {
|
13 | 18 | console.log("Fetching latest uploads...");
|
14 | 19 |
|
@@ -99,42 +104,47 @@ export default async function fetchLatestUploads() {
|
99 | 104 |
|
100 | 105 | const channelInfo = await getChannelDetails(channelId);
|
101 | 106 |
|
102 |
| - console.log("Discord guilds to update:", discordGuildsToUpdate); |
103 |
| - for (const guild of discordGuildsToUpdate) { |
104 |
| - try { |
105 |
| - const channelObj = await client.channels.fetch( |
106 |
| - guild.guild_channel_id, |
107 |
| - ); |
108 |
| - |
109 |
| - if ( |
110 |
| - !channelObj || |
111 |
| - (channelObj.type !== ChannelType.GuildText && |
112 |
| - channelObj.type !== |
113 |
| - ChannelType.GuildAnnouncement) |
114 |
| - ) { |
115 |
| - console.error( |
116 |
| - "Invalid channel or not a text channel in fetchLatestUploads", |
117 |
| - ); |
118 |
| - continue; |
119 |
| - } |
120 |
| - |
121 |
| - await (channelObj as TextChannel).send({ |
122 |
| - content: |
123 |
| - guild.guild_ping_role && channelInfo |
124 |
| - ? `<@&${guild.guild_ping_role}> New video uploaded for ${channelInfo?.channelName}! https://www.youtube.com/watch?v=${videoId}` |
125 |
| - : guild.guild_ping_role |
126 |
| - ? `<@&${guild.guild_ping_role}> New video uploaded! https://www.youtube.com/watch?v=${videoId}` |
127 |
| - : channelInfo |
128 |
| - ? `New video uploaded for ${channelInfo.channelName}! https://www.youtube.com/watch?v=${videoId}` |
129 |
| - : `New video uploaded! https://www.youtube.com/watch?v=${videoId}`, |
130 |
| - }); |
131 |
| - } catch (error) { |
132 |
| - console.error( |
133 |
| - "Error fetching or sending message to channel in fetchLatestUploads:", |
134 |
| - error, |
135 |
| - ); |
136 |
| - } |
137 |
| - } |
| 107 | + updates.set(videoId, { |
| 108 | + channelInfo, |
| 109 | + discordGuildsToUpdate, |
| 110 | + }); |
| 111 | + |
| 112 | + // console.log("Discord guilds to update:", discordGuildsToUpdate); |
| 113 | + // for (const guild of discordGuildsToUpdate) { |
| 114 | + // try { |
| 115 | + // const channelObj = await client.channels.fetch( |
| 116 | + // guild.guild_channel_id, |
| 117 | + // ); |
| 118 | + |
| 119 | + // if ( |
| 120 | + // !channelObj || |
| 121 | + // (channelObj.type !== ChannelType.GuildText && |
| 122 | + // channelObj.type !== |
| 123 | + // ChannelType.GuildAnnouncement) |
| 124 | + // ) { |
| 125 | + // console.error( |
| 126 | + // "Invalid channel or not a text channel in fetchLatestUploads", |
| 127 | + // ); |
| 128 | + // continue; |
| 129 | + // } |
| 130 | + |
| 131 | + // await (channelObj as TextChannel).send({ |
| 132 | + // content: |
| 133 | + // guild.guild_ping_role && channelInfo |
| 134 | + // ? `<@&${guild.guild_ping_role}> New video uploaded for ${channelInfo?.channelName}! https://www.youtube.com/watch?v=${videoId}` |
| 135 | + // : guild.guild_ping_role |
| 136 | + // ? `<@&${guild.guild_ping_role}> New video uploaded! https://www.youtube.com/watch?v=${videoId}` |
| 137 | + // : channelInfo |
| 138 | + // ? `New video uploaded for ${channelInfo.channelName}! https://www.youtube.com/watch?v=${videoId}` |
| 139 | + // : `New video uploaded! https://www.youtube.com/watch?v=${videoId}`, |
| 140 | + // }); |
| 141 | + // } catch (error) { |
| 142 | + // console.error( |
| 143 | + // "Error fetching or sending message to channel in fetchLatestUploads:", |
| 144 | + // error, |
| 145 | + // ); |
| 146 | + // } |
| 147 | + // } |
138 | 148 | }
|
139 | 149 | }
|
140 | 150 | }
|
|
0 commit comments