Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash Command API enhancements #579

Open
wants to merge 104 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
9f39209
api
yofukashino Jun 28, 2023
3892bb0
coremod
yofukashino Jun 28, 2023
2def330
types
yofukashino Jun 28, 2023
5c28721
messages common
yofukashino Jun 28, 2023
fabeec6
replugged item
yofukashino Jun 28, 2023
be51579
type fix
yofukashino Jun 28, 2023
f17b51e
cspell
yofukashino Jun 28, 2023
a6a4c25
made send option optional
yofukashino Jun 28, 2023
943a4bf
name in export and replugged object
yofukashino Jun 28, 2023
515c8b8
into a codeblock as requested by moon girl
yofukashino Jun 28, 2023
8873f93
Merge branch 'main' into slash-command-api
yofukashino Jun 28, 2023
1b990c9
i forgot to make it false before
yofukashino Jun 29, 2023
f92d35d
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Jun 29, 2023
705d88d
i should test before pushing
yofukashino Jun 29, 2023
92e4d35
Merge branch 'main' into slash-command-api
yofukashino Jun 30, 2023
e20907c
Merge branch 'main' into slash-command-api
yofukashino Jul 3, 2023
d8f3f4c
prettier??
yofukashino Jul 3, 2023
52d36e8
Merge branch 'main' into slash-command-api
yofukashino Jul 5, 2023
4989952
removed a testing log
yofukashino Jul 9, 2023
92c42f0
Merge branch 'main' into slash-command-api
yofukashino Jul 9, 2023
039ab83
ability to add custom sections removed
yofukashino Jul 25, 2023
95c343f
Merge remote-tracking branch 'refs/remotes/origin/slash-command-api' …
yofukashino Jul 25, 2023
aff0ad4
Merge branch 'main' into slash-command-api
yofukashino Jul 25, 2023
0ff654d
better type for commands
yofukashino Jul 25, 2023
770c1d8
Merge remote-tracking branch 'refs/remotes/origin/slash-command-api' …
yofukashino Jul 25, 2023
0598285
this spelling is right i am pretty sure
yofukashino Jul 25, 2023
ec35ac4
it is a word. check on wipipedia
yofukashino Jul 25, 2023
5b58a56
discord changed it first
yofukashino Jul 25, 2023
3f375bd
better styling in codeblock
yofukashino Jul 25, 2023
c79fe00
feat(types): more precise MessageUtils
FedeIlLeone Jul 27, 2023
87e2c29
Merge branch 'v4.6.0' into pr/Tharki-God/501
asportnoy Aug 3, 2023
df6c0d2
Merge branch 'replugged-org:main' into slash-command-api
yofukashino Aug 22, 2023
6091b4b
done now pls. uwu accept this pr meow rawr x3
yofukashino Aug 22, 2023
4f5d7b7
some more changes? more coming later
yofukashino Aug 24, 2023
c4f75a6
meh
yofukashino Aug 24, 2023
38f5ec9
Merge branch 'v4.7.0' into slash-command-api
yofukashino Aug 24, 2023
e88bce9
Merge branch 'replugged-org:main' into slash-command-api
yofukashino Aug 26, 2023
071a963
localized?
yofukashino Aug 26, 2023
4fbdc44
todos
yofukashino Aug 26, 2023
b4a6ce7
Dynamic typing
asportnoy Aug 27, 2023
4c302c0
MInor fixes
asportnoy Aug 27, 2023
60bc540
names ig
yofukashino Aug 27, 2023
405180a
cspell f u
yofukashino Aug 27, 2023
3830d9c
Merge branch 'v4.7.0' into slash-command-api
yofukashino Aug 27, 2023
a6a25dc
missed this smh
yofukashino Aug 27, 2023
0b91eed
sorry
yofukashino Aug 27, 2023
49d952f
removed subcommand
yofukashino Aug 27, 2023
068b272
Merge branch 'v4.7.0' into slash-command-api
yofukashino Aug 27, 2023
1a35d9e
requested changes
yofukashino Aug 27, 2023
9984149
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Aug 27, 2023
1d846f5
oki
yofukashino Aug 27, 2023
a53278c
mummy meri shaddi kardo may june july mai
yofukashino Aug 27, 2023
4e5f499
meh
yofukashino Aug 27, 2023
cdb23e3
done
yofukashino Aug 27, 2023
2c0c474
loading message
yofukashino Aug 28, 2023
03e95e1
all done. fml
yofukashino Aug 28, 2023
a434819
Still thanks Fede
yofukashino Aug 28, 2023
cd0512a
individual slash command manager
yofukashino Aug 28, 2023
6519316
loading message
yofukashino Aug 28, 2023
cc50bdc
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Aug 28, 2023
e063e5c
f me
yofukashino Aug 28, 2023
9d3c8f3
happy?
yofukashino Aug 28, 2023
d093523
Merge branch 'v4.7.0' into slash-command-api
yofukashino Aug 29, 2023
b520df4
Update src/renderer/modules/injector.ts
yofukashino Aug 29, 2023
adfcaae
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Aug 29, 2023
5db08e1
requested changes
yofukashino Aug 29, 2023
d33deea
feat(types): commands improvement
FedeIlLeone Aug 29, 2023
421cae8
fix(types): lint
FedeIlLeone Aug 29, 2023
d22098f
Update src/renderer/modules/injector.ts
yofukashino Sep 1, 2023
e8b8c0b
Update src/renderer/modules/injector.ts
yofukashino Sep 1, 2023
93e78db
i18n
yofukashino Sep 1, 2023
53ac3fa
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Sep 1, 2023
8f596d0
channelId was wrong
yofukashino Sep 1, 2023
b79245b
unused var
yofukashino Sep 1, 2023
19897bd
feat: update embed types
FedeIlLeone Sep 8, 2023
6559b29
ignition issue. someone explain to me why it was blocking tho
yofukashino Sep 14, 2023
576c718
Merge branch 'v4.7.0' of https://github.com/replugged-org/replugged i…
yofukashino Sep 21, 2023
0aa4621
Merge branch 'v4.7.0' of https://github.com/replugged-org/replugged i…
yofukashino Sep 24, 2023
e9ea706
better
yofukashino Sep 24, 2023
bc3fd0b
it only accepts that
yofukashino Sep 24, 2023
1eac1e2
forgot these
yofukashino Sep 24, 2023
3991f89
Merge branch 'v4.7.0' into slash-command-api
yofukashino Sep 24, 2023
6bb7806
requested changes
yofukashino Sep 24, 2023
2864d5e
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Sep 24, 2023
90ec654
Merge branch 'v4.7.0' into slash-command-api
yofukashino Sep 26, 2023
4986c47
Merge branch 'v4.7.0' into slash-command-api
yofukashino Oct 2, 2023
1aa3201
Merge branch 'v4.7.0' into pr/559/slash-command-api
asportnoy Oct 15, 2023
07d45fb
Type fixes
asportnoy Oct 15, 2023
0ecf45c
removed subcommands on request for now.
yofukashino Oct 15, 2023
31c8c6d
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Oct 15, 2023
981d54a
Merge branch 'v4.7.0' into slash-command-api
yofukashino Oct 15, 2023
893ea49
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Oct 15, 2023
d728baf
type fixes
yofukashino Oct 15, 2023
2bf8cc4
Fix mistake
asportnoy Oct 17, 2023
ba0d5ea
Fix other mistakes
asportnoy Oct 17, 2023
21bcf03
Another one
asportnoy Oct 17, 2023
8e5d582
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Oct 22, 2023
73e5ac9
sub command support and bug fix
yofukashino Oct 22, 2023
3113116
Merge https://github.com/replugged-org/replugged into slash-command-api
yofukashino Oct 22, 2023
69158c1
Merge branch 'main' into slash-command-api
yofukashino Oct 24, 2023
e6a983c
added up key to previous command
yofukashino Oct 24, 2023
8bbd967
Merge branch 'slash-command-api' of https://github.com/Tharki-God/rep…
yofukashino Oct 24, 2023
b60e408
Merge branch 'main' into slash-command-api
yofukashino Apr 9, 2024
efb7121
cache fix
yofukashino Apr 9, 2024
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
48 changes: 46 additions & 2 deletions src/renderer/apis/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
},
// eslint-disable-next-line @typescript-eslint/naming-convention
interaction_data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
application_command: command,
options: args,
type: command.type,
id: command.id,
name: command.displayName,
},
type: 20,
Expand Down Expand Up @@ -155,6 +160,11 @@
},
// eslint-disable-next-line @typescript-eslint/naming-convention
interaction_data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
application_command: command,
options: args,
type: command.type,
id: command.id,
name: command.displayName,
},
type: 20,
Expand Down Expand Up @@ -183,6 +193,11 @@
},
// eslint-disable-next-line @typescript-eslint/naming-convention
interaction_data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
application_command: command,
options: args,
type: command.type,
id: command.id,
name: command.displayName,
},
type: 20,
Expand Down Expand Up @@ -215,26 +230,55 @@
});
}
const currentSection = commandAndSections.get(this.#section.id);
const subcommandUnregister: Array<() => void> = [];
command.applicationId = currentSection?.section.id;
command.displayName ??= command.name;
command.displayDescription ??= command.description;
command.type = 2;
command.type = 1;
command.id ??= command.name;

command.execute ??= (args, currentInfo) => {
void executeCommand(command.executor, args, currentInfo, command);
};

command.options?.map((option) => {
if (option.type === ApplicationCommandOptionType.Subcommand) {

Check failure on line 245 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

This comparison appears to be unintentional because the types 'ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Boolean | ... 5 more ... | ApplicationCommandOptionType.Attachment' and 'ApplicationCommandOptionType.Subcommand' have no overlap.
option.applicationId = currentSection?.section.id;

Check failure on line 246 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'applicationId' does not exist on type 'never'.
option.name = `${command.name} ${option.name}`;

Check failure on line 247 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'name' does not exist on type 'never'.

Check failure on line 247 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'name' does not exist on type 'never'.
option.displayName ??= option.name;

Check failure on line 248 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'displayName' does not exist on type 'never'.

Check failure on line 248 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'name' does not exist on type 'never'.
option.displayDescription ??= option.description;

Check failure on line 249 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'displayDescription' does not exist on type 'never'.

Check failure on line 249 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'description' does not exist on type 'never'.
option.id = `${command.id}\u0000${option.name}`;

Check failure on line 250 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'id' does not exist on type 'never'.

Check failure on line 250 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run TypeScript

Property 'name' does not exist on type 'never'.
option.execute ??= (args, currentInfo) => {
void executeCommand(option.executor, args, currentInfo, option);
};
subcommandUnregister.push(this.registerCommand(option));
return null;
}
if (option.type === ApplicationCommandOptionType.SubcommandGroup) {
for (const subcommand of option.options ?? []) {
subcommand.type = 1;
subcommand.applicationId = currentSection?.section.id;
subcommand.name = `${command.name} ${option.name} ${subcommand.name}`;
subcommand.displayName ??= subcommand.name;
subcommand.displayDescription ??= subcommand.description;
subcommand.id = `${command.id}\u0000${option.name}\u0000${subcommand.name}`;
subcommand.execute ??= (args, currentInfo) => {
void executeCommand(subcommand.executor, args, currentInfo, subcommand);
};
subcommandUnregister.push(this.registerCommand(subcommand));
}
return null;
}
option.serverLocalizedName ??= option.displayName;
option.displayName ??= option.name;
option.displayDescription ??= option.description;
return option;
});

command.options = command.options?.filter(Boolean);
currentSection?.commands.set(command.id, command as AnyRepluggedCommand);

const uninject = (): void => {
subcommandUnregister.forEach((un) => un());
void currentSection?.commands.delete(command.id!);
this.#unregister = this.#unregister.filter((u) => u !== uninject);
};
Expand Down
27 changes: 26 additions & 1 deletion src/renderer/coremods/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,31 @@ async function injectApplicationCommandIndexStore(): Promise<void> {
},
);
}

