Skip to content

Commit

Permalink
Experimental: a better way to interact.
Browse files Browse the repository at this point in the history
One of the biggest changes of TouchGuild history, enabling you to do much more with a more controlled environment, preventing issues, and making your experience, simply, better.

Discover that by yourself.
We're taking feedback.
  • Loading branch information
pakkographic committed Aug 17, 2024
1 parent 4b15361 commit 7631086
Show file tree
Hide file tree
Showing 17 changed files with 1,123 additions and 1,613 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = {
}
],
"@typescript-eslint/method-signature-style": ["error", "method"],
"@typescript-eslint/no-duplicate-imports": "error",
// "@typescript-eslint/no-duplicate-imports": "error",
"@typescript-eslint/no-empty-function": [
"error",
{
Expand Down Expand Up @@ -184,7 +184,7 @@ module.exports = {
"no-console": "off",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "off",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
Expand Down Expand Up @@ -299,7 +299,8 @@ module.exports = {
"SwitchCase": 1
}
],
"jsdoc/newline-after-description": ["error", "never"],
// "jsdoc/newline-after-description": ["error", "never"],
"jsdoc/newline-after-description": "off",
"arrow-parens": ["error", "as-needed"],
"unicorn/no-null": "off",
"unicorn/no-static-only-class": "off",
Expand Down
16 changes: 16 additions & 0 deletions lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ export type ChannelSubcategoryReactionTypes = "CalendarEventComment" | "ForumThr

/** Channel reaction types that supports bulk delete. */
export type ChannelReactionTypeBulkDeleteSupported = "ChannelMessage";

export enum ApplicationCommandOptionType {
STRING,
INTEGER,
FLOAT,
NUMBER,
SIGNED_32_INTEGER,
USER,
ROLE,
CHANNEL,
EMBEDDED_ATTACHMENT
}

export enum ApplicationCommandType {
CHAT_INPUT = 1
}
98 changes: 96 additions & 2 deletions lib/gateway/events/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import type {
GatewayEvent_ChatMessageDeleted,
GatewayEvent_ChatMessageUpdated
} from "../../Constants";
import type { TextChannel } from "../../structures/TextChannel";
import { TextChannel } from "../../structures/TextChannel";
import type { ChannelMessageReactionBulkRemove } from "../../types/";

import { CommandInteraction } from "../../structures/CommandInteraction";
/** Internal component, emitting message events. */
export class MessageHandler extends GatewayEventHandler {
private async addGuildChannel(guildID: string, channelID: string): Promise<void> {
Expand All @@ -39,10 +39,104 @@ export class MessageHandler extends GatewayEventHandler {
if (this.client.params.waitForCaching)
await this.addGuildChannel(data.serverId, data.message.channelId);
else void this.addGuildChannel(data.serverId, data.message.channelId);

if (
this.client.application.enabled
&& !data.message.createdByWebhookId
) {
const isReplyingApp =
data.message.replyMessageIds?.some(messageID => {
const message =
this.client.getMessage(
data.serverId,
data.message.channelId,
messageID
);
return message?.memberID === this.client.user?.id;
}) ?? false;

const commandNames =
this.client.application.commands.map(command => command.name);

let currentCommandName: string | null = null;
const executionType: "full" | "simple" | false =
commandNames?.some((name): boolean => {
const usingAppCommand = data.message.content?.startsWith("/" + this.client.params.setupApplication!.appShortcutName + " " + name);
const usingSimpleCommand = data.message.content?.startsWith("/" + name);

if (usingAppCommand) {
currentCommandName = name;
return true;
}

if (usingSimpleCommand) {
currentCommandName = name;
return true;
}

return false;
}) ? (data.message.content?.startsWith("/" + this.client.params.setupApplication!.appShortcutName + " ") ? "full" : "simple") : false;


if (
isReplyingApp
&& executionType === "simple"
|| executionType === "full"
) {
const interaction =
new CommandInteraction(
{
guildID: data.serverId,
message: data.message,
name: currentCommandName!,
directReply: isReplyingApp,
executionType
},
this.client
);

const verifyOptionsData = interaction.data ? interaction.data.options.verifyOptions() : { missing: [], incorrect: [], total: [] };
if (
interaction.data?.options.requiredOptions.length
&& interaction.data.options.values
&& (verifyOptionsData.missing.length !== 0 || verifyOptionsData.incorrect.length !== 0)
) {
let content = "";
if (verifyOptionsData.missing.length !== 0 && verifyOptionsData.incorrect.length !== 0) {
content = `${verifyOptionsData.missing.length} required option${verifyOptionsData.missing.length > 1 ? "s are" : " is"} missing, ${verifyOptionsData.incorrect.length} ${verifyOptionsData.incorrect.length > 1 ? "are" : "is"} incorrect.`;
} else if (verifyOptionsData.missing.length !== 0) {
content = `${verifyOptionsData.missing.length} required option${verifyOptionsData.missing.length > 1 ? "s are" : " is"} missing.`;
} else if (verifyOptionsData.incorrect.length !== 0) {
content = `${verifyOptionsData.incorrect.length} required option${verifyOptionsData.incorrect.length > 1 ? "s are" : " is"} incorrect.`;
} else {
content = "An error has occurred while treating your command.";
}

const totalList = interaction.data.applicationCommand.options ?
interaction.data.applicationCommand.options.map(opt => {
if (verifyOptionsData.total.includes(opt.name)) return `**${opt.name}**`;
if (!opt.required) return `*${opt.name}*`;
return opt.name;
}) : [];

if (content !== "An error has occurred while treating your command.") {
content += " (" + totalList.join(", ") + ")";
}

return void interaction.createMessage({ content, isPrivate: true });
}
return void this.client.emit(
"interactionCreate",
interaction
);
}
}

const channel =
this.client.getChannel<TextChannel>(data.serverId, data.message.channelId);
const MessageComponent =
channel?.messages?.update(data.message) ?? new Message(data.message, this.client);

this.client.emit("messageCreate", MessageComponent);
}
async messageDelete(data: GatewayEvent_ChatMessageDeleted): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export * from "./util/Collection";
export * from "./util/TypedCollection";

export * as APITypes from "guildedapi-types.ts/v1";
export * from "./Constants";
export * as Constants from "./Constants";
2 changes: 1 addition & 1 deletion lib/rest/RESTManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class RESTManager {
token: Client["ws"]["token"];
/** Request Handler */
handler: RequestHandler;
/** Guild routes */
/** Guild routes. */
guilds: Guilds;
/** Channel routes */
channels: Channels;
Expand Down
Loading

0 comments on commit 7631086

Please sign in to comment.