mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
// 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 { Expectation, Unicord, UnicordArgumentType, Intent } from '../rewrite/index.ts';
|
|
|
|
const DISCORD_APPLICATION_ID = process.env.APPLICATION_ID!;
|
|
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({
|
|
intents: [
|
|
Intent.GUILDS,
|
|
Intent.GUILD_MESSAGES,
|
|
Intent.GUILD_MESSAGE_REACTIONS,
|
|
Intent.MESSAGE_CONTENT,
|
|
Intent.DIRECT_MESSAGES,
|
|
Intent.DIRECT_MESSAGE_REACTIONS,
|
|
],
|
|
application_id: DISCORD_APPLICATION_ID,
|
|
token: DISCORD_CLIENT_TOKEN,
|
|
prefix: '!!',
|
|
})
|
|
.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: 'Say hello',
|
|
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: 'Get info about a channel',
|
|
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}`);
|
|
});
|
|
|
|
// Allow use of "child" instances inside parent instance
|
|
const etc = new Unicord().registerChatCommand(
|
|
'zing',
|
|
async (context, args) => {
|
|
await context.reply(`Zing! You got served!` + args.fav_amimal ? ` One ${args.fav_amimal} please!` : '');
|
|
},
|
|
{
|
|
args: [
|
|
{
|
|
name: 'fav_amimal',
|
|
description: 'Your favorite animal',
|
|
type: UnicordArgumentType.String,
|
|
required: false,
|
|
choices: [
|
|
{ name: 'Dog', value: 'dog' },
|
|
{ name: 'Cat', value: 'cat' },
|
|
{ name: 'Hamster', value: 'hamster' },
|
|
{ name: 'Dolphin', value: 'dolphin' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
);
|
|
|
|
// client.use(etc);
|
|
|
|
client.login();
|