Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/discord/bot/commands/webhooks/DeleteWebhookCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export default class extends Command<GitCordClient> {
return;
}

const getChannelName = (id: string) => {
const channel = this.client.channels.cache.get(id);
return channel?.toString() || `#${id}`;
};

if (!input.value || typeof input.value !== "string") {
await interaction.respond(config.webhooks.map((webhook) => ({ name: webhook.id, value: webhook.id })));
await interaction.respond(config.webhooks.map((webhook) => ({ name: getChannelName(webhook.id), value: webhook.id })));
return;
}

const inputValue = input.value as string; // The command input type is a string
const allOptions = config.webhooks.map((webhook) => webhook.id);
const options = allOptions.filter((opt) => opt.startsWith(inputValue) || opt.endsWith(inputValue) || opt.includes(inputValue));

await interaction.respond(options.map((opt) => ({ name: opt, value: opt })));
await interaction.respond(options.map((opt) => ({ name: getChannelName(opt), value: opt })));
}

public override async run(interaction: CommandInteraction<"cached">) {
Expand Down
9 changes: 7 additions & 2 deletions src/discord/bot/commands/webhooks/GetSecretCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export default class extends Command<GitCordClient> {
return;
}

const getChannelName = (id: string) => {
const channel = this.client.channels.cache.get(id);
return channel?.toString() || `#${id}`;
};

if (!input.value || typeof input.value !== "string") {
await interaction.respond(config.webhooks.map((webhook) => ({ name: webhook.id, value: webhook.id })));
await interaction.respond(config.webhooks.map((webhook) => ({ name: getChannelName(webhook.id), value: webhook.id })));
return;
}

const inputValue = input.value as string; // The command input type is a string
const allOptions = config.webhooks.map((webhook) => webhook.id);
const options = allOptions.filter((opt) => opt.startsWith(inputValue) || opt.endsWith(inputValue) || opt.includes(inputValue));

await interaction.respond(options.map((opt) => ({ name: opt, value: opt })));
await interaction.respond(options.map((opt) => ({ name: getChannelName(opt), value: opt })));
}

public override async run(interaction: CommandInteraction<"cached">) {
Expand Down
2 changes: 1 addition & 1 deletion src/github/lib/GitHubManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type GitCordClient from "../../discord/lib/GitCordClient.js";
import type GitCordClient from "#discord/lib/GitCordClient.js";
import GitHubEmbedLoader from "./embed/GitHubEmbedLoader.js";
import GitHubWebhookManager from "./webhook/GitHubWebhookManager.js";

Expand Down
6 changes: 3 additions & 3 deletions src/github/lib/webhook/GitHubWebhookManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RequestManager, RequestMethod } from "@discordjs/rest";
import BodyParser from "body-parser";

export default class GitHubWebhookManager {
public requestManager = new RequestManager({});
public requestManager = new RequestManager({ userAgentAppendix: "GitCord (https://github.com/ijsKoud/gitcord)" });

public constructor(public client: GitCordClient, public manager: GitHubManager) {}

Expand Down Expand Up @@ -51,7 +51,7 @@ export default class GitHubWebhookManager {
);
};

this.client.logger.info(`[GITHUB]: Smee.io connection ready for event listening.`);
this.client.logger.info("[GITHUB]: Smee.io connection ready for event listening.");
}

private initProd() {
Expand All @@ -60,7 +60,7 @@ export default class GitHubWebhookManager {
.use(BodyParser.json())
.post("/webhook/:guildId/:webhookId", this.handleRequest.bind(this))
.get("*", (_, res) => res.redirect("https://ijskoud.dev/github/gitcord"))
.listen(Number(process.env.PORT), () => this.client.logger.info(`[GITHUB]: Webhook server ready for event listening.`));
.listen(Number(process.env.PORT), () => this.client.logger.info("[GITHUB]: Webhook server ready for event listening."));
}

private async handleRequest(req: Request, res: Response) {
Expand Down