Skip to content

Commit a789ee5

Browse files
Merge pull request #222 from Pdzly/feature/devbin-integration
2 parents f23d807 + afaac8a commit a789ee5

6 files changed

Lines changed: 30 additions & 14 deletions

File tree

.env.local.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
DDB_HOST=localhost
22
DDB_PORT=5432
33

4-
DDB_BOT_TOKEN=
4+
DDB_BOT_TOKEN=
5+
6+
DDB_PASTE_BYPASS_TOKEN=

src/Config.prod.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export const config: Config = {
7272
archiveChannel: "1415283787440328836",
7373
channel: "1415283659350741062",
7474
},
75-
pastebin: {
76-
url: "https://paste.developerden.org",
75+
devbin: {
76+
url: "https://devbin.developerden.org",
77+
api_url: "https://devbin-api.developerden.org",
7778
threshold: 20,
7879
},
7980
branding: {

src/Config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const devConfig: Config = {
7070
archiveChannel: "1412470199495561338",
7171
channel: "1412470223004766268",
7272
},
73-
pastebin: prodConfig.pastebin,
73+
devbin: prodConfig.devbin,
7474
branding: {
7575
color: "#ffffff",
7676
font: "CascadiaCode.ttf",

src/config.type.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ export interface Config {
6262
yesEmojiId: string;
6363
noEmojiId: string;
6464
};
65-
pastebin: { url: string; threshold: number };
65+
devbin: {
66+
url: string;
67+
api_url: string;
68+
threshold: number
69+
};
6670
channels: {
6771
welcome: string;
6872
botCommands: string;

src/modules/pastify/paste.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export const PasteCommand: Command<ApplicationCommandType.ChatInput> = {
1010
options: [],
1111

1212
handle: async (interaction: CommandInteraction) =>
13-
await interaction.reply(config.pastebin.url),
13+
await interaction.reply(config.devbin.url),
1414
};

src/modules/pastify/pastify.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from "../../logging.js";
55
import { createStandardEmbed } from "../../util/embeds.js";
66
import { mentionIfPingable } from "../../util/users.js";
77

8+
const BYPASS_TOKEN = process.env.DDB_PASTE_BYPASS_TOKEN;
9+
810
const codeBlockPattern =
911
/```(?:(?<lang>[a-zA-Z]+)?\n)?(?<content>(?:.|\n)*?)```|(?:(?:.|\n)(?!```))+/g;
1012

@@ -17,7 +19,7 @@ type SplitMessageComponent =
1719

1820
export function splitMessage(
1921
message: string,
20-
threshold: number = config.pastebin.threshold,
22+
threshold: number = config.devbin.threshold
2123
) {
2224
const matches = message.matchAll(codeBlockPattern);
2325

@@ -44,9 +46,18 @@ export async function upload(component: SplitMessageComponent) {
4446
if ("text" in component) {
4547
return component.text;
4648
}
49+
const header: { [key: string]: string } = {
50+
"Content-Type": "application/json",
51+
"Accept": "application/json"
52+
};
53+
54+
if (BYPASS_TOKEN) {
55+
header.Authorization = BYPASS_TOKEN;
56+
}
4757

48-
const response = await fetch(`${config.pastebin.url}/documents`, {
58+
const response = await fetch(`${config.devbin.api_url}/documents`, {
4959
method: "POST",
60+
headers: header,
5061
body: component.content,
5162
});
5263

@@ -57,16 +68,14 @@ export async function upload(component: SplitMessageComponent) {
5768
return "Pasting failed";
5869
}
5970

60-
const key = ((await response.json()) as { key: string }).key;
71+
const id = ((await response.json()) as { id: string }).id;
6172

62-
if (!key) {
63-
logger.warn("Key was missing from pastebin response");
73+
if (!id) {
74+
logger.warn("Id was missing from pastebin response");
6475
return "Pasting failed";
6576
}
6677

67-
return `${config.pastebin.url}/${key}${
68-
component.language ? `.${component.language}` : ""
69-
}`;
78+
return `${config.devbin.url}/paste/${id}`;
7079
}
7180

7281
type PastifyReturn<T extends boolean> = T extends true

0 commit comments

Comments
 (0)