mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
little file refactor
This commit is contained in:
+2
-2
@@ -14,10 +14,10 @@ import {
|
||||
ActivityType,
|
||||
CommandFuntion,
|
||||
Interaction,
|
||||
InteractionFunction,
|
||||
InteractionContext
|
||||
InteractionFunction
|
||||
} from '../types';
|
||||
import { Context } from './context';
|
||||
import { InteractionContext } from './interaction';
|
||||
|
||||
export class Gateway {
|
||||
socket: WebSocket;
|
||||
|
||||
@@ -3,3 +3,4 @@ export * from './cache';
|
||||
export * from './guilds';
|
||||
export * from './context';
|
||||
export * from './message';
|
||||
export * from './interaction';
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Client } from "..";
|
||||
import { InteractionResponseType } from "../types";
|
||||
import { Message } from "./message";
|
||||
|
||||
export class InteractionContext {
|
||||
public client: Client;
|
||||
public interaction: Record<string, any>;
|
||||
constructor({ client, interaction }: { client: Client; interaction: Record<string, any> }) {
|
||||
this.client = client;
|
||||
this.interaction = interaction;
|
||||
}
|
||||
|
||||
ack = (type: InteractionResponseType = InteractionResponseType.Pong, data?: Record<string, any>) => {
|
||||
return this.client.api.post(`/interactions/${this.interaction.id}/${this.interaction.token}/callback`, {
|
||||
type,
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
reply = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.ack(InteractionResponseType.Reply, {
|
||||
...message
|
||||
});
|
||||
};
|
||||
|
||||
edit = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.ack(InteractionResponseType.UpdateMessage, {
|
||||
...message
|
||||
});
|
||||
};
|
||||
|
||||
editOriginal = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.client.api.patch(
|
||||
`/webhooks/${this.client.application_id}/${this.interaction.token}/messages/@original`,
|
||||
{
|
||||
type: InteractionResponseType.DeferredUpdateMessage,
|
||||
...message
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
deleteOriginal = () => {
|
||||
return this.client.api.delete(
|
||||
`/webhooks/${this.client.application_id}/${this.interaction.token}/messages/@original`
|
||||
);
|
||||
};
|
||||
|
||||
loading = async () => {
|
||||
await this.ack(InteractionResponseType.DeferredReply);
|
||||
return new InteractionContext({ client: this.client, interaction: this.interaction });
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Client, Message } from '..';
|
||||
import { Client } from '..';
|
||||
import { InteractionContext } from '../lib';
|
||||
|
||||
export abstract class Interaction {
|
||||
abstract custom_id: string | string[];
|
||||
@@ -16,61 +17,3 @@ export enum InteractionResponseType {
|
||||
AutocompleteResult = 8,
|
||||
Modal = 9
|
||||
}
|
||||
|
||||
export class InteractionContext {
|
||||
public client: Client;
|
||||
public interaction: Record<string, any>;
|
||||
constructor({ client, interaction }: { client: Client; interaction: Record<string, any> }) {
|
||||
this.client = client;
|
||||
this.interaction = interaction;
|
||||
}
|
||||
|
||||
ack = (type: InteractionResponseType = InteractionResponseType.Pong, data?: Record<string, any>) => {
|
||||
return this.client.api.post(`/interactions/${this.interaction.id}/${this.interaction.token}/callback`, {
|
||||
type,
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
reply = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.ack(InteractionResponseType.Reply, {
|
||||
...message
|
||||
});
|
||||
};
|
||||
|
||||
edit = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.ack(InteractionResponseType.UpdateMessage, {
|
||||
...message
|
||||
});
|
||||
};
|
||||
|
||||
editOriginal = (message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
}
|
||||
return this.client.api.patch(
|
||||
`/webhooks/${this.client.application_id}/${this.interaction.token}/messages/@original`,
|
||||
{
|
||||
type: InteractionResponseType.DeferredUpdateMessage,
|
||||
...message
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
deleteOriginal = () => {
|
||||
return this.client.api.delete(
|
||||
`/webhooks/${this.client.application_id}/${this.interaction.token}/messages/@original`
|
||||
);
|
||||
};
|
||||
|
||||
loading = async () => {
|
||||
await this.ack(InteractionResponseType.DeferredReply);
|
||||
return new InteractionContext({ client: this.client, interaction: this.interaction });
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user