This commit is contained in:
Yuzu 2022-07-14 12:58:09 -05:00
parent a2dd9ddf5d
commit 4dd48d9bb4
10 changed files with 274 additions and 272 deletions

View File

@ -7,7 +7,6 @@
[![downloads](https://img.shields.io/npm/dw/@oasisjs/biscuit?color=green&logo=npm&style=flat)](https://www.npmjs.com/package/@oasisjs/biscuit)
[![deno.land](https://img.shields.io/badge/deno-%5E1.23.3-informational?color=blue&logo=deno&style=flat)](https://deno.land/x/biscuit)
<img align="right" src="https://raw.githubusercontent.com/oasisjs/biscuit/main/assets/biscuit.svg" alt="biscuit"/>
### Install (for [node18](https://nodejs.org/en/download/))

View File

@ -1,4 +1,4 @@
import 'https://deno.land/std@0.146.0/dotenv/load.ts';
import "https://deno.land/std@0.146.0/dotenv/load.ts";
import {
ActionRowBuilder,
ButtonBuilder,
@ -6,23 +6,23 @@ import {
GatewayIntents,
InteractionResponseTypes,
Session,
} from 'https://x.nest.land/biscuit/mod.ts';
} from "https://x.nest.land/biscuit/mod.ts";
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
if (!token) {
throw new Error('Please provide a token');
throw new Error("Please provide a token");
}
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
const session = new Session({ token, intents });
const PREFIX = ">";
const components = new ButtonBuilder().setCustomId('ping').setLabel('Hello!').setStyle(ButtonStyles.Success);
const components = new ButtonBuilder().setCustomId("ping").setLabel("Hello!").setStyle(ButtonStyles.Success);
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(components).toJSON();
session.on('ready', (payload) => {
console.log('Logged in as:', payload.user.username);
session.on("ready", (payload) => {
console.log("Logged in as:", payload.user.username);
});
session.on("messageCreate", (message) => {
@ -34,13 +34,13 @@ session.on("messageCreate", (message) => {
const name = args.shift()?.toLowerCase();
console.log(args, name);
if (name === 'ping') {
if (name === "ping") {
message.reply({ components: [row] });
}
});
// Follow interaction event
session.on('interactionCreate', (interaction) => {
session.on("interactionCreate", (interaction) => {
if (!interaction.isComponent()) {
return;
}

View File

@ -1,7 +1,7 @@
/**
* Bun example
* this example should work on most systems, but if it doesn't just clone the library and import everything from mod.ts
*/
*/
const { GatewayIntents, Session } = require("@oasisjs/biscuit");
@ -30,4 +30,3 @@ session.on("messageCreate", async (message) => {
});
await session.start();

View File

@ -36,4 +36,3 @@ session.on("messageCreate", (message) => {
});
session.start();

View File

@ -1,13 +1,13 @@
/**
* Biscuit node example
*/
*/
// process for get the token
/** @type {NodeJS.Process} process */
import process from 'node:process';
import process from "node:process";
// Session for create a new bot and intents
import { Session, GatewayIntents } from '@oasisjs/biscuit';
import { GatewayIntents, Session } from "@oasisjs/biscuit";
// Discord bot token
/** @type {string} token */
@ -26,7 +26,7 @@ const PREFIX = ">";
session.on("ready", (data) => {
console.log("Ready! Let's start chatting!");
console.log("Connected as: " + data.user.username);
})
});
session.on("messageCreate", (message) => {
if (message.author?.bot || !message.content.startsWith(PREFIX)) {

View File

@ -1,6 +1,6 @@
/**
* Biscuit node example
*/
*/
// process for get the token
/** @type {NodeJS.Process} process */
@ -26,7 +26,7 @@ const PREFIX = ">";
session.on("ready", (data) => {
console.log("Ready! Let's start chatting!");
console.log("Connected as: " + data.user.username);
})
});
session.on("messageCreate", (message) => {
if (message.author?.bot || !message.content.startsWith(PREFIX)) {

View File

@ -1,5 +1,10 @@
import "https://deno.land/std@0.146.0/dotenv/load.ts";
import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "https://x.nest.land/biscuit/mod.ts";
import {
CreateApplicationCommand,
GatewayIntents,
InteractionResponseTypes,
Session,
} from "https://x.nest.land/biscuit/mod.ts";
const token = Deno.env.get("TOKEN") ?? Deno.args[0];

View File

@ -1,14 +1,14 @@
import type { Localization, PermissionStrings } from '../../../../discordeno/mod.ts';
import { ApplicationCommandTypes } from '../../../../discordeno/mod.ts';
import { OptionBased } from './ApplicationCommandOption.ts';
import { CreateApplicationCommand } from "../../../Session.ts"
import type { Localization, PermissionStrings } from "../../../../discordeno/mod.ts";
import { ApplicationCommandTypes } from "../../../../discordeno/mod.ts";
import { OptionBased } from "./ApplicationCommandOption.ts";
import { CreateApplicationCommand } from "../../../Session.ts";
export abstract class ApplicationCommandBuilder implements CreateApplicationCommand {
protected constructor(
// required
public type: ApplicationCommandTypes = ApplicationCommandTypes.ChatInput,
public name = '',
public description = '',
public name = "",
public description = "",
// non-required
public defaultMemberPermissions?: PermissionStrings[],
// etc
@ -69,7 +69,7 @@ export class MessageApplicationCommandBuilder {
}
public toJSON(): { name: string; type: ApplicationCommandTypes.Message } {
if (!this.name) throw new TypeError('Propety \'name\' is required');
if (!this.name) throw new TypeError("Propety 'name' is required");
return {
type: ApplicationCommandTypes.Message,
@ -82,10 +82,10 @@ export class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilde
public type: ApplicationCommandTypes.ChatInput = ApplicationCommandTypes.ChatInput;
public toJSON(): CreateApplicationCommand {
if (!this.type) throw new TypeError('Propety \'type\' is required');
if (!this.name) throw new TypeError('Propety \'name\' is required');
if (!this.type) throw new TypeError("Propety 'type' is required");
if (!this.name) throw new TypeError("Propety 'name' is required");
if (!this.description) {
throw new TypeError('Propety \'description\' is required');
throw new TypeError("Propety 'description' is required");
}
return {

View File

@ -1,5 +1,5 @@
import { ApplicationCommandOptionTypes, type ChannelTypes, type Localization } from "../../../../discordeno/mod.ts";
import { ApplicationCommandOptionChoice } from "../../interactions/CommandInteraction.ts"
import { ApplicationCommandOptionChoice } from "../../interactions/CommandInteraction.ts";
export class ChoiceBuilder {
public name?: string;