Nubis, Eytak'tan açık kaynak bir framework
Nubis, Discord botları için bir TypeScript framework'ü. Bir dosya yaz, bir slash komutun olsun: tipleri yazdığından çıkar, testleri Discord olmadan çalışır.
$ npx create-nubis my-botimport { command, hasPermission, option } from "nubis";
import { PermissionFlagsBits } from "discord-api-types/v10";
import { confirmBan } from "../../components/confirm-ban";
export default command({
description: "Ban a member",
ephemeral: true,
options: {
user: option.user({ required: true }),
days: option.integer({
choices: [
{ name: "One day", value: 1 },
{ name: "A week", value: 7 },
],
}),
},
guards: [hasPermission(PermissionFlagsBits.BanMembers)],
run: ({ options, reply }) =>
reply({
content: `Ban ${options.user.username}?`,
components: [confirmBan({ userId: options.user.id })],
}),
});
ada/mod ban kullandı
my-botUygulama
Ban alice?
Bunu yalnızca sen görebilirsin
commands/mod/ban.ts/mod ban
Bir dosya seç. Yolu, komutun kendisi.Tipler
Seçenek değerleri, seçim birleşimleri, bileşen durumu ve modal alanları tanımlarından çıkarılır. Bir şeyi string'le arayıp bulman gerekmez.
days: option.integer({
choices: [
{ name: "One day", value: 1 },
{ name: "A week", value: 7 },
],
}),çıkarıldı
options.days: 1 | 7 | undefined
export const confirmBan = button({
id: "confirm-ban",
label: "Confirm",
state: z.object({ userId: z.string() }),
onClick: ({ state }) => …çıkarıldı
state.userId: string
fields: {
reason: textInput({
label: "Reason",
required: true,
}),
contact: textInput({ label: "Contact" }),
},çıkarıldı
values.contact: string | undefined
Discord'un kuralları
En fazla 32 karakterlik komut adları, en çok 25 seçenek ve 25 seçim, 100 karakterlik custom_id'ler, 5 satır bileşen. Discord'un reddedeceği bir tanım, yüklendiği anda hata verir ve hata nerede olduğunu söyler.
days: option.integer({
choices: [
{ name: "One day", value: 1 },
{ name: "A week and a half", value: 7.5 },
],
}),$ nubis dev
[nubis] Synced commands:
+ ping
+ mod
[nubis] commands/mod/ban.ts changed, restarting.
[nubis] /mod ban option "days": integer choices must be whole numbers.
[nubis] Fix the error and save; I'll try again.
Test
nubis/testing; komutları, düğmeleri, seçim menülerini, modalları ve menüleri Discord'un çalıştıracağı gibi çalıştırır. Token yok, ağ yok, test sunucusu yok.
import { PermissionFlagsBits } from "discord-api-types/v10";
import { fake, testCommand } from "nubis/testing";
import ban from "../commands/mod/ban";
test("asks for confirmation", async () => {
const result = await testCommand(ban)
.as({ permissions: PermissionFlagsBits.BanMembers })
.run({ user: fake.user("alice") });
expect(result.replies).toEqual(["Ban alice?"]);
expect(result.ephemeral).toBe(true);
});
test("members without the permission are turned away", async () => {
const result = await testCommand(ban).run({ user: fake.user("alice") });
expect(result.status).toBe("denied");
});$ bun test
tests/ban.test.ts:
✓ asks for confirmation
✓ members without the permission are turned away
2 pass
0 fail
Yanıtlar
Discord bir bota yanıt vermesi için 3 saniye tanır. Sen reply() çağır, gerisini Nubis halleder: bekleme mesajı, düzenleme ve ek mesajlar.
0 sn
Handler'ın raporu hazırlamaya başlar.
2 sn
2 saniye yanıt gelmezse, Discord'un 3 saniyelik süresi dolmadan.
Hazır olunca
İlk yanıt “düşünüyor…” mesajının yerini alır.
15 dk içinde
Sonraki yanıtlar, gönderdiğin sırayla yeni mesaj olarak gelir.
Discord'un sınırı · 3 sn