init
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
||||
node_modules
|
||||
lib
|
||||
examples/*.js
|
||||
lib
|
||||
1
examples/index.d.ts
vendored
1
examples/index.d.ts
vendored
@@ -1 +0,0 @@
|
||||
declare const TOKEN: string;
|
||||
@@ -1,72 +0,0 @@
|
||||
import { Client, CommandInteraction, Intents } from 'discord.js';
|
||||
import { addCommand, CommandGenerator, CommandOptionGenerator, initClient } from '../lib/main';
|
||||
|
||||
const EightBallAnswers = [
|
||||
'It is certain',
|
||||
'It is decidedly so',
|
||||
'Without a doubt',
|
||||
'Yes - definitely',
|
||||
'You may rely on it',
|
||||
'As I see it, yes',
|
||||
'Most likely',
|
||||
'Outlook good',
|
||||
'Yes',
|
||||
'Signs point to yes',
|
||||
'Don\'t count on it',
|
||||
'My reply is no',
|
||||
'My sources say no',
|
||||
'Outlook not so good',
|
||||
'Very doubtful',
|
||||
'Reply hazy, try again',
|
||||
'Ask again later',
|
||||
'Better not tell you now',
|
||||
'Cannot predict now',
|
||||
'Concentrate and ask again'
|
||||
];
|
||||
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
|
||||
initClient(client);
|
||||
|
||||
addCommand([
|
||||
new CommandGenerator()
|
||||
.setName('ping')
|
||||
.setDescription('ping me')
|
||||
.setRun((interaction: CommandInteraction) =>
|
||||
interaction.reply('pong')),
|
||||
|
||||
new CommandGenerator()
|
||||
.setName('8ball')
|
||||
.setDescription('ask the magic 8ball a question')
|
||||
//.addOption('question', 'string', 'question to ask the 8ball') //will add something like this later
|
||||
.addOption([
|
||||
|
||||
new CommandOptionGenerator()
|
||||
.setName('question')
|
||||
.setType('string')
|
||||
.setDescription('question to ask the 8ball')
|
||||
.setRequired()
|
||||
|
||||
])
|
||||
.setRun(EightBall)
|
||||
]);
|
||||
|
||||
function EightBall(interaction: CommandInteraction) {
|
||||
|
||||
let question = interaction.options.get('question', true).value,
|
||||
answer = EightBallAnswers[Math.floor(Math.random() * EightBallAnswers.length)];
|
||||
|
||||
if (typeof question === 'string') {
|
||||
|
||||
if (!question.endsWith('?'))
|
||||
question += '?';
|
||||
|
||||
interaction.reply(`\`${question}\` ${answer}`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
client.on('ready', client => console.log(`Ready ${client.user.tag}`));
|
||||
|
||||
client.login(TOKEN);
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
11
package.json
11
package.json
@@ -1,18 +1,17 @@
|
||||
{
|
||||
"name": "discordslash",
|
||||
"name": "lang",
|
||||
"description": "",
|
||||
"version": "1.0.0",
|
||||
"main": "lib/main.js",
|
||||
"types": "lib/main.d.ts",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"buildexamples": "node buildexample.js",
|
||||
"_prepare": "npm run build"
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.zomo.dev:zomo/discordslash.git"
|
||||
"url": "git@git.zomo.dev:zomo/lang.git"
|
||||
},
|
||||
"author": "ashley zomo",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import { MessageEmbed } from 'discord.js';
|
||||
import { template, resolveColor, bigString } from '../main';
|
||||
import { embedObject, basicObjectString, authorData, footerData } from '../types';
|
||||
|
||||
export * from "../main";
|
||||
|
||||
/**
|
||||
* converts embedObj to Discord.MessageEmbed
|
||||
*/
|
||||
export function embedObjEmbed(embedObj: embedObject, args: basicObjectString = {}): MessageEmbed {
|
||||
const embed = new MessageEmbed(),
|
||||
{ author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
||||
|
||||
if (author !== undefined) {
|
||||
|
||||
let authorFix: authorData;
|
||||
|
||||
if (typeof author === 'string')
|
||||
authorFix = {
|
||||
name: template(author, args)
|
||||
};
|
||||
else {
|
||||
|
||||
const {name, iconURL, url} = author;
|
||||
|
||||
authorFix = {
|
||||
name: template(name, args)
|
||||
};
|
||||
|
||||
if (iconURL !== undefined)
|
||||
authorFix.iconURL = template(iconURL, args);
|
||||
|
||||
if (url !== undefined)
|
||||
authorFix.url = template(url, args);
|
||||
|
||||
}
|
||||
|
||||
embed.setAuthor(authorFix);
|
||||
|
||||
}
|
||||
|
||||
if (footer !== undefined) {
|
||||
|
||||
let footerFix: footerData;
|
||||
|
||||
if (typeof footer === 'string') {
|
||||
|
||||
footerFix = {
|
||||
text: template(footer, args)
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
const {text, iconURL} = footer;
|
||||
|
||||
footerFix = {
|
||||
text: template(text, args)
|
||||
};
|
||||
|
||||
if (iconURL !== undefined)
|
||||
footerFix.iconURL = template(iconURL, args);
|
||||
|
||||
}
|
||||
|
||||
embed.setFooter(footerFix);
|
||||
|
||||
}
|
||||
|
||||
if (color !== undefined)
|
||||
embed.setColor(resolveColor(template(color, args)));
|
||||
|
||||
if (description !== undefined)
|
||||
embed.setDescription(template(bigString(description), args));
|
||||
|
||||
if (image !== undefined)
|
||||
embed.setImage(template(image, args));
|
||||
|
||||
if (thumbnail !== undefined)
|
||||
embed.setThumbnail(template(thumbnail, args));
|
||||
|
||||
if (title !== undefined)
|
||||
embed.setTitle(template(title, args));
|
||||
|
||||
if (url !== undefined)
|
||||
embed.setURL(template(url, args));
|
||||
|
||||
if (timestamp === true)
|
||||
embed.setTimestamp();
|
||||
else if (typeof timestamp === 'string')
|
||||
embed.setTimestamp(new Date(template(timestamp, args)));
|
||||
else if (timestamp !== false)
|
||||
embed.setTimestamp(timestamp);
|
||||
|
||||
fields?.forEach(field => {
|
||||
embed.addField(template(field.name, args), template(bigString(field.value), args), field.inline);
|
||||
});
|
||||
|
||||
return embed;
|
||||
}
|
||||
Reference in New Issue
Block a user