Skip to content

Commit 87dd93a

Browse files
committed
feat: add post to bluesky feed command
1 parent 7a44c08 commit 87dd93a

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

src/interactions/commands/command-manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { backupRequestCommand } from './handlers/backup-request';
2424
import { createVoicechat } from './handlers/voicechat/voice-slash';
2525
import { removeBlueskyPostFromFeedSlashCommand } from './handlers/remove-bluesky-post-from-feed-slash';
2626
import { supportedVersionsSlashCommand } from './handlers/supported-versions-slash';
27+
import { addBlueskyPostToFeedSlashCommand } from './handlers/add-bluesky-post-to-feed-slash';
2728

2829
class CommandManager implements IInteractionManager {
2930
private handlers: ICommandHandler[] = [];
@@ -49,6 +50,7 @@ class CommandManager implements IInteractionManager {
4950
backupRequestCommand,
5051
createVoicechat,
5152
removeBlueskyPostFromFeedSlashCommand,
53+
addBlueskyPostToFeedSlashCommand,
5254
supportedVersionsSlashCommand
5355
];
5456

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
2+
import { CommandType, ICommandHandler } from '../command-handler.interface';
3+
import { addPostToFeed, removePostFromFeed } from '../../../services/firebot-atproto-feed.service';
4+
5+
const config = new SlashCommandBuilder()
6+
.setName('addtofeed')
7+
.setDescription('Add a post to the Firebot Bluesky feed')
8+
.addStringOption((option) =>
9+
option
10+
.setName('posturl')
11+
.setDescription('The url of the post to add to the feed')
12+
.setRequired(true)
13+
)
14+
.setDefaultMemberPermissions(0);
15+
16+
export const addBlueskyPostToFeedSlashCommand: ICommandHandler = {
17+
type: CommandType.SlashCommand,
18+
config,
19+
async onTrigger(interaction) {
20+
await interaction.deferReply();
21+
22+
const postUrl = interaction.options.getString('posturl', true);
23+
24+
const { success, errorMessage } = await addPostToFeed(postUrl);
25+
26+
if (success) {
27+
await interaction.followUp({
28+
content: `Successfully added post to Firebot Bluesky feed!`,
29+
});
30+
} else {
31+
await interaction.followUp({
32+
content: `Could not add post to feed: ${errorMessage ?? 'Unknown error'}`,
33+
});
34+
}
35+
},
36+
};

src/services/firebot-atproto-feed.service.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,44 @@ export async function removePostFromFeed(
2525
errorMessage: error?.response?.data?.error,
2626
};
2727
} else {
28-
console.log('Error getting featured streams', error);
28+
console.log('Error removing post from feed', error);
2929
return {
3030
success: false,
3131
errorMessage: 'An error occurred removing post from feed',
3232
};
3333
}
3434
}
3535
}
36+
37+
export async function addPostToFeed(
38+
postUrl: string
39+
): Promise<{ success: boolean; errorMessage?: string }> {
40+
try {
41+
const response = await axios.post(
42+
'https://atprotofeed.firebot.app/post',
43+
{
44+
params: {
45+
postUrl,
46+
token: config.firebot.atProtoFeedApiToken,
47+
},
48+
}
49+
);
50+
return {
51+
success: response?.status === 200,
52+
errorMessage: response?.data?.error,
53+
};
54+
} catch (error) {
55+
if (error && error.response) {
56+
return {
57+
success: false,
58+
errorMessage: error?.response?.data?.error,
59+
};
60+
} else {
61+
console.log('Error adding post to feed', error);
62+
return {
63+
success: false,
64+
errorMessage: 'An error occurred adding post to feed',
65+
};
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)