Skip to content

Commit

Permalink
style: prettier formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jul 19, 2024
1 parent b0438f2 commit 3ff1b06
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 109 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"type": "module",
"scripts": {
"start": "NODE_ENV=production bun src/index.ts",
"validate:tags": "bun scripts/validate_tags/index.ts"
"validate:tags": "bun scripts/validate_tags/index.ts",
"format:check": "prettier . --check",
"format:apply": "prettier . --write"
},
"devDependencies": {
"bun-types": "^1.1.6"
"bun-types": "^1.1.6",
"prettier": "3.3.3"
},
"dependencies": {
"@lilybird/handlers": "^0.6.0-beta.9",
Expand All @@ -22,4 +25,4 @@
"gray-matter": "^4.0.3",
"lilybird": "^0.7.3"
}
}
}
19 changes: 10 additions & 9 deletions src/commands/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { safeSlice } from "src/util.ts";
// @ts-expect-error It is callable, but algolia for some reason has a namespace with the same name
const algoliaClient = algoliasearch(
"2527C13E0N",
"4efc87205e1fce4a1f267cadcab42cb2"
"4efc87205e1fce4a1f267cadcab42cb2",
);
const algoliaIndex = algoliaClient.initIndex("bun");

Expand All @@ -20,11 +20,12 @@ $applicationCommand({
description: "Select query",
required: true,
autocomplete: true,
}, {
},
{
type: ApplicationCommandOptionType.USER,
name: "target",
description: "User to mention"
}
description: "User to mention",
},
],
autocomplete: async (interaction) => {
const query = interaction.data.getFocused<string>().value;
Expand All @@ -40,7 +41,7 @@ $applicationCommand({
name: safeSlice(name.full, 100),
value: safeSlice(name.name, 100),
};
})
}),
);
},
handle: async (interaction) => {
Expand All @@ -58,7 +59,7 @@ $applicationCommand({
const name = getHitName(hit);
const snippetContent = hit._snippetResult?.content?.value?.replace(
/<[^>]+>/g,
""
"",
);
const notice = hit.content?.replace(/\r/g, "");

Expand All @@ -68,9 +69,9 @@ $applicationCommand({
snippetContent ? snippetContent : "",
notice
? notice
.split("\n")
.map((s: any) => `> ${s}`)
.join("\n")
.split("\n")
.map((s: any) => `> ${s}`)
.join("\n")
: "",
].join("\n");

Expand Down
43 changes: 24 additions & 19 deletions src/commands/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { $applicationCommand } from "@lilybird/handlers/advanced";
import { ApplicationCommandOptionType } from "lilybird";
import { safeSlice, silently } from "../util.ts";
Expand Down Expand Up @@ -35,16 +34,18 @@ interface Item {

$applicationCommand({
name: "github",
description: "Query an issue, pull request or direct link to issue, pull request",
description:
"Query an issue, pull request or direct link to issue, pull request",
options: [
{
type: ApplicationCommandOptionType.STRING,
name: "query",
description: "Issue/Pull request number or name",
autocomplete: true,
required: true,
max_length: 100
}, {
max_length: 100,
},
{
type: ApplicationCommandOptionType.STRING,
name: "state",
description: "Issue or Pull request state",
Expand All @@ -55,31 +56,33 @@ $applicationCommand({
{ name: "⚫️ Closed", value: "closed" },
{ name: "🟣 Merged", value: "merged" },
{ name: "📝 Draft", value: "draft" },
{ name: "🌍 All", value: "all" }
]
}, {
{ name: "🌍 All", value: "all" },
],
},
{
type: ApplicationCommandOptionType.STRING,
name: "type",
description: "Issue/Pull request number or name",
choices: [
{ name: "🐛 Issues", value: "issues" },
{ name: "🔨 Pull Requests", value: "pull_requests" },
{ name: "🌍 Both", value: "both" }
{ name: "🌍 Both", value: "both" },
],
},
{
type: ApplicationCommandOptionType.BOOLEAN,
name: "hide",
description: "Show this message only for you"
}
description: "Show this message only for you",
},
],
handle: async (interaction) => {
const hide = interaction.data.getBoolean("hide") ?? false;

await interaction.deferReply(hide);

const query = interaction.data.getString("query", true);
const state: State = (interaction.data.getString("state") as State) || "all";
const state: State =
(interaction.data.getString("state") as State) || "all";
const type: Type = (interaction.data.getString("type") as Type) || "both";

const result = (await search(query, state, type))[0];
Expand All @@ -95,8 +98,10 @@ $applicationCommand({

interaction.editReply({
content: [
`${result.emoji.type} ${result.emoji.state} [#${result.number
} in oven-sh/bun](<${result.html_url}>) by [${result.user.login}](<${result.user.html_url
`${result.emoji.type} ${result.emoji.state} [#${
result.number
} in oven-sh/bun](<${result.html_url}>) by [${result.user.login}](<${
result.user.html_url
}>) ${stateToText(result)} ${stateToTimestamp(result)}`,
result.title,
].join("\n"),
Expand All @@ -118,11 +123,11 @@ $applicationCommand({
response.map((r) => ({
name: safeSlice<string>(
`${r.emoji.type} ${r.emoji.state} #${r.number} | ${r.title}`,
100
100,
),
value: r.number.toString(),
}))
)
})),
),
);
},
});
Expand Down Expand Up @@ -178,7 +183,7 @@ async function search(
query: string,
state: State,
type: Type,
length = 1
length = 1,
): Promise<Item[]> {
let actualQuery = "repo:oven-sh/bun ";

Expand Down Expand Up @@ -225,14 +230,14 @@ async function search(

const response = await fetch(
`https://api.github.com/search/issues?q=${encodeURIComponent(
actualQuery
actualQuery,
)}&per_page=${length}`,
{
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
Accept: "application/vnd.github+json",
},
}
},
);

