Skip to content

Commit d9b1ead

Browse files
committed
fix(bot,database): add ephemeral flag + update constraint for dm tracking
1 parent 0d2e8ee commit d9b1ead

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/commands.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ActionRowBuilder,
55
ApplicationCommandOptionType,
66
ApplicationCommandType,
7+
ApplicationIntegrationType,
78
AutocompleteInteraction,
89
ButtonBuilder,
910
ButtonStyle,
@@ -12,6 +13,7 @@ import {
1213
ComponentType,
1314
EmbedBuilder,
1415
GuildMember,
16+
InteractionContextType,
1517
MessageFlags,
1618
type ApplicationCommandOptionData,
1719
type CacheType,
@@ -54,8 +56,8 @@ interface Command {
5456
name: string;
5557
description: string;
5658
options?: ApplicationCommandOptionData[];
57-
integration_types?: number[];
58-
contexts?: number[];
59+
integration_types?: ApplicationIntegrationType[];
60+
contexts?: InteractionContextType[];
5961
type?: ApplicationCommandType;
6062
};
6163
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
@@ -64,6 +66,8 @@ interface Command {
6466
) => Promise<any>;
6567
}
6668

69+
// Context 2: Interaction can be used within Group DMs and DMs other than the app's bot user
70+
// /track, /tracked and /untracked can't be used in these contexts
6771
const commands: Record<string, Command> = {
6872
ping: {
6973
data: {
@@ -76,7 +80,7 @@ const commands: Record<string, Command> = {
7680
execute: async (interaction: CommandInteraction) => {
7781
await interaction
7882
.reply({
79-
ephemeral: false,
83+
flags: MessageFlags.Ephemeral,
8084
content: `Ping: ${interaction.client.ws.ping}ms`,
8185
})
8286
.catch(console.error);
@@ -134,7 +138,7 @@ const commands: Record<string, Command> = {
134138
execute: async (interaction: CommandInteraction) => {
135139
await interaction
136140
.reply({
137-
ephemeral: false,
141+
flags: MessageFlags.Ephemeral,
138142
content: `Uptime: ${(
139143
performance.now() /
140144
(86400 * 1000)
@@ -149,7 +153,7 @@ const commands: Record<string, Command> = {
149153
name: "hmm",
150154
description: "What does this command do?",
151155
integration_types: [0, 1],
152-
contexts: [0, 1],
156+
contexts: [0, 1, 2],
153157
},
154158
execute: async (interaction: CommandInteraction) => {
155159
await interaction.reply({
@@ -173,7 +177,7 @@ const commands: Record<string, Command> = {
173177
Bun.gc(false);
174178
await interaction
175179
.reply({
176-
ephemeral: false,
180+
flags: MessageFlags.Ephemeral,
177181
content: [
178182
`Heap size: ${(heap.heapSize / 1024 / 1024).toFixed(2)} MB / ${(
179183
heap.heapCapacity /
@@ -266,7 +270,7 @@ const commands: Record<string, Command> = {
266270
description:
267271
"Track a channel to get notified when they upload a video!",
268272
integration_types: [0, 1],
269-
contexts: [0, 1, 2],
273+
contexts: [0, 1],
270274
},
271275
execute: async (interaction: CommandInteraction) => {
272276
// Get the YouTube Channel ID

src/db/discord.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
dbTwitchTable,
1212
} from "./schema";
1313

14+
// Check if the guild is tracking the user already
1415
export async function checkIfGuildIsTrackingUserAlready(
1516
platform: Platform,
1617
userId: string,
@@ -334,6 +335,7 @@ export async function discordRemoveGuildTrackingChannel(
334335
// Add a new guild to track
335336
export async function discordAddNewGuild(
336337
guildId: string,
338+
isDm?: boolean,
337339
): Promise<{ success: boolean; data: [] }> {
338340
console.log(`Adding new guild to track: ${guildId}`);
339341

@@ -343,6 +345,7 @@ export async function discordAddNewGuild(
343345
allowedPublicSharing: false,
344346
isInServer: true,
345347
memberCount: 0,
348+
isDm: isDm ?? false,
346349
});
347350

348351
return { success: true, data: [] };

src/db/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const dbDiscordTable = pgTable("discord", {
1717
${table.allowedPublicSharing} = false AND
1818
${table.feedrUpdatesChannelId} = ${table.guildId} AND
1919
${table.isInServer} = true AND
20-
${table.memberCount} = 1
20+
${table.memberCount} = 0
2121
)`
2222
)
2323
]);

0 commit comments

Comments
 (0)