From a2dd9ddf5df11ada9084fc34c64f2b6581df344b Mon Sep 17 00:00:00 2001 From: Yuzu Date: Thu, 14 Jul 2022 12:54:33 -0500 Subject: [PATCH] fix: examples --- examples/components/mod.ts | 19 ++++++++------- examples/hello-bun/index.js | 9 +++++--- examples/hello-deno/mod.ts | 10 ++++---- examples/node.js | 42 ---------------------------------- examples/nodemodules.mjs | 42 ---------------------------------- examples/slash-commands/mod.ts | 2 +- 6 files changed, 21 insertions(+), 103 deletions(-) delete mode 100644 examples/node.js delete mode 100644 examples/nodemodules.mjs diff --git a/examples/components/mod.ts b/examples/components/mod.ts index fb52bc6..14431c0 100644 --- a/examples/components/mod.ts +++ b/examples/components/mod.ts @@ -3,11 +3,10 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyles, - ComponentInteraction, GatewayIntents, InteractionResponseTypes, Session, -} from 'https://x.nest.land/biscuit@0.1.0/mod.ts'; +} from 'https://x.nest.land/biscuit/mod.ts'; const token = Deno.env.get("TOKEN") ?? Deno.args[0]; @@ -36,22 +35,22 @@ session.on("messageCreate", (message) => { console.log(args, name); if (name === 'ping') { - message.reply({ components: [row] }) - .then(() => {}) - .catch((e) => console.error(e)); + message.reply({ components: [row] }); } }); // Follow interaction event session.on('interactionCreate', (interaction) => { - if (!interaction.isComponent()) return; - const component = interaction as ComponentInteraction; - if (component.customId == "ping") { - component.respond({ + if (!interaction.isComponent()) { + return; + } + + if (interaction.customId === "ping") { + interaction.respond({ type: InteractionResponseTypes.ChannelMessageWithSource, data: { content: "pong!" }, }); } }); -await session.start(); +session.start(); diff --git a/examples/hello-bun/index.js b/examples/hello-bun/index.js index f575a3a..bdfd117 100644 --- a/examples/hello-bun/index.js +++ b/examples/hello-bun/index.js @@ -3,7 +3,8 @@ * this example should work on most systems, but if it doesn't just clone the library and import everything from mod.ts */ -import { GatewayIntents, Session } from "@oasisjs/biscuit"; +const { GatewayIntents, Session } = require("@oasisjs/biscuit"); + // if it didn't worked use: // const { GatewayIntents, Session } = require("@oasisjs/biscuit"); @@ -16,15 +17,17 @@ session.on("ready", (payload) => { }); session.on("messageCreate", async (message) => { + // GET if (message.content.startsWith("whatever")) { - const whatever = await message.fetch().then(console.log); + const whatever = await message.fetch(); console.log(whatever); } + // POST if (message.content.startsWith("ping")) { message.reply({ content: "pong!" }).catch((err) => console.error(err)); } }); await session.start(); - \ No newline at end of file + diff --git a/examples/hello-deno/mod.ts b/examples/hello-deno/mod.ts index e247c3f..e05f293 100644 --- a/examples/hello-deno/mod.ts +++ b/examples/hello-deno/mod.ts @@ -1,11 +1,11 @@ /** * Deno example -*/ + */ import "https://deno.land/std@0.146.0/dotenv/load.ts"; -// Session for create a new bot and intents -import { GatewayIntents, Session } from "https://x.nest.land/biscuit@0.1.0/mod.ts"; +// Session to create a new bot (and intents) +import { GatewayIntents, Session } from "https://x.nest.land/biscuit/mod.ts"; const token = Deno.env.get("TOKEN") ?? Deno.args[0]; @@ -35,5 +35,5 @@ session.on("messageCreate", (message) => { } }); -await session.start(); - \ No newline at end of file +session.start(); + diff --git a/examples/node.js b/examples/node.js deleted file mode 100644 index aedac40..0000000 --- a/examples/node.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Biscuit node example -*/ - -/** @type {NodeJS.Process} process */ -const process = require("node:process"); -const { Session, GatewayIntents } = require("@oasisjs/biscuit"); - -/** @type {string} token */ -const token = process.env.TOKEN || "YOUR_TOKEN_HERE"; - -if (token === "") { - return new Error("Please set the TOKEN environment variable"); -} - -const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; -const session = new Session({ token, intents }); -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)) { - return; - } - - const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); - const name = args.shift()?.toLowerCase(); - - if (name === "ping") { - message.reply({ content: "pong!" }); - } -}); - -try { - session.start(); -} catch(err){ - throw err; -} \ No newline at end of file diff --git a/examples/nodemodules.mjs b/examples/nodemodules.mjs deleted file mode 100644 index f566931..0000000 --- a/examples/nodemodules.mjs +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Biscuit node example -*/ - -/** @type {NodeJS.Process} process */ -import process from 'node:process'; -import { Session, GatewayIntents } from '@oasisjs/biscuit'; - -/** @type {string} token */ -const token = process.env.TOKEN || "YOUR_TOKEN_HERE"; - -if (token === "") { - console.log(new Error("Please set the TOKEN environment variable")); -} - -const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; -const session = new Session({ token, intents }); -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)) { - return; - } - - const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); - const name = args.shift()?.toLowerCase(); - - if (name === "ping") { - message.reply({ content: "pong!" }); - } -}); - -try { - session.start(); -} catch(err){ - throw err; -} \ No newline at end of file diff --git a/examples/slash-commands/mod.ts b/examples/slash-commands/mod.ts index 8f52ab0..294d7db 100644 --- a/examples/slash-commands/mod.ts +++ b/examples/slash-commands/mod.ts @@ -1,5 +1,5 @@ import "https://deno.land/std@0.146.0/dotenv/load.ts"; -import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "./deps.ts"; +import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session } from "https://x.nest.land/biscuit/mod.ts"; const token = Deno.env.get("TOKEN") ?? Deno.args[0];