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,
|
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
@@ -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';
|
||||||
|
|||||||
@@ -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 {
|
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 });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user