Skip to content

Commit f4fdf2e

Browse files
committed
welcome back pg
1 parent 59bd0a7 commit f4fdf2e

File tree

7 files changed

+114
-54
lines changed

7 files changed

+114
-54
lines changed

.env.example

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,3 @@ CONFIG_DISCORD_LOGS_CHANNEL='YOUR_DISCORD_LOGS_CHANNEL'
2020

2121
# Backups
2222
BACKUP_ENABLED=true
23-
BACKUP_USING_SSH=false # It will still backup locally if set to true
24-
25-
# Note: The following sections are only required if BACKUP_USING_SSH is set to true
26-
BACKUP_SSH_HOST='YOUR_SSH_HOST'
27-
BACKUP_SSH_PORT='22' # Default SSH port is 22
28-
BACKUP_SSH_USER='YOUR_SSH_USER'
29-
BACKUP_SSH_PASSWORD='YOUR_SSH_PASSWORD' # You must use a password as private keys are not supported yet
30-
BACKUP_SSH_PATH='YOUR_SSH_PATH' # The path where the backups will be stored

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
* text=auto eol=lf
2-
*.lockb binary diff=lockb

bun.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"version": "1.3.0",
66
"devDependencies": {
77
"@types/bun": "1.1.14",
8+
"@types/pg": "^8.11.14",
89
"@typescript-eslint/eslint-plugin": "8.11.0",
910
"@typescript-eslint/parser": "8.11.0",
1011
"eslint": "^8.57.0",
@@ -25,6 +26,7 @@
2526
},
2627
"dependencies": {
2728
"cron": "^3.2.1",
28-
"discord.js": "^14.16.3"
29+
"discord.js": "^14.16.3",
30+
"pg": "^8.15.6"
2931
}
3032
}

src/commands.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import Bun from "bun";
22
import { heapStats } from "bun:jsc";
33
import {
4-
ApplicationIntegrationType,
4+
ApplicationCommandType,
5+
AutocompleteInteraction,
56
ChannelType,
7+
ChatInputCommandInteraction,
68
GuildMember,
7-
InteractionContextType,
89
MessageFlags,
10+
type ApplicationCommandOptionData,
11+
type CacheType,
912
type CommandInteraction,
1013
} from "discord.js";
1114
import { PermissionFlagsBits } from "discord-api-types/v8";
@@ -32,13 +35,17 @@ import client from ".";
3235

3336
interface Command {
3437
data: {
35-
options: any[];
3638
name: string;
3739
description: string;
38-
integration_types: ApplicationIntegrationType[];
39-
contexts: InteractionContextType[];
40+
options?: ApplicationCommandOptionData[];
41+
integration_types?: number[];
42+
contexts?: number[];
43+
type?: ApplicationCommandType;
4044
};
41-
execute: (interaction: CommandInteraction) => Promise<void>;
45+
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
46+
autoComplete?: (
47+
interaction: AutocompleteInteraction<CacheType>,
48+
) => Promise<any>;
4249
}
4350

