mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
starting a huge rewrite
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
// Here we are defining what we want the interface to look like so that there is a goal to work towards
|
||||
// Things here are not necessarily implemented in the actual code but show what we want it to look like to use the library
|
||||
|
||||
// import { unicord, t } from 'unicord';
|
||||
import { Expectation, Unicord, UnicordArgumentType } from '../rewrite/index.ts';
|
||||
|
||||
const DISCORD_CLIENT_TOKEN = process.env.BOT_TOKEN!;
|
||||
|
||||
// Create a new client instance
|
||||
// Most usage will be via chaining methods off the client instance
|
||||
const client = new Unicord({
|
||||
token: process.env.BOT_TOKEN!,
|
||||
})
|
||||
.registerChatCommand(
|
||||
'ping',
|
||||
async (context, args) => {
|
||||
let response = 'Pong!';
|
||||
response += ` Hello, ${args.name}!`;
|
||||
if (!!args.age && args.age > 0) {
|
||||
response += ` Happy to hear you are ${args.age} years old.`;
|
||||
}
|
||||
await context.reply(response);
|
||||
},
|
||||
{
|
||||
description: 'Ping command',
|
||||
args: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'Your name',
|
||||
// Maybe we can use t.String() here but only certain types are valid for command options
|
||||
// But in theory we could parse the raw value and attempt convert it to requested type here
|
||||
type: UnicordArgumentType.String,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'age',
|
||||
description: 'Your age',
|
||||
type: UnicordArgumentType.Number,
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
.registerChatCommand(
|
||||
'channel',
|
||||
async (context) => {
|
||||
const hydrated = await context.hydrate(context, [Expectation.Channel]);
|
||||
await context.reply(hydrated.channel.name ?? 'Unnamed Channel');
|
||||
},
|
||||
{
|
||||
description: 'Channel command',
|
||||
args: [],
|
||||
},
|
||||
)
|
||||
.registerApplicationCommand(
|
||||
'echo',
|
||||
async (context, args) => {
|
||||
await context.reply('Echo! ' + args.text);
|
||||
},
|
||||
{
|
||||
description: 'Echo command',
|
||||
args: [
|
||||
{
|
||||
name: 'text',
|
||||
description: 'Text to echo',
|
||||
type: UnicordArgumentType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
.onEvent('READY', async (payload) => {
|
||||
console.log(`Logged in as ${payload.user.username}`);
|
||||
});
|
||||
|
||||
client.login(DISCORD_CLIENT_TOKEN);
|
||||
|
||||
// Allow use of "child" instances inside parent instance
|
||||
// const client2 = new Unicord().chatCommand('ping', async (context, _) => {
|
||||
// await context.reply('Pong!');
|
||||
// });
|
||||
|
||||
// new Unicord().use(client2).login(DISCORD_CLIENT_TOKEN);
|
||||
Reference in New Issue
Block a user