Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Fixes and New Features #62

Closed
wants to merge 106 commits into from
Closed
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
8937987
### fix
Jul 1, 2021
c0b39d7
fix github.com/OwenCalvin/discord.ts/pull/56
Jul 1, 2021
a9ad6ee
fix github.com/OwenCalvin/discord.ts/pull/58
Jul 1, 2021
2138b4f
fix github.com/OwenCalvin/discord.ts/pull/60
Jul 1, 2021
9906e10
unused var and decorator fix
Jul 1, 2021
d66fc71
fix https://discord.js.org/#/docs/main/master/class/ApplicationComma…
Jul 1, 2021
4815968
fix no-inferrable-types
Jul 1, 2021
5762d9a
fix type error
Jul 1, 2021
d02a953
## init slash for guilds
Jul 1, 2021
d87ebba
multiple bot support
Jul 1, 2021
029539b
fix github.com/OwenCalvin/discord.ts/issues/49
Jul 1, 2021
d5bf0df
multi bot support
Jul 1, 2021
841d506
fix multiple bot
Jul 1, 2021
26ae1b7
readme
Jul 1, 2021
2e5cb5c
original readme restored
Jul 1, 2021
2b5ab41
fixes based on @AndyClausen suggestion
Jul 1, 2021
0558c4a
* formated code with prettier
Jul 1, 2021
0587f80
strong type checking
Jul 1, 2021
a0aad89
fix empty constructor
Jul 1, 2021
f73bd73
DGroup type fix
Jul 1, 2021
56cf961
ModifyFunction from it's usage
Jul 1, 2021
dcb582b
Client type fix
Jul 2, 2021
6479166
classes code fix
Jul 2, 2021
c234eea
initslash fix
Jul 2, 2021
f81c2c1
multibot events support fix
Jul 2, 2021
7314985
adde log options for initslash
Jul 2, 2021
c43d6c0
init slash fix
Jul 2, 2021
f4ab388
execute slash fix
Jul 2, 2021
3474122
init slash fix
Jul 2, 2021
6a27fd3
* test update
Jul 2, 2021
ee9f472
* recoded classes again
Jul 2, 2021
f3cb42b
jest test passed
Jul 2, 2021
0d01296
multiple bot support fix for groups
Jul 2, 2021
547a04b
added ``Bot()`` decorator
Jul 2, 2021
8d2edfa
fix multiple bot for groups
Jul 2, 2021
805f909
* new featured added: buttons selectmenu
Jul 3, 2021
899551d
fix button/selectmenu
Jul 3, 2021
78d4a4a
Update button not found log
vijayymmeena Jul 3, 2021
82d60ae
Update menu not found log text
vijayymmeena Jul 3, 2021
ad599cd
fix init slash with permissions
Jul 3, 2021
86773fd
fix permissions on init slash
Jul 3, 2021
82e122c
permissions global comment
Jul 3, 2021
ec69d24
removed unwanted permission code
Jul 3, 2021
64d386e
fixed examples to support latest code
Jul 3, 2021
49fe6e9
update executeInteraction
Jul 3, 2021
721e7fe
doc update bot multiple botid
Jul 3, 2021
ac44935
accepted pull OwenCalvin/discord.ts/pull/56
Jul 3, 2021
1d1c3e7
added button example
Jul 3, 2021
df83522
fix example button
Jul 3, 2021
8c5fca1
added menu example
Jul 3, 2021
60d8759
update
Jul 3, 2021
16fd3e0
restored important async on decorators
Jul 3, 2021
fb9866a
* jest test failed because of buttons
Jul 3, 2021
53017f6
jest test fix for slash commands
Jul 3, 2021
932dea0
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
2b59105
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
680ad51
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
816b652
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
8b346ae
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
92da21f
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
2411836
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
f84dfbb
Update examples/button/discords/AppDiscord.ts
vijayymmeena Jul 3, 2021
5a1a6aa
fix button example
Jul 3, 2021
fa563e7
requiredByDefault set back to false
Jul 3, 2021
3514725
doc update: botid required, classes not required
Jul 3, 2021
6929eec
doc update: MetadataStorage
Jul 3, 2021
79b85cc
doc update
Jul 3, 2021
f770a2e
doc: added incomplete notes
Jul 3, 2021
659ef2f
doc: warning for incomplete docs
Jul 3, 2021
0c911f6
example update: function rename
Jul 4, 2021
55e1367
updated deprecated events
Jul 4, 2021
5c88ad9
added unknown interaction warning
Jul 4, 2021
42652d2
removed unwanted filter
Jul 4, 2021
61ecc3a
gourp permission fix
Jul 4, 2021
445b82e
update: permission decorator
Jul 4, 2021
c283fbb
developer can set default permission for slash
Jul 4, 2021
5c39108
removed unwanted greater than condition
Jul 4, 2021
a105dc5
* new decorator @DefaultPermission
Jul 4, 2021
a195d2c
doc for @DefaultPermission
Jul 4, 2021
65af9b4
init slash > guild > replace for loop with foreach
Jul 4, 2021
85b28a4
init slash > guild > replaced for loop
Jul 4, 2021
1824aca
@Bot fix for @On
Jul 4, 2021
947a0ef
botid fix for events
Jul 4, 2021
3a787fd
comment update for initslash
Jul 5, 2021
a06d222
solution for multiple class import
Jul 5, 2021
d837639
revert back last commit
Jul 5, 2021
3b7acda
fix multiple imports under multiple clients
Jul 5, 2021
a7587f4
removed unused variable
Jul 5, 2021
d8ab4f9
regular update based on discord.js
Jul 5, 2021
60f4008
jest slash test fix
Jul 5, 2021
f301739
simple command support
Jul 6, 2021
3f9ddd3
fix examples
Jul 6, 2021
1c8ff7a
fixed event execute
Jul 6, 2021
dcdab5d
simple command example
Jul 6, 2021
9d5bd0e
update command example
Jul 6, 2021
d04e31a
fix ``@Commad`` executation
Jul 6, 2021
ae2b055
update example command
Jul 6, 2021
2eb57d0
example command update
Jul 6, 2021
01fa0bb
update executecommand
Jul 6, 2021
1916229
fix permissions decorator for commands
Jul 6, 2021
b01b90d
update commands private to public for external use
Jul 6, 2021
6215c2a
guard type update
Jul 7, 2021
a741e2d
type fix
Jul 7, 2021
fe33ac7
doc formated
Jul 7, 2021
bb30bb8
guard example update
Jul 7, 2021
150a239
update guard example
Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"rules": {
"semi": "error",
"quotes": "error",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off"
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { Discord, On, Once } from "@typeit/discord";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage() {
// ...
}
Expand Down Expand Up @@ -96,12 +96,12 @@ import { Prefix } from "./Prefix";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
@Guard(
NotBot, // You can use multiple guard functions, they are excuted in the same order!
Prefix("!")
)
async onMessage([message]: ArgsOf<"message">) {
async onMessage([message]: ArgsOf<"messageCreate">) {
switch (message.content.toLowerCase()) {
case "hello":
message.reply("Hello!");
Expand Down
18 changes: 11 additions & 7 deletions docs/src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ module.exports = {
path: "/decorators/discord",
children: [
["/decorators/discord", "@Discord"],
["/decorators/on", "@On"],
["/decorators/once", "@Once"],
["/decorators/slash", "@Slash"],
["/decorators/option", "@Option"],
["/decorators/bot", "@Bot"],
["/decorators/button", "@Button"],
["/decorators/choice", "@Choice"],
["/decorators/choices", "@Choices"],
["/decorators/guild", "@Guild"],
["/decorators/permission", "@Permission"],
["/decorators/description", "@Description"],
["/decorators/group", "@Group"],
["/decorators/guard", "@Guard"],
["/decorators/description", "@Description"],
["/decorators/guild", "@Guild"],
["/decorators/on", "@On"],
["/decorators/once", "@Once"],
["/decorators/option", "@Option"],
["/decorators/defaultpermission", "@DefaultPermission"],
["/decorators/permission", "@Permission"],
["/decorators/selectmenu", "@SelectMenu"],
["/decorators/slash", "@Slash"],
]
}
]
Expand Down
5 changes: 5 additions & 0 deletions docs/src/decorators/bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @Bot

::: danger
doc for `@Bot` is not ready
:::
5 changes: 5 additions & 0 deletions docs/src/decorators/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @Button

::: danger
doc for `@Button` is not ready
:::
5 changes: 5 additions & 0 deletions docs/src/decorators/defaultpermission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @DefaultPermission

::: danger
doc for `@DefaultPermission` is not ready
:::
20 changes: 12 additions & 8 deletions docs/src/decorators/guard.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# @Guard
::: warning
add example for slash, argof message does not apply on interactions
:::

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.
Guards can be set for `@Slash`, `@Button`, `@SelectMenu`, `@On`, `@Once`, `@Discord` and globaly.

```typescript
import { Discord, On, Client, Guard } from "@typeit/discord";
Expand All @@ -13,12 +16,12 @@ import { Prefix } from "./Prefix";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
@Guard(
NotBot, // You can use multiple guard functions, they are excuted in the same order!
Prefix("!")
)
async onMessage([message]: ArgsOf<"message">) {
async onMessage([message]: ArgsOf<"messageCreate">) {
switch (message.content.toLowerCase()) {
case "hello":
message.reply("Hello!");
Expand Down Expand Up @@ -49,8 +52,8 @@ import { Prefix } from "./Prefix";
@Discord()
@Guard(NotBot, Prefix("!"))
abstract class AppDiscord {
@On("message")
message([message]: ArgsOf<"message">) {
@On("messageCreate")
message([message]: ArgsOf<"messageCreate">) {
//...
}

Expand All @@ -75,6 +78,7 @@ import { Client } from "@typeit/discord";

async function start() {
const client = new Client({
botId: "test",
classes: [
`${__dirname}/*Discord.ts`, // glob string to load the classes
`${__dirname}/*Discord.js`, // If you compile using "tsc" the file extension change to .js
Expand Down Expand Up @@ -104,7 +108,7 @@ Guards work like `Koa`'s, it's a function passed in parameter (third parameter i
```typescript
import { GuardFunction, ArgsOf } from "@typeit/discord";

export const NotBot: GuardFunction<ArgsOf<"message">> = ([message], client, next) => {
export const NotBot: GuardFunction<ArgsOf<"messageCreate">> = ([message], client, next) => {
if (client.user.id !== message.author.id) {
await next();
}
Expand All @@ -117,7 +121,7 @@ If you have to indicate parameters for a guard function you can simple use the "
import { GuardFunction } from "@typeit/discord";

export function Prefix(text: string, replace: boolean = true) {
const guard: GuardFunction<ArgsOf<"message">> = ([message], client, next) => {
const guard: GuardFunction<ArgsOf<"messageCreate">> = ([message], client, next) => {
const startWith = message.content.startsWith(text);
if (replace) {
message.content = message.content.replace(text, "");
Expand All @@ -138,7 +142,7 @@ As 4th parameter you receive a basic empty object that can be used to transmit d
```typescript
import { GuardFunction } from "@typeit/discord";

export const NotBot: GuardFunction<ArgsOf<"message">> = (
export const NotBot: GuardFunction<ArgsOf<"messageCreate">> = (
[message],
client,
next,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/decorators/guild.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @Guild
You can specify in wich guilds your @Slash commands are created by decorating the method with @Slash and @Guild
You can specify in which guilds your @Slash commands are created by decorating the method with @Slash and @Guild

```ts
@Discord()
Expand Down
6 changes: 3 additions & 3 deletions docs/src/decorators/on.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Discord, On, Once } from "@typeit/discord";

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage() {
// ...
}
Expand Down Expand Up @@ -42,9 +42,9 @@ import {

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage(
[message]: ArgsOf<"message">, // Type message automatically
[message]: ArgsOf<"messageCreate">, // Type message automatically
client: Client, // Client instance injected here,
guardPayload: any
) {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/decorators/once.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage(
[message]: ArgsOf<"message">, // Type message automatically
[message]: ArgsOf<"messageCreate">, // Type message automatically
client: Client, // Client instance injected here,
guardPayload: any
) {
Expand Down
1 change: 1 addition & 0 deletions docs/src/decorators/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ if you want to set the default required value, you can use `client.requiredByDef

```ts
const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand Down
5 changes: 5 additions & 0 deletions docs/src/decorators/selectmenu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @SelectMenu

::: danger
doc for `@SelectMenu` is not ready
:::
9 changes: 6 additions & 3 deletions docs/src/decorators/slash.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AppDiscord {
It require a bit of configuration at you Client initialization.
You have to manualy execute and initialize your Slash commands by using:
- `client.initSlashes()`
- `client.executeSlash(interaction)`
- `client.executeInteraction(interaction)`

This provide flexibility in your code

Expand All @@ -28,6 +28,7 @@ import { Client } from "@typeit/discord";

async function start() {
const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand All @@ -38,8 +39,8 @@ async function start() {
await client.initSlashes();
});

client.on("interaction", (interaction) => {
client.executeSlash(interaction);
client.on("interactionCreate", (interaction) => {
client.executeInteraction(interaction);
});

await client.login("YOUR_TOKEN");
Expand All @@ -53,6 +54,7 @@ start();

```ts
const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand Down Expand Up @@ -123,6 +125,7 @@ You can do:

```ts
const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/general/argsof.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {

@Discord()
abstract class AppDiscord {
@On("message")
@On("messageCreate")
private onMessage(
// The type of message is Message
[message]: ArgsOf<"message">
[message]: ArgsOf<"messageCreate">
) {
// ...
}
Expand Down
16 changes: 14 additions & 2 deletions docs/src/general/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ It manage all the operations between your app, Discord's API and discord.js
In order to start your application, you must use the discord.**ts**'s Client (not the client that is provided by discord.**js**!).
It works the same as the discord.**js**'s Client (same methods, properties, ...).

- **`classes` (required)**
- **`botId` (required)**
`string`
a bot id, help you manage your bot interactions, events (this is important in case there are more than one bot running in single instance)

- **`intents` (required)**
`Intents[]`
[see Intents](#intents)

- **`classes`**
`string[]`
Indicate the class jacket of your classes containing the `@Discord` decorator. It accepts a list of classes or of (glob) paths

Expand Down Expand Up @@ -35,6 +43,7 @@ import { Client } from "@typeit/discord";

async function start() {
const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand All @@ -53,7 +62,7 @@ start();
```

## Intents
You must specify the "**intents**" of your bot when you initialize the Client, it specify wich informations your bot receive from the Discord's servers, **it's different from the permissions**
You must specify the "**intents**" of your bot when you initialize the Client, it specify which informations your bot receive from the Discord's servers, **it's different from the permissions**

*Maintaining a stateful application can be difficult when it comes to the amount of data you're expected to process, especially at scale. Gateway Intents are a system to help you lower that computational burden.*

Expand All @@ -68,6 +77,7 @@ If an event of your app isn't triggered, you probably missed an Intent
import { Intents } from "discord.js";

const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand All @@ -81,6 +91,7 @@ const client = new Client({
import { Intents } from "discord.js";

const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand Down Expand Up @@ -114,6 +125,7 @@ const client = new Client({
import { Intents } from "discord.js";

const client = new Client({
botId: "test",
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Expand Down
2 changes: 2 additions & 0 deletions docs/src/general/metadatastorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ import { MetadataStorage } from "@typeit/discord.ts"
MetadataStorage.instance.slashes;
MetadataStorage.instance.events;
MetadataStorage.instance.discords;
MetadataStorage.instance.buttons;
MetadataStorage.instance.selectMenus;
// ...
```
1 change: 1 addition & 0 deletions docs/src/installation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Be aware that if you compile your code into JavaScript with `tsc` you have to sp

```ts
const client = new Client({
botId: "test",
// glob string to load the classes
classes: [
`${__dirname}/*Discord.ts`, // If you use ts-node
Expand Down
Loading