4451
const commands: Record<string, Command> = {
@@ -175,11 +182,12 @@ const commands: Record<string, Command> = {
175182
"Enter the YouTube channel ID or Twitch Streamer to track",
176183
type: 3,
177184
required: true,
185+
autocomplete: true,
178186
},
179187
{
180188
name: "updates_channel",
181189
description:
182-
"Enter the Guild channel to recieve updates in.",
190+
"Enter the Guild channel to receive updates in.",
183191
type: 7,
184192
required: false,
185193
},
@@ -207,6 +215,9 @@ const commands: Record<string, Command> = {
207215
interaction.channelId;
208216
const guildId = interaction.guildId;
209217

218+
// Log the autocomplete value
219+
console.log(`Autocomplete value: ${platformUserId}`);
220+
210221
// Checks if the platform is valid ig
211222
if (targetPlatform != "youtube" && targetPlatform != "twitch") {
212223
await interaction.reply({
@@ -386,7 +397,7 @@ const commands: Record<string, Command> = {
386397
}
387398

388399
return;
389-
case "twitch":
400+
case "twitch": {
390401
// Check if the streamer exists by getting the ID
391402
const streamerId = await getStreamerId(platformUserId);
392403

@@ -461,11 +472,24 @@ const commands: Record<string, Command> = {
461472
}
462473

463474
return;
475+
}
464476
default:
465477
console.error("This should never happen");
466478
break;
467479
}
468480
},
481+
autoComplete: async (interaction: AutocompleteInteraction) => {
482+
try {
483+
const platform = interaction.options.get("platform")?.value;
484+
const query = interaction.options.get("user_id")?.value;
485+
486+
if (!query) {
487+
return;
488+
}
489+
} catch (error) {
490+
console.error(error);
491+
}
492+
},
469493
},
470494
untrack: {
471495
data: {
@@ -582,7 +606,7 @@ const commands: Record<string, Command> = {
582606
}
583607

584608
return;
585-
case "twitch":
609+
case "twitch": {
586610
// get the twitch id for the streamer
587611
const streamerId = await getStreamerId(youtubeChannelId);
588612

@@ -632,6 +656,7 @@ const commands: Record<string, Command> = {
632656
}
633657

634658
return;
659+
}
635660
default:
636661
return;
637662
}

src/types/innertube.d.ts

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// NOTE: Experimental
2-
// You think i was typing this all out manually? lol no :p
3-
41
export type InnertubeSearchRequest = {
52
contents: {
63
twoColumnSearchResultsRenderer: {
@@ -9,35 +6,7 @@ export type InnertubeSearchRequest = {
96
contents: Array<{
107
itemSectionRenderer?: {
118
contents: Array<{
12-
didYouMeanRenderer?: {
13-
didYouMean: {
14-
runs: Array<{
15-
text: string;
16-
}>;
17-
};
18-
correctedQuery: {
19-
runs: Array<{
20-
text: string;
21-
italics: boolean;
22-
}>;
23-
};
24-
correctedQueryEndpoint: {
25-
clickTrackingParams: string;
26-
commandMetadata: {
27-
webCommandMetadata: {
28-
url: string;
29-
webPageType: string;
30-
rootVe: number;
31-
};
32-
};
33-
searchEndpoint: {
34-
query: string;
35-
params: string;
36-
};
37-
};
38-
trackingParams: string;
39-
};
40-
channelRenderer?: {
9+
channelRenderer: {
4110
channelId: string;
4211
title: {
4312
simpleText: string;
@@ -91,18 +60,39 @@ export type InnertubeSearchRequest = {
9160
}>;
9261
};
9362
videoCountText: {
94-
accessibility: {
63+
accessibility?: {
9564
accessibilityData: {
9665
label: string;
9766
};
9867
};
99-
simpleText: string;
68+
simpleText?: string;
69+
runs?: Array<{
70+
text: string;
71+
}>;
10072
};
10173
subscriptionButton: {
10274
subscribed: boolean;
10375
};
76+
ownerBadges?: Array<{
77+
metadataBadgeRenderer: {
78+
icon: {
79+
iconType: string;
80+
};
81+
style: string;
82+
tooltip: string;
83+
trackingParams: string;
84+
accessibilityData: {
85+
label: string;
86+
};
87+
};
88+
}>;
10489
subscriberCountText: {
10590
simpleText: string;
91+
accessibility?: {
92+
accessibilityData: {
93+
label: string;
94+
};
95+
};
10696
};
10797
subscribeButton: {
10898
buttonRenderer: {

src/utils/youtube/search.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export default async function (query: string) {
2323
method: "POST",
2424
},
2525
);
26-
const data = (await response.json()) as Promise<InnertubeSearchRequest>;
26+
27+
const data = (
28+
await ((await response.json()) as Promise<InnertubeSearchRequest>)
29+
).contents.twoColumnSearchResultsRenderer.primaryContents
30+
.sectionListRenderer.contents;
2731

2832
console.dir(data, { depth: null });
2933
} catch (err) {

0 commit comments

Comments
 (0)