mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-10 01:08:07 +01:00
feat(ping): implement button for normal people
This commit is contained in:
parent
7ecb0a201a
commit
d8614afdf9
5 changed files with 87 additions and 1 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -15,6 +15,7 @@
|
||||||
"@lilybird/jsx": "0.2.0",
|
"@lilybird/jsx": "0.2.0",
|
||||||
"@lilybird/transformers": "^0.2.0",
|
"@lilybird/transformers": "^0.2.0",
|
||||||
"@paperdave/logger": "^3.0.1",
|
"@paperdave/logger": "^3.0.1",
|
||||||
|
"@purplet/serialize": "^2.0.0",
|
||||||
"@wolfram-alpha/wolfram-alpha-api": "^23.1004.144821-RELEASE",
|
"@wolfram-alpha/wolfram-alpha-api": "^23.1004.144821-RELEASE",
|
||||||
"algoliasearch": "^4.23.2",
|
"algoliasearch": "^4.23.2",
|
||||||
"bun-tracestrings": "github:oven-sh/bun.report",
|
"bun-tracestrings": "github:oven-sh/bun.report",
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import { ApplicationCommand as JSXApplicationCommand } from "@lilybird/jsx";
|
import {
|
||||||
|
ActionRow,
|
||||||
|
Button,
|
||||||
|
ApplicationCommand as JSXApplicationCommand,
|
||||||
|
} from "@lilybird/jsx";
|
||||||
import { ApplicationCommand } from "@lilybird/handlers";
|
import { ApplicationCommand } from "@lilybird/handlers";
|
||||||
|
import { serializers as S } from "@purplet/serialize";
|
||||||
import { possibleClosedForm } from "../util.ts";
|
import { possibleClosedForm } from "../util.ts";
|
||||||
|
import { ButtonStyle } from "lilybird";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
post: "GLOBAL",
|
post: "GLOBAL",
|
||||||
|
@ -15,12 +21,29 @@ export default {
|
||||||
possibleClosedForm(rest),
|
possibleClosedForm(rest),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const serialized = S.generic.encodeCustomId([
|
||||||
|
ws,
|
||||||
|
wsClosedForm,
|
||||||
|
rest,
|
||||||
|
restClosedForm,
|
||||||
|
]);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: [
|
content: [
|
||||||
`🏓`,
|
`🏓`,
|
||||||
`WebSocket: \`${wsClosedForm} ms\``,
|
`WebSocket: \`${wsClosedForm} ms\``,
|
||||||
`Rest: \`${restClosedForm} ms\``,
|
`Rest: \`${restClosedForm} ms\``,
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
|
components: [
|
||||||
|
<ActionRow>
|
||||||
|
<Button
|
||||||
|
label="I'm dumb!"
|
||||||
|
style={ButtonStyle.Danger}
|
||||||
|
emoji={{ name: "😕", id: null, animated: false }}
|
||||||
|
id={`0-${serialized}`}
|
||||||
|
/>
|
||||||
|
</ActionRow>,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
} satisfies ApplicationCommand;
|
} satisfies ApplicationCommand;
|
||||||
|
|
42
src/listeners/interaction_create.ts
Normal file
42
src/listeners/interaction_create.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import { Event } from "@lilybird/handlers";
|
||||||
|
import { serializers as S } from "@purplet/serialize";
|
||||||
|
import { silently } from "src/util.ts";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
event: "interactionCreate",
|
||||||
|
run: (interaction) => {
|
||||||
|
if (
|
||||||
|
!interaction.isMessageComponentInteraction() ||
|
||||||
|
!interaction.data.isButton()
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const id = interaction.data.id;
|
||||||
|
|
||||||
|
if (id?.[0] == "0" && id?.[1] == "-") {
|
||||||
|
const combined = interaction.data.id.split("-")?.[1];
|
||||||
|
if (!combined) return;
|
||||||
|
|
||||||
|
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! And being a software engineer requires a deep understanding of this language. It's not an easy field, but it's incredibly rewarding. 😄",
|
||||||
|
].join("\n"),
|
||||||
|
ephemeral: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} satisfies Event<"interactionCreate">;
|
|
@ -1,5 +1,8 @@
|
||||||
|
import { serializers as S } from "@purplet/serialize";
|
||||||
import { MessageCommand } from "@lilybird/handlers";
|
import { MessageCommand } from "@lilybird/handlers";
|
||||||
|
import { ActionRow, Button } from "@lilybird/jsx";
|
||||||
import { possibleClosedForm } from "../util.ts";
|
import { possibleClosedForm } from "../util.ts";
|
||||||
|
import { ButtonStyle } from "lilybird";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ping",
|
name: "ping",
|
||||||
|
@ -15,12 +18,29 @@ export default {
|
||||||
possibleClosedForm(rest),
|
possibleClosedForm(rest),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const serialized = S.generic.encodeCustomId([
|
||||||
|
ws,
|
||||||
|
wsClosedForm,
|
||||||
|
rest,
|
||||||
|
restClosedForm,
|
||||||
|
]);
|
||||||
|
|
||||||
await newMessage.edit({
|
await newMessage.edit({
|
||||||
content: [
|
content: [
|
||||||
`🏓`,
|
`🏓`,
|
||||||
`WebSocket: \`${wsClosedForm} ms\``,
|
`WebSocket: \`${wsClosedForm} ms\``,
|
||||||
`Rest: \`${restClosedForm} ms\``,
|
`Rest: \`${restClosedForm} ms\``,
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
|
components: [
|
||||||
|
<ActionRow>
|
||||||
|
<Button
|
||||||
|
label="I'm dumb!"
|
||||||
|
style={ButtonStyle.Danger}
|
||||||
|
emoji={{ name: "😕", id: null, animated: false }}
|
||||||
|
id={`0-${serialized}`}
|
||||||
|
/>
|
||||||
|
</ActionRow>,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
} satisfies MessageCommand;
|
} satisfies MessageCommand;
|
Loading…
Reference in a new issue