async function injectCommandCache(): Promise<void> {
const mod = await waitForProps<{
getCachedCommand: (channel: Channel, id: string) => Promise<void>;
}>("getCachedCommand");
injector.after(
mod,
"getCachedCommand",
([, id], res: { application?: RepluggedCommandSection; command?: AnyRepluggedCommand }) => {
const commandAndSectionsArray = Array.from(commandAndSections.values()).filter(
(commandAndSection) => commandAndSection.commands.size,
);
const rpCached = commandAndSectionsArray
.map((commandAndSection) => ({
application: commandAndSection.section,
command: Array.from(commandAndSection.commands.values()).find(
(command) => command.id === id,
),
}))
.find((applicationAndCommand) => applicationAndCommand.command);
res.application ??= rpCached?.application;
res.command ??= rpCached?.command;
return res;
},
);
}
async function injectProfileFetch(): Promise<void> {
const mod = await waitForProps<{
fetchProfile: (id: string) => Promise<void>;
Expand All @@ -280,6 +304,7 @@ export async function start(): Promise<void> {
await injectRepluggedBotIcon();
await injectRepluggedSectionIcon();
await injectApplicationCommandIndexStore();
await injectCommandCache();
await injectProfileFetch();
loadCommands();
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/discord.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Message } from "@common/i18n";

export enum ApplicationCommandOptionType {
//Subcommand = 1,
//SubcommandGroup = 2,
Subcommand = 1,
SubcommandGroup = 2,
String = 3,
Integer = 4,
Boolean = 5,
Expand Down
Loading