Skip to content

Commit 8a73bf5

Browse files
committed
chore: cleanup
1 parent b4980b0 commit 8a73bf5

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

src/events/ready.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { Events } from "discord.js";
22
import { CronJob } from "cron";
33

44
import client from "../index";
5-
import {
6-
fetchLatestUploads,
7-
sendLatestUploads,
8-
} from "../utils/youtube/fetchLatestUploads";
95
import { config } from "../config";
106
// import { checkIfStreamersAreLive } from "../utils/twitch/checkIfStreamerIsLive";
117
import { cronUpdateBotInfo } from "../utils/cronJobs";
8+
import sendLatestUploads from "../utils/youtube/sendLatestUploads";
9+
import fetchLatestUploads from "../utils/youtube/fetchLatestUploads";
1210

1311
// Log into the bot
1412
client.once(Events.ClientReady, async (bot) => {

src/utils/youtube/fetchLatestUploads.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import type { dbDiscordTable, dbYouTube } from "../../types/database";
22

3-
import { ChannelType, type TextChannel } from "discord.js";
4-
53
import { env } from "../../config";
64
import { getGuildsTrackingChannel, updateVideoId } from "../database";
75
import { dbYouTubeGetAllChannelsToTrack } from "../db/youtube";
8-
import client from "../..";
96

107
import getChannelDetails from "./getChannelDetails";
118

12-
const updates = new Map<
9+
export const updates = new Map<
1310
string,
1411
{
1512
channelInfo: Awaited<ReturnType<typeof getChannelDetails>>;
1613
discordGuildsToUpdate: dbDiscordTable[];
1714
}
1815
>();
1916

20-
export async function fetchLatestUploads() {
17+
export default async function fetchLatestUploads() {
2118
console.log("Fetching latest uploads...");
2219

2320
const channels: dbYouTube[] | [] = await dbYouTubeGetAllChannelsToTrack();
@@ -152,46 +149,3 @@ export async function fetchLatestUploads() {
152149
}
153150
}
154151
}
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-
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ChannelType, TextChannel } from "discord.js";
2+
3+
import client from "../..";
4+
5+
import { updates } from "./fetchLatestUploads";
6+
7+
export default async function sendLatestUploads() {
8+
for (const [videoId, update] of updates.entries()) {
9+
const channelInfo = update.channelInfo;
10+
const discordGuildsToUpdate = update.discordGuildsToUpdate;
11+
12+
console.log("Discord guilds to update:", discordGuildsToUpdate);
13+
for (const guild of discordGuildsToUpdate) {
14+
try {
15+
const channelObj = await client.channels.fetch(
16+
guild.guild_channel_id,
17+
);
18+
19+
if (
20+
!channelObj ||
21+
(channelObj.type !== ChannelType.GuildText &&
22+
channelObj.type !== ChannelType.GuildAnnouncement)
23+
) {
24+
console.error(
25+
"Invalid channel or not a text channel in fetchLatestUploads",
26+
);
27+
continue;
28+
}
29+
30+
await (channelObj as TextChannel).send({
31+
content:
32+
guild.guild_ping_role && channelInfo
33+
? `<@&${guild.guild_ping_role}> New video uploaded for ${channelInfo?.channelName}! https://www.youtube.com/watch?v=${videoId}`
34+
: guild.guild_ping_role
35+
? `<@&${guild.guild_ping_role}> New video uploaded! https://www.youtube.com/watch?v=${videoId}`
36+
: channelInfo
37+
? `New video uploaded for ${channelInfo.channelName}! https://www.youtube.com/watch?v=${videoId}`
38+
: `New video uploaded! https://www.youtube.com/watch?v=${videoId}`,
39+
});
40+
} catch (error) {
41+
console.error(
42+
"Error fetching or sending message to channel in fetchLatestUploads:",
43+
error,
44+
);
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)