little file refactor

This commit is contained in:
Jaron Pate
2022-09-18 01:18:38 -05:00
parent 11bb6d9569
commit 72483a5070
4 changed files with 67 additions and 62 deletions
+2 -2
View File
@@ -14,10 +14,10 @@ import {
ActivityType, ActivityType,
CommandFuntion, CommandFuntion,
Interaction, Interaction,
InteractionFunction, InteractionFunction
InteractionContext
} from '../types'; } from '../types';
import { Context } from './context'; import { Context } from './context';
import { InteractionContext } from './interaction';
export class Gateway { export class Gateway {
socket: WebSocket; socket: WebSocket;
+2 -1
View File
@@ -2,4 +2,5 @@ export * from './gateway';
export * from './cache'; export * from './cache';
export * from './guilds'; export * from './guilds';
export * from './context'; export * from './context';
export * from './message'; export * from './message';
export * from './interaction';
+61
View File
@@ -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 });
};
}
+2 -59
View File
@@ -1,4 +1,5 @@
import { Client, Message } from '..'; import { Client } from '..';
import { InteractionContext } from '../lib';
export abstract class Interaction { export abstract class Interaction {
abstract custom_id: string | string[]; abstract custom_id: string | string[];
@@ -16,61 +17,3 @@ export enum InteractionResponseType {
AutocompleteResult = 8, AutocompleteResult = 8,
Modal = 9 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 });
};
}