mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
Update examples
This commit is contained in:
parent
af73561279
commit
9193346f52
@ -1,57 +1,57 @@
|
|||||||
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
import 'https://deno.land/std@0.146.0/dotenv/load.ts';
|
||||||
import {
|
import {
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
ButtonBuilder,
|
ButtonBuilder,
|
||||||
ButtonStyles,
|
ButtonStyles,
|
||||||
ComponentInteraction,
|
ComponentInteraction,
|
||||||
GatewayIntents,
|
GatewayIntents,
|
||||||
InteractionResponseTypes,
|
InteractionResponseTypes,
|
||||||
Session,
|
Session,
|
||||||
} from "./deps.ts";
|
} from 'https://x.nest.land/biscuit@0.1.0/mod.ts';
|
||||||
|
|
||||||
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
||||||
|
|
||||||
if (!token) {
|
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 intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
const session = new Session({ token, intents });
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
const PREFIX = ">";
|
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();
|
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(components).toJSON();
|
||||||
|
|
||||||
session.on("ready", (payload) => {
|
session.on('ready', (payload) => {
|
||||||
console.log("Logged in as:", payload.user.username);
|
console.log('Logged in as:', payload.user.username);
|
||||||
});
|
});
|
||||||
|
|
||||||
session.on("messageCreate", (message) => {
|
session.on("messageCreate", (message) => {
|
||||||
if (message.author?.bot || !message.content.startsWith(PREFIX)) {
|
if (message.author?.bot || !message.content.startsWith(PREFIX)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm);
|
const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm);
|
||||||
const name = args.shift()?.toLowerCase();
|
const name = args.shift()?.toLowerCase();
|
||||||
console.log(args, name);
|
console.log(args, name);
|
||||||
|
|
||||||
if (name === "ping") {
|
if (name === 'ping') {
|
||||||
message.reply({ components: [row] })
|
message.reply({ components: [row] })
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((e) => console.error(e));
|
.catch((e) => console.error(e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Follow interaction event
|
// Follow interaction event
|
||||||
session.on("interactionCreate", (interaction) => {
|
session.on('interactionCreate', (interaction) => {
|
||||||
if (!interaction.isComponent()) return;
|
if (!interaction.isComponent()) return;
|
||||||
const component = interaction as ComponentInteraction;
|
const component = interaction as ComponentInteraction;
|
||||||
if (component.customId == "ping") {
|
if (component.customId == "ping") {
|
||||||
component.respond({
|
component.respond({
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: { content: "pong!" },
|
data: { content: "pong!" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await session.start();
|
await session.start();
|
@ -1,34 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* Bun example
|
* Bun example
|
||||||
* this example should work on most systems, but if it doesn't just clone the library and import everything from mod.ts
|
* 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";
|
import { GatewayIntents, Session } from "@oasisjs/biscuit";
|
||||||
// if it didn't worked use:
|
// if it didn't worked use:
|
||||||
// const { GatewayIntents, Session } = require("@oasisjs/biscuit");
|
// const { GatewayIntents, Session } = require("@oasisjs/biscuit");
|
||||||
|
|
||||||
const token = process.env.TOKEN;
|
const token = process.env.TOKEN;
|
||||||
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
const session = new Session({ token, intents });
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
// uncomment to debug stuff
|
session.on("ready", (payload) => {
|
||||||
// session.on("debug", (any) => {
|
console.log("Logged in as:", payload.user.username);
|
||||||
// console.debug(any);
|
});
|
||||||
// })
|
|
||||||
|
session.on("messageCreate", async (message) => {
|
||||||
session.on("ready", (payload) => {
|
if (message.content.startsWith("whatever")) {
|
||||||
console.log("Logged in as:", payload.user.username);
|
const whatever = await message.fetch().then(console.log);
|
||||||
});
|
console.log(whatever);
|
||||||
|
}
|
||||||
session.on("messageCreate", async (message) => {
|
|
||||||
if (message.content.startsWith("whatever")) {
|
if (message.content.startsWith("ping")) {
|
||||||
const whatever = await message.fetch().then(console.log);
|
message.reply({ content: "pong!" }).catch((err) => console.error(err));
|
||||||
console.log(whatever);
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
if (message.content.startsWith("ping")) {
|
await session.start();
|
||||||
message.reply({ content: "pong!" }).catch((err) => console.error(err));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await session.start();
|
|
@ -1,36 +1,39 @@
|
|||||||
/**
|
/**
|
||||||
* Deno example
|
* Deno example
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
||||||
import { GatewayIntents, Session } from "https://x.nest.land/biscuit@0.1.0/mod.ts";
|
|
||||||
|
// Session for create a new bot and intents
|
||||||
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
import { GatewayIntents, Session } from "https://x.nest.land/biscuit@0.1.0/mod.ts";
|
||||||
|
|
||||||
if (!token) {
|
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
||||||
throw new Error("Please provide a token");
|
|
||||||
}
|
if (!token) {
|
||||||
|
throw new Error("Please provide a token");
|
||||||
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
}
|
||||||
const session = new Session({ token, intents });
|
|
||||||
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
session.on("ready", (payload) => {
|
const session = new Session({ token, intents });
|
||||||
console.log("Logged in as:", payload.user.username);
|
|
||||||
});
|
session.on("ready", (payload) => {
|
||||||
|
console.log("Logged in as:", payload.user.username);
|
||||||
const PREFIX = ">";
|
});
|
||||||
|
|
||||||
session.on("messageCreate", (message) => {
|
const PREFIX = ">";
|
||||||
if (message.author?.bot || !message.content.startsWith(PREFIX)) {
|
|
||||||
return;
|
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();
|
|
||||||
|
const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm);
|
||||||
if (name === "ping") {
|
const name = args.shift()?.toLowerCase();
|
||||||
message.reply({ content: "pong!" });
|
|
||||||
}
|
if (name === "ping") {
|
||||||
});
|
message.reply({ content: "pong!" });
|
||||||
|
}
|
||||||
await session.start();
|
});
|
||||||
|
|
||||||
|
await session.start();
|
||||||
|
|
@ -2,10 +2,14 @@
|
|||||||
* Biscuit node example
|
* Biscuit node example
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// process for get the token
|
||||||
/** @type {NodeJS.Process} process */
|
/** @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 { Session, GatewayIntents } from '@oasisjs/biscuit';
|
||||||
|
|
||||||
|
// Discord bot token
|
||||||
/** @type {string} token */
|
/** @type {string} token */
|
||||||
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
|
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
|
||||||
|
|
||||||
@ -15,6 +19,8 @@ if (token === "") {
|
|||||||
|
|
||||||
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
const session = new Session({ token, intents });
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
|
// Command prefix
|
||||||
const PREFIX = ">";
|
const PREFIX = ">";
|
||||||
|
|
||||||
session.on("ready", (data) => {
|
session.on("ready", (data) => {
|
||||||
@ -35,8 +41,4 @@ session.on("messageCreate", (message) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
session.start();
|
||||||
session.start();
|
|
||||||
} catch(err){
|
|
||||||
throw err;
|
|
||||||
}
|
|
@ -2,10 +2,14 @@
|
|||||||
* Biscuit node example
|
* Biscuit node example
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// process for get the token
|
||||||
/** @type {NodeJS.Process} process */
|
/** @type {NodeJS.Process} process */
|
||||||
const process = require("node:process");
|
const process = require("node:process");
|
||||||
|
|
||||||
|
// Session for create a new bot and intents
|
||||||
const { Session, GatewayIntents } = require("@oasisjs/biscuit");
|
const { Session, GatewayIntents } = require("@oasisjs/biscuit");
|
||||||
|
|
||||||
|
// Discord bot token
|
||||||
/** @type {string} token */
|
/** @type {string} token */
|
||||||
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
|
const token = process.env.TOKEN || "YOUR_TOKEN_HERE";
|
||||||
|
|
||||||
@ -15,6 +19,8 @@ if (token === "") {
|
|||||||
|
|
||||||
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
const session = new Session({ token, intents });
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
|
// Command prefix
|
||||||
const PREFIX = ">";
|
const PREFIX = ">";
|
||||||
|
|
||||||
session.on("ready", (data) => {
|
session.on("ready", (data) => {
|
||||||
@ -35,8 +41,4 @@ session.on("messageCreate", (message) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
session.start();
|
||||||
session.start();
|
|
||||||
} catch(err){
|
|
||||||
throw err;
|
|
||||||
}
|
|
@ -1,43 +1,43 @@
|
|||||||
import "https://deno.land/std@0.146.0/dotenv/load.ts";
|
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 "./deps.ts";
|
||||||
|
|
||||||
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
const token = Deno.env.get("TOKEN") ?? Deno.args[0];
|
||||||
|
|
||||||
if (!token) {
|
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 intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||||
const session = new Session({ token, intents });
|
const session = new Session({ token, intents });
|
||||||
|
|
||||||
const command: CreateApplicationCommand = {
|
const command: CreateApplicationCommand = {
|
||||||
name: "ping",
|
name: "ping",
|
||||||
description: "Replies with pong!",
|
description: "Replies with pong!",
|
||||||
};
|
};
|
||||||
|
|
||||||
const guildId = "";
|
const guildId = "";
|
||||||
|
|
||||||
session.on("ready", async (payload) => {
|
session.on("ready", async (payload) => {
|
||||||
console.log("Logged in as:", payload.user.username);
|
console.log("Logged in as:", payload.user.username);
|
||||||
console.log("Creating the application commands...");
|
console.log("Creating the application commands...");
|
||||||
// create command
|
// create command
|
||||||
try {
|
try {
|
||||||
await session.createApplicationCommand(command, guildId);
|
await session.createApplicationCommand(command, guildId);
|
||||||
console.log("Done!");
|
console.log("Done!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Follow interaction event
|
// Follow interaction event
|
||||||
session.on("interactionCreate", (interaction) => {
|
session.on("interactionCreate", (interaction) => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
if (interaction.commandName === "ping") {
|
if (interaction.commandName === "ping") {
|
||||||
interaction.respond({
|
interaction.respond({
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: { content: "pong!" },
|
data: { content: "pong!" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await session.start();
|
await session.start();
|
Loading…
x
Reference in New Issue
Block a user