Skip to content

Commit 5488a96

Browse files
committed
mini changes to db
1 parent 94aeea3 commit 5488a96

6 files changed

Lines changed: 77 additions & 3 deletions

File tree

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
"lint:fix": "eslint . --ext .ts -c .eslintrc.json --fix",
2828
"cargo:api:dev": "cd api && cargo watch -x \"run -- --dev\"",
2929
"web:dev": "concurrently --names \"WEB,API\" --prefix-colors \"blue,green\" \"cd web && bun dev\" \"cd api && cargo watch -x \\\"run -- --dev\\\"\"",
30-
"web:build": "cd web && bun build"
30+
"web:build": "cd web && bun build",
31+
"start:api": "echo 'Cannot start API without cargo. Reserved for future use' && exit 1",
32+
"start:bot": "bun run src/bot.ts",
33+
"start:web": "cd web && bun start"
3134
},
3235
"dependencies": {
3336
"cron": "^4.3.0",

perftesting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ export default async function test(
4343

4444
test("UC1234567890", PlaylistType.Video);
4545

46+
// Crash the program
47+
process.exit(1);

src/commands.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,23 @@ const commands: Record<string, Command> = {
232232
return;
233233
}
234234

235-
// DMs are currently not supported, so throw back an error
235+
// TODO: Embed
236+
// For YouTube: Check if the channel ID is in a valid format
237+
if (
238+
targetPlatform === "youtube" &&
239+
(platformUserId.length !== 24 ||
240+
!platformUserId.startsWith("UC"))
241+
) {
242+
await interaction.reply({
243+
flags: MessageFlags.Ephemeral,
244+
content:
245+
'Invalid YouTube channel ID format! Each channel ID should be 24 characters long and start with "UC". Need to find the channel ID? We have a guide here: https://github.com/GalvinPython/feedr/wiki/Guide:-How-to-get-the-YouTube-Channel-ID. If this was an issue with the autocomplete, please report it!',
246+
});
247+
248+
return;
249+
}
250+
251+
// TODO: Enable DMs :)
236252
if (!guildId || interaction.channel?.isDMBased()) {
237253
await interaction.reply({
238254
flags: MessageFlags.Ephemeral,
@@ -243,6 +259,7 @@ const commands: Record<string, Command> = {
243259
return;
244260
}
245261

262+
// TODO: Embed
246263
// Check the permissions of the user
247264
if (
248265
!interaction.memberPermissions?.has(
@@ -258,6 +275,7 @@ const commands: Record<string, Command> = {
258275
return;
259276
}
260277

278+
// TODO: Embed
261279
// Check if the bot has the required permissions for the target channel
262280
const targetChannel = await client.channels.fetch(discordChannelId);
263281

src/types/types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Generalised types to be used throughout the bot if its not suitable in the other files
2+
3+
export enum Platform {
4+
YouTube = "youtube",
5+
Twitch = "twitch",
6+
}

src/utils/db/discord.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Platform } from "../../types/types";
2+
import { pool } from "../database";
3+
4+
export async function checkIfGuildIsTrackingUserAlready(
5+
platform: Platform,
6+
userId: string,
7+
guildId: string,
8+
): Promise<boolean> {
9+
console.log(
10+
`Checking if guild ${guildId} is tracking user ${userId} on platform ${platform}`,
11+
);
12+
13+
let query: string | null = null;
14+
15+
if (platform === Platform.YouTube) {
16+
query = `
17+
SELECT * FROM guild_youtube_subscriptions
18+
WHERE youtube_channel_id = ? AND guild_id = ?
19+
`;
20+
} else if (platform === Platform.Twitch) {
21+
query = `
22+
SELECT * FROM guild_twitch_subscriptions
23+
WHERE twitch_user_id = ? AND guild_id = ?
24+
`;
25+
}
26+
27+
if (!query) {
28+
console.error("Invalid platform provided for tracking check.");
29+
30+
return false;
31+
}
32+
33+
try {
34+
const client = await pool.connect();
35+
const result = await client.query(query, [userId, guildId]);
36+
37+
client.release();
38+
39+
return result.rows.length > 0;
40+
} catch (error) {
41+
console.error("Error checking if guild is tracking user:", error);
42+
43+
return false;
44+
}
45+
}

src/utils/quickEmbed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enum EmbedType {
1+
export enum EmbedType {
22
Success = "success",
33
Error = "error",
44
Warning = "warning",

0 commit comments

Comments
 (0)