|
1 | 1 | import type { dbDiscordTable, dbYouTube } from "../../types/database"; |
2 | 2 |
|
3 | | -import { ChannelType, type TextChannel } from "discord.js"; |
4 | | - |
5 | 3 | import { env } from "../../config"; |
6 | 4 | import { getGuildsTrackingChannel, updateVideoId } from "../database"; |
7 | 5 | import { dbYouTubeGetAllChannelsToTrack } from "../db/youtube"; |
8 | | -import client from "../.."; |
9 | 6 |
|
10 | 7 | import getChannelDetails from "./getChannelDetails"; |
11 | 8 |
|
12 | | -const updates = new Map< |
| 9 | +export const updates = new Map< |
13 | 10 | string, |
14 | 11 | { |
15 | 12 | channelInfo: Awaited<ReturnType<typeof getChannelDetails>>; |
16 | 13 | discordGuildsToUpdate: dbDiscordTable[]; |
17 | 14 | } |
18 | 15 | >(); |
19 | 16 |
|
20 | | -export async function fetchLatestUploads() { |
| 17 | +export default async function fetchLatestUploads() { |
21 | 18 | console.log("Fetching latest uploads..."); |
22 | 19 |
|
23 | 20 | const channels: dbYouTube[] | [] = await dbYouTubeGetAllChannelsToTrack(); |
@@ -152,46 +149,3 @@ export async function fetchLatestUploads() { |
152 | 149 | } |
153 | 150 | } |
154 | 151 | } |
155 | | - |
156 | | -export async function sendLatestUploads() { |
157 | | - for (const [videoId, update] of updates.entries()) { |
158 | | - const channelInfo = update.channelInfo; |
159 | | - const discordGuildsToUpdate = update.discordGuildsToUpdate; |
160 | | - |
161 | | - console.log("Discord guilds to update:", discordGuildsToUpdate); |
162 | | - for (const guild of discordGuildsToUpdate) { |
163 | | - try { |
164 | | - const channelObj = await client.channels.fetch( |
165 | | - guild.guild_channel_id, |
166 | | - ); |
167 | | - |
168 | | - if ( |
169 | | - !channelObj || |
170 | | - (channelObj.type !== ChannelType.GuildText && |
171 | | - channelObj.type !== ChannelType.GuildAnnouncement) |
172 | | - ) { |
173 | | - console.error( |
174 | | - "Invalid channel or not a text channel in fetchLatestUploads", |
175 | | - ); |
176 | | - continue; |
177 | | - } |
178 | | - |
179 | | - await (channelObj as TextChannel).send({ |
180 | | - content: |
181 | | - guild.guild_ping_role && channelInfo |
182 | | - ? `<@&${guild.guild_ping_role}> New video uploaded for ${channelInfo?.channelName}! https://www.youtube.com/watch?v=${videoId}` |
183 | | - : guild.guild_ping_role |
184 | | - ? `<@&${guild.guild_ping_role}> New video uploaded! https://www.youtube.com/watch?v=${videoId}` |
185 | | - : channelInfo |
186 | | - ? `New video uploaded for ${channelInfo.channelName}! https://www.youtube.com/watch?v=${videoId}` |
187 | | - : `New video uploaded! https://www.youtube.com/watch?v=${videoId}`, |
188 | | - }); |
189 | | - } catch (error) { |
190 | | - console.error( |
191 | | - "Error fetching or sending message to channel in fetchLatestUploads:", |
192 | | - error, |
193 | | - ); |
194 | | - } |
195 | | - } |
196 | | - } |
197 | | -} |
0 commit comments