Commit f4ac55ef authored by Rasmus Bengtsson's avatar Rasmus Bengtsson
Browse files

finally working

parent b79ecf6f
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Main = void 0;
require("reflect-metadata");
const discordx_1 = require("discordx");
const discord_js_1 = require("discord.js");
// Use the Client that are provided by @typeit/discord NOT discord.js
const discord_1 = require("@typeit/discord");
async function start() {
const client = new discord_1.Client({
intents: [
discord_js_1.Intents.FLAGS.GUILDS,
discord_js_1.Intents.FLAGS.GUILD_MESSAGES,
],
classes: [
`${__dirname}/*Discord.ts`,
`${__dirname}/*Discord.js`, // If you compile using "tsc" the file extension change to .js
],
silent: false,
});
client.once("ready", async () => {
await client.clearSlashes();
await client.initSlashes();
});
client.on("interaction", (interaction) => {
console.log("an interaction has happened");
client.executeSlash(interaction);
});
await client.login("ODg2NjYzNDY2OTM5NzM2MTE2.YT43sw.N8AQPqwt5FEG6G5PCuBGE4eXitc");
class Main {
static get Client() {
return this._client;
}
static async start() {
var _a;
this._client = new discordx_1.Client({
intents: [discord_js_1.Intents.FLAGS.GUILDS, discord_js_1.Intents.FLAGS.GUILD_MESSAGES],
classes: [
// glob string to load the classes. If you compile your bot, the file extension will be .js
`${__dirname}/*.Discord.{js,ts}`,
],
requiredByDefault: true,
});
// In the login method, you must specify the glob string to load your classes (for the framework).
// In this case that's not necessary because the entry point of your application is this file.
await this._client.login((_a = process.env.BOT_TOKEN) !== null && _a !== void 0 ? _a : "ODg2NjYzNDY2OTM5NzM2MTE2.YT43sw.N8AQPqwt5FEG6G5PCuBGE4eXitc");
this._client.once("ready", async () => {
await this._client.initApplicationCommands();
console.log("Bot started");
});
this._client.on("interactionCreate", (interaction) => {
this._client.executeInteraction(interaction);
});
}
}
start();
exports.Main = Main;
Main.start();
//# sourceMappingURL=main.js.map
\ No newline at end of file
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,4BAA0B;AAC1B,2CAAqC;AACrC,qEAAqE;AACrE,6C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IAAI;SACxB,CAAC,CAAC;QAEH,kGAAkG;QAClG,8FAA8F;QAC9F,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,SAAS,mCAAI,6DAA6D,CAAC,CAAC;QAEjH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;YACpC,MAAM,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;YAE7C,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,WAAW,EAAE,EAAE;YACnD,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/BD,oBA+BC;AAED,IAAI,CAAC,KAAK,EAAE,CAAC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const discord_1 = require("@typeit/discord");
const discordx_1 = require("discordx");
const discord_js_1 = require("discord.js");
let PingBot = class PingBot {
ping(interaction) {
......@@ -12,13 +12,12 @@ let PingBot = class PingBot {
}
};
(0, tslib_1.__decorate)([
(0, discord_1.Slash)("ping"),
(0, discord_1.Description)("Ping Pong!"),
(0, discordx_1.Slash)("ping"),
(0, tslib_1.__metadata)("design:type", Function),
(0, tslib_1.__metadata)("design:paramtypes", [discord_js_1.CommandInteraction]),
(0, tslib_1.__metadata)("design:returntype", void 0)
], PingBot.prototype, "ping", null);
PingBot = (0, tslib_1.__decorate)([
(0, discord_1.Discord)()
(0, discordx_1.Discord)()
], PingBot);
//# sourceMappingURL=ping.Discord.js.map
\ No newline at end of file
{"version":3,"file":"ping.Discord.js","sourceRoot":"","sources":["../src/ping.Discord.ts"],"names":[],"mappings":";;;AAAA,6CAAsE;AACtE,2CAA+C;AAG/C,IAAe,OAAO,GAAtB,MAAe,OAAO;IAIV,IAAI,CACR,WAA+B;QAE/B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC9B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QAC/B,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC3B,CAAC;CACJ,CAAA;AARG;IAFC,IAAA,eAAK,EAAC,MAAM,CAAC;IACb,IAAA,qBAAW,EAAC,YAAY,CAAC;;kDAET,+BAAkB;;mCAMlC;AAXU,OAAO;IADrB,IAAA,iBAAO,GAAE;GACK,OAAO,CAYrB"}
\ No newline at end of file
{"version":3,"file":"ping.Discord.js","sourceRoot":"","sources":["../src/ping.Discord.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAC1C,2CAA+C;AAG/C,IAAe,OAAO,GAAtB,MAAe,OAAO;IAGlB,IAAI,CACA,WAA+B;QAE/B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC9B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QAC/B,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC3B,CAAC;CACJ,CAAA;AARG;IADC,IAAA,gBAAK,EAAC,MAAM,CAAC;;kDAEG,+BAAkB;;mCAMlC;AAVU,OAAO;IADrB,IAAA,kBAAO,GAAE;GACK,OAAO,CAWrB"}
\ No newline at end of file
......@@ -6,9 +6,9 @@
"flags": [],
"linkedModules": [],
"topLevelPatterns": [
"@typeit/discord@slash@^5.0.13",
"@types/node@^16.9.1",
"discord.js@https://github.com/discordjs/discord.js",
"discordx@^5.0.13",
"reflect-metadata@^0.1.13",
"tslib@^2.3.1",
"typescript@^4.4.3"
......@@ -19,7 +19,6 @@
"@discordjs/form-data@^3.0.1": "https://registry.yarnpkg.com/@discordjs/form-data/-/form-data-3.0.1.tgz#5c9e6be992e2e57d0dfa0e39979a850225fb4697",
"@sapphire/async-queue@^1.1.4": "https://registry.yarnpkg.com/@sapphire/async-queue/-/async-queue-1.1.4.tgz#ae431310917a8880961cebe8e59df6ffa40f2957",
"@sindresorhus/is@^4.0.1": "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.1.0.tgz#3853c0c48b47f0ebcdd3cd9a66fdd0d277173e78",
"@typeit/discord@slash@^5.0.13": "https://registry.yarnpkg.com/@typeit/discord/-/discord-5.0.13.tgz#a4cf6c1c4e8d3adddb23eba16b8adc8f5659dafd",
"@types/node@*": "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708",
"@types/node@^16.9.1": "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708",
"@types/ws@^7.4.7": "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702",
......@@ -30,10 +29,10 @@
"combined-stream@^1.0.8": "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f",
"concat-map@0.0.1": "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b",
"delayed-stream@~1.0.0": "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619",
"discord-api-types@^0.18.1": "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.18.1.tgz#5d08ed1263236be9c21a22065d0e6b51f790f492",
"discord-api-types@^0.22.0": "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.22.0.tgz#34dc57fe8e016e5eaac5e393646cd42a7e1ccc2a",
"discord.js@github:discordjs/discord.js": "https://codeload.github.com/discordjs/discord.js/tar.gz/be8912a4219d1c1aa59a8060707973e567b7b5a3",
"discord.js@^13.1.0": "https://registry.yarnpkg.com/discord.js/-/discord.js-13.1.0.tgz#99f6a2a8be88d31906ff0148e9b1cb603ebb2e2e",
"discord.js@https://github.com/discordjs/discord.js": "https://github.com/discordjs/discord.js#be8912a4219d1c1aa59a8060707973e567b7b5a3",
"discordx@^5.0.13": "https://registry.yarnpkg.com/discordx/-/discordx-5.8.2.tgz#3cd35a55bce223cd6c5b25158119578a2dc6f5c0",
"dot-prop@^6.0.1": "https://registry.yarnpkg.com/dot-prop/-/dot-prop-6.0.1.tgz#fc26b3cf142b9e59b74dbd39ed66ce620c681083",
"fs.realpath@^1.0.0": "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f",
"glob@^7.1.7": "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90",
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const discord_js_1 = require("discord.js");
const Glob = require("glob");
const _1 = require(".");
const errors_1 = require("./errors");
class Client extends discord_js_1.Client {
/**
* Create your bot
* @param options { silent: boolean, loadClasses: LoadClass[] }
*/
constructor(options) {
super(options);
this._loadClasses = [];
this._silent = !!(options === null || options === void 0 ? void 0 : options.silent);
this._loadClasses = (options === null || options === void 0 ? void 0 : options.classes) || [];
this.guards = options.guards || [];
this.requiredByDefault = options.requiredByDefault;
this.slashGuilds = options.slashGuilds || [];
}
static get slashGuilds() {
return Client._slashGuilds;
}
static set slashGuilds(value) {
Client._slashGuilds = value;
}
get slashGuilds() {
return Client._slashGuilds;
}
set slashGuilds(value) {
Client._slashGuilds = value;
}
static get requiredByDefault() {
return Client._requiredByDefault;
}
static set requiredByDefault(value) {
Client._requiredByDefault = value;
}
get requiredByDefault() {
return Client._requiredByDefault;
}
set requiredByDefault(value) {
Client._requiredByDefault = value;
}
static get guards() {
return Client._guards;
}
static set guards(value) {
Client._guards = value;
}
get guards() {
return Client.guards;
}
set guards(value) {
Client._guards = value;
}
static get slashes() {
return _1.MetadataStorage.instance.slashes;
}
get slashes() {
return Client.slashes;
}
static get allSlashes() {
return _1.MetadataStorage.instance.allSlashes;
}
get allSlashes() {
return Client.allSlashes;
}
static get events() {
return _1.MetadataStorage.instance.events;
}
get events() {
return Client.events;
}
static get discords() {
return _1.MetadataStorage.instance.discords;
}
get discord() {
return Client.discords;
}
static get decorators() {
return _1.MetadataStorage.instance;
}
get decorators() {
return _1.MetadataStorage.instance;
}
get silent() {
return this._silent;
}
set silent(value) {
this._silent = value;
}
/**
* Start your bot
* @param token The bot token
* @param loadClasses A list of glob path or classes
*/
async login(token, ...loadClasses) {
if (loadClasses.length > 0) {
this._loadClasses = loadClasses;
}
await this.build();
if (!this.silent) {
console.log("Events");
if (this.events.length > 0) {
this.events.map((event) => {
const eventName = event.event;
console.log(` ${eventName} (${event.classRef.name}.${event.key})`);
});
}
else {
console.log(" No events detected");
}
console.log("");
console.log("Slashes");
if (this.slashes.length > 0) {
this.slashes.map((slash) => {
console.log(` ${slash.name} (${slash.classRef.name}.${slash.key})`);
const printOptions = (options, depth) => {
if (!options)
return;
const tab = Array(depth).join(" ");
options.map((option) => {
console.log(`${tab}${option.name}: ${option.stringType} (${option.classRef.name}.${option.key})`);
printOptions(option.options, depth + 1);
});
};
printOptions(slash.options, 2);
console.log("");
});
}
else {
console.log(" No slashes detected");
}
}
this.decorators.usedEvents.map(async (on) => {
if (on.once) {
this.once(on.event, this.decorators.trigger(on.event, this, true));
}
else {
this.on(on.event, this.decorators.trigger(on.event, this));
}
});
return await super.login(token);
}
/**
* Initialize all the @Slash with their permissions
*/
async initSlashes() {
await Promise.all(this.slashes.map(async (slash) => {
// Init all the @Slash
if (slash.guilds.length > 0) {
// If the @Slash is guild specific, add it to the guild
await Promise.all(slash.guilds.map(async (guildID) => {
const guild = this.guilds.cache.get(guildID);
if (!guild) {
throw new errors_1.GuildNotFoundError(guildID);
}
const commands = guild.commands;
const command = await commands.create(slash.toObject());
if (slash.permissions.length <= 0)
return;
await commands.setPermissions(command, slash.getPermissions());
}));
}
else {
// If the @Slash is global, add it globaly
const commands = this.application.commands;
const command = await commands.create(slash.toObject());
// Only available for Guilds
// https://discord.js.org/#/docs/main/master/class/ApplicationCommand?scrollTo=setPermissions
// if (slash.permissions.length <= 0) return;
// await commands.setPermissions(command, slash.getPermissions());
}
}));
}
/**
* Fetch the existing slash commands of a guild or globaly
* @param guild The guild ID (empty -> globaly)
* @returns The existing commands
*/
async fetchSlash(guildID) {
if (guildID) {
const guild = this.guilds.cache.get(guildID);
if (!guild) {
throw new errors_1.GuildNotFoundError(guildID);
}
return await guild.commands.fetch();
}
return await this.application.commands.fetch();
}
/**
* Clear the Slash commands globaly or for some guilds
* @param guilds The guild IDs (empty -> globaly)
*/
async clearSlashes(...guilds) {
if (guilds.length > 0) {
await Promise.all(guilds.map(async (guild) => {
// Select and delete the commands of each guild
const commands = await this.fetchSlash(guild);
await Promise.all(commands.map(async (value) => {
await this.guilds.cache.get(guild).commands.delete(value);
}));
}));
}
else {
// Select and delete the commands of each guild
const commands = await this.fetchSlash();
await Promise.all(commands.map(async (value) => {
await this.application.commands.delete(value);
}));
}
}
/**
* Get the group tree of an interaction
* /hello => ["hello"]
* /test hello => ["test", "hello"]
* /test hello me => ["test", "hello", "me"]
* @param interaction The targeted interaction
* @returns The group tree
*/
getInteractionGroupTree(interaction) {
const tree = [];
const getOptionsTree = (option) => {
var _a, _b;
if (!option)
return;
if (!option.type ||
option.type === "SUB_COMMAND_GROUP" ||
option.type === "SUB_COMMAND") {
tree.push(option.name);
return getOptionsTree((_b = Array.from(((_a = option.options) === null || _a === void 0 ? void 0 : _a.values()) || [])) === null || _b === void 0 ? void 0 : _b[0]);
}
};
getOptionsTree({
name: interaction.commandName,
options: interaction.options,
type: undefined
});
return tree;
}
/**
* Return the corresponding @Slash from a tree
* @param tree
* @returns The corresponding Slash
*/
getSlashFromTree(tree) {
// Find the corresponding @Slash
return this.allSlashes.find((slash) => {
switch (tree.length) {
case 1:
// Simple command /hello
return (slash.group === undefined &&
slash.subgroup === undefined &&
slash.name === tree[0]);
case 2:
// Simple grouped command
// /permission user perm
return (slash.group === tree[0] &&
slash.subgroup === undefined &&
slash.name === tree[1]);
case 3:
// Grouped and subgroupped command
// /permission user perm
return (slash.group === tree[0] &&
slash.subgroup === tree[1] &&
slash.name === tree[2]);
}
});
}
/**
* Execute the corresponding @Slash command based on an Interaction instance
* @param interaction The discord.js interaction instance
* @returns void
*/
async executeSlash(interaction) {
if (!interaction) {
if (!this.silent) {
console.log("Interaction is undefined");
}
return;
}
// If the interaction isn't a slash command, return
if (!interaction.isCommand())
return;
// Get the interaction group tree
const tree = this.getInteractionGroupTree(interaction);
const slash = this.getSlashFromTree(tree);
if (!slash)
return;
// Parse the options values and inject it into the @Slash method
return await slash.execute(interaction, this);
}
/**
* Manually build the app
*/
async build() {
this.loadClasses();
await this.decorators.build();
}
/**
* Manually trigger an event (used for tests)
* @param event The event
* @param params Params to inject
* @param once Trigger an once event
*/
trigger(event, params, once = false) {
return this.decorators.trigger(event, this, once)(params);
}
loadClasses() {
if (!this._loadClasses) {
return;
}
this._loadClasses.map((file) => {
if (typeof file === "string") {
const files = Glob.sync(file);
files.map((file) => {
require(file);
});
}
});
}
}
exports.Client = Client;
Client._requiredByDefault = false;
Client._slashGuilds = [];
Client._guards = [];
//# sourceMappingURL=Client.js.map
\ No newline at end of file
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;;AAAA,2CAQoB;AACpB,6BAA6B;AAC7B,wBAOW;AAEX,qCAA8C;AAE9C,MAAa,MAAO,SAAQ,mBAAQ;IAwFlC;;;OAGG;IACH,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QA3FT,iBAAY,GAAgB,EAAE,CAAC;QA6FrC,IAAI,CAAC,OAAO,GAAG,C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a,EAAE,CAAC;AAC5B,cAAO,GAAoB,EAAE,CAAC"}
\ No newline at end of file
<p align="center">
<br/>
<img src="https://i.imgur.com/kSLOEIF.png" width="150px">
<br/>
<br/>
<h1 align="center">
<p align="center">
discord.ts (@typeit/discord)
</p>
</h1>
<p align="center">
<b>
Create your discord bot by using TypeScript and decorators!
</b>
<p>
</p>
<br/>
</p>
# 🎻 Introduction
This module is an extension of **[discord.**js**](https://discordjs.guide/)**, so the internal behavior (methods, properties, ...) is the same.
This library allows you to use TypeScript decorators on discord.**js**, it simplify your code and improve the readability !
# 📜 Documentation
**[https://owencalvin.github.io/discord.ts/](https://owencalvin.github.io/discord.ts/)**
# 📟 @Slash - Discord commands
Discord has it's own command system now, you can simply declare commands and use Slash commands this way
```ts
import { Discord, Slash } from "@typeit/discord";
import { CommandInteraction } from "discord.js";
@Discord()
abstract class AppDiscord {
@Slash("hello")
private hello(
@Option("text")
text: string,
interaction: CommandInteraction
) {
// ...
}
}
```
## Decorators related to Slash commands
There is a whole system that allows you to implement complex Slash commands
- `@Choice`
- `@Choices`
- `@Option`
- `@Permission`
- `@Guild`
- `@Group`
- `@Description`
- `@Guard`
# 💡@On / @Once - Discord events
We can declare methods that will be executed whenever a Discord event is triggered.
Our methods must be decorated with the `@On(event: string)` or `@Once(event: string)` decorator.
That's simple, when the event is triggered, the method is called:
```typescript
import { Discord, On, Once } from "@typeit/discord";
@Discord()
abstract class AppDiscord {
@On("message")
private onMessage() {
// ...
}
@Once("messageDelete")
private onMessageDelete() {
// ...
}
}
```
# ⚔️ Guards
We implemented a guard system thats work pretty like the [Koa](https://koajs.com/) middleware system
You can use functions that are executed before your event to determine if it's executed. For example, if you want to apply a prefix to the messages, you can simply use the `@Guard` decorator.
The order of execution of the guards is done according to their position in the list, so they will be executed in order (from top to bottom).
Guards can be set for `@Slash`, `@On`, `@Once`, `@Discord` and globaly.
```typescript
import { Discord, On, Client, Guard } from "@typeit/discord";
import { NotBot } from "./NotBot";
import { Prefix } from "./Prefix";
@Discord()
abstract class AppDiscord {
@On("message")
@Guard(
NotBot, // You can use multiple guard functions, they are excuted in the same order!
Prefix("!")
)
async onMessage([message]: ArgsOf<"message">) {
switch (message.content.toLowerCase()) {
case "hello":
message.reply("Hello!");
break;
default:
message.reply("Command not found");
break;
}
}
}
```
# 📡 Installation
Use [npm](https://www.npmjs.com/package/@typeit/discord) or yarn to install **@typeit/discord@slash** with **discord.js**
**[Please refer to the documentation](https://owencalvin.github.io/discord.ts/installation/#installation)**
# ☎️ Need help?
**[Simply join the Discord server](https://discord.gg/VDjwu8E)**
You can also find help with the [different projects that use discord.ts](https://github.com/OwenCalvin/discord.ts/network/dependents?package_id=UGFja2FnZS00Njc1MzYwNzU%3D) and in the [examples folder](https://github.com/OwenCalvin/discord.ts/tree/master/examples)