const body = await response.json();
Expand Down
23 changes: 12 additions & 11 deletions src/commands/mdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const MDN_DATA = (await (
const cache = new Map<string, Document>();

$applicationCommand({

name: "mdn",
description: "Search the Mozilla Developer Network documentation",
options: [
Expand All @@ -48,16 +47,18 @@ $applicationCommand({
description: "Class or method to search for",
required: true,
autocomplete: true,
max_length: 100
}, {
max_length: 100,
},
{
type: ApplicationCommandOptionType.USER,
name: "target",
description: "User to mention"
}, {
description: "User to mention",
},
{
type: ApplicationCommandOptionType.BOOLEAN,
name: "hide",
description: "Show this message only for you"
}
description: "Show this message only for you",
},
],
handle: async (interaction) => {
const hide = interaction.data.getBoolean("hide") ?? false;
Expand All @@ -73,7 +74,7 @@ $applicationCommand({
if (!hit) {
try {
const result = (await fetch(key).then(async (response) =>
response.json()
response.json(),
)) as APIResult;
hit = result.doc;
} catch {
Expand Down Expand Up @@ -143,9 +144,9 @@ $applicationCommand({
name: candidate.entry.title,
value: candidate.entry.url,
})),
25
)
)
25,
),
),
);
},
});
Expand Down
57 changes: 30 additions & 27 deletions src/commands/ping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,38 @@ import { ButtonStyle, ComponentType } from "lilybird";
$applicationCommand({
name: "ping",
description: "pong",
components: [{
type: ComponentType.Button,
id: "ping",
customMatcher: `custom_id[0] == "0" && custom_id[1] == "-"`,
handle: (interaction) => {
const combined = interaction.data.id.split("-")?.[1];
if (!combined) return;
components: [
{
type: ComponentType.Button,
id: "ping",
customMatcher: `custom_id[0] == "0" && custom_id[1] == "-"`,
handle: (interaction) => {
const combined = interaction.data.id.split("-")?.[1];
if (!combined) return;

const [ws, wsClosedForm, rest, restClosedForm] = S.generic.decodeCustomId(combined);
const [ws, wsClosedForm, rest, restClosedForm] =
S.generic.decodeCustomId(combined);

silently(
interaction.reply({
content: [
`🏓`,
"**WebSocket:**",
`\`${wsClosedForm}\``,
`\`≈ ${ws} ms\``,
"",
"**Rest:**",
`\`${restClosedForm}\``,
`\`≈ ${rest} ms\``,
"",
"Mathematics is the language of the universe, it's truly fascinating! 😄",
].join("\n"),
ephemeral: true,
})
);
}
}],
silently(
interaction.reply({
content: [
`🏓`,
"**WebSocket:**",
`\`${wsClosedForm}\``,
`\`≈ ${ws} ms\``,
"",
"**Rest:**",
`\`${restClosedForm}\``,
`\`≈ ${rest} ms\``,
"",
"Mathematics is the language of the universe, it's truly fascinating! 😄",
].join("\n"),
ephemeral: true,
}),
);
},
},
],
handle: async (interaction) => {
await interaction.deferReply();

Expand Down
7 changes: 3 additions & 4 deletions src/commands/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ $applicationCommand({
description: "Get tag",
options: [
{

type: ApplicationCommandOptionType.STRING,
name: "query",
description: "Select query",
required: true,
autocomplete: true
autocomplete: true,
},
{
type: ApplicationCommandOptionType.USER,
name: "target",
description: "User to mention"
}
description: "User to mention",
},
],
handle: async (interaction) => {
if (!interaction.inGuild()) return;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ $applicationCommand({
handle: (interaction) => {
interaction.reply({
content: [
`[git-bun-discord-bot-${COMMIT_HASH}](<https://github.com/xHyroM/bun-discord-bot/tree/${COMMIT_HASH}>) ${!PRODUCTION ? "(dev)" : ""
`[git-bun-discord-bot-${COMMIT_HASH}](<https://github.com/xHyroM/bun-discord-bot/tree/${COMMIT_HASH}>) ${
!PRODUCTION ? "(dev)" : ""
}`,
`[Bun v${Bun.version} (${Bun.revision})](<https://github.com/oven-sh/bun/releases/tag/bun-v${Bun.version}>)`,
"",
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const COMMIT_HASH = spawnSync({
export const LILYBIRD_VERSION = sliceIfStartsWith(dependencies.lilybird, "^");
export const LILYBIRD_JSX_VERSION = sliceIfStartsWith(
dependencies["@lilybird/jsx"],
"^"
"^",
);
export const LILYBIRD_HANDLERS_VERSION = sliceIfStartsWith(
dependencies["@lilybird/handlers"],
"^"
"^",
);

export const PRODUCTION = process.env.NODE_ENV === "production";
Expand Down
2 changes: 1 addition & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const transformers = simpleTransformers;
export const handler = new Handler<SimpleTransformers>({});
export const $applicationCommand = handler.storeCommand.bind(handler);
export const $listener = handler.storeListener.bind(handler);
export const $component = handler.buttonCollector.bind(handler);
export const $component = handler.buttonCollector.bind(handler);
Loading

0 comments on commit 3ff1b06

Please sign in to comment.