mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 04:56:07 +00:00
feat: monetization (#227)
* feat: monetization * chore: apply formatting * fix: query list entitlements
This commit is contained in:
parent
026530fd39
commit
11c72e66f6
@ -30,6 +30,11 @@ import type {
|
||||
RESTPostAPIApplicationEmojiResult,
|
||||
RESTPatchAPIApplicationEmojiResult,
|
||||
RESTDeleteAPIApplicationEmojiResult,
|
||||
RESTGetAPIEntitlementsResult,
|
||||
RESTGetAPIEntitlementsQuery,
|
||||
RESTPostAPIEntitlementBody,
|
||||
RESTPostAPIEntitlementResult,
|
||||
RESTGetAPISKUsResult,
|
||||
} from '../../types';
|
||||
|
||||
import type { ProxyRequestMethod } from '../Router';
|
||||
@ -118,5 +123,25 @@ export interface ApplicationRoutes {
|
||||
args?: RestArguments<ProxyRequestMethod.Post, RESTPostAPIApplicationEmojiJSONBody>,
|
||||
): Promise<RESTPostAPIApplicationEmojiResult>;
|
||||
};
|
||||
entitlements: {
|
||||
get(
|
||||
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIEntitlementsQuery>,
|
||||
): Promise<RESTGetAPIEntitlementsResult>;
|
||||
post(
|
||||
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIEntitlementBody>,
|
||||
): Promise<RESTPostAPIEntitlementResult>;
|
||||
|
||||
(
|
||||
id: string,
|
||||
): {
|
||||
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<never>;
|
||||
consume: {
|
||||
post(args?: RestArguments<ProxyRequestMethod.Post>): Promise<never>;
|
||||
};
|
||||
};
|
||||
};
|
||||
skus: {
|
||||
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPISKUsResult>;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import type {
|
||||
import { IgnoreCommand, type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
||||
import { CommandHandler } from '../commands/handler';
|
||||
import {
|
||||
ApplicationShorter,
|
||||
ChannelShorter,
|
||||
EmojiShorter,
|
||||
GuildShorter,
|
||||
@ -56,6 +57,7 @@ export class BaseClient {
|
||||
rest!: ApiHandler;
|
||||
cache!: Cache;
|
||||
|
||||
applications = new ApplicationShorter(this);
|
||||
users = new UsersShorter(this);
|
||||
channels = new ChannelShorter(this);
|
||||
guilds = new GuildShorter(this);
|
||||
|
@ -16,6 +16,7 @@ export * from './shorters/users';
|
||||
export * from './shorters/threads';
|
||||
export * from './shorters/webhook';
|
||||
export * from './shorters/interaction';
|
||||
export * from './shorters/application';
|
||||
//
|
||||
export * from './types/options';
|
||||
export * from './types/resolvables';
|
||||
|
31
src/common/shorters/application.ts
Normal file
31
src/common/shorters/application.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Entitlement } from '../../structures/Entitlement';
|
||||
import type { APIEntitlement, RESTGetAPIEntitlementsQuery, RESTPostAPIEntitlementBody } from '../../types';
|
||||
import { BaseShorter } from './base';
|
||||
|
||||
export class ApplicationShorter extends BaseShorter {
|
||||
async listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) {
|
||||
return this.client.proxy
|
||||
.applications(applicationId)
|
||||
.entitlements.get({ query })
|
||||
.then(et => et.map(e => new Entitlement(this.client, e)));
|
||||
}
|
||||
|
||||
async consumeEntitlement(applicationId: string, entitlementId: string) {
|
||||
return this.client.proxy.applications(applicationId).entitlements(entitlementId).consume.post();
|
||||
}
|
||||
|
||||
async createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) {
|
||||
return this.client.proxy
|
||||
.applications(applicationId)
|
||||
.entitlements.post({ body })
|
||||
.then(et => new Entitlement(this.client, et as APIEntitlement));
|
||||
}
|
||||
|
||||
async deleteTestEntitlement(applicationId: string, entitlementId: string) {
|
||||
return this.client.proxy.applications(applicationId).entitlements(entitlementId).delete();
|
||||
}
|
||||
|
||||
async listSKUs(applicationId: string) {
|
||||
return this.client.proxy.applications(applicationId).skus.get();
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
import type { APIEntitlement } from '../../types';
|
||||
import { toCamelCase } from '../../common';
|
||||
import type { UsingClient } from '../../commands';
|
||||
import { Entitlement } from '../../structures/Entitlement';
|
||||
|
||||
export const ENTITLEMENT_CREATE = (_: UsingClient, data: APIEntitlement) => {
|
||||
return toCamelCase(data);
|
||||
export const ENTITLEMENT_CREATE = (client: UsingClient, data: APIEntitlement) => {
|
||||
return new Entitlement(client, data);
|
||||
};
|
||||
|
||||
export const ENTITLEMENT_UPDATE = (_: UsingClient, data: APIEntitlement) => {
|
||||
return toCamelCase(data);
|
||||
export const ENTITLEMENT_UPDATE = (client: UsingClient, data: APIEntitlement) => {
|
||||
return new Entitlement(client, data);
|
||||
};
|
||||
|
||||
export const ENTITLEMENT_DELETE = (_: UsingClient, data: APIEntitlement) => {
|
||||
return toCamelCase(data);
|
||||
export const ENTITLEMENT_DELETE = (client: UsingClient, data: APIEntitlement) => {
|
||||
return new Entitlement(client, data);
|
||||
};
|
||||
|
19
src/structures/Entitlement.ts
Normal file
19
src/structures/Entitlement.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { ObjectToLower } from '../common';
|
||||
import type { APIEntitlement } from '../types';
|
||||
import { DiscordBase } from './extra/DiscordBase';
|
||||
|
||||
export interface Entitlement extends ObjectToLower<APIEntitlement> {}
|
||||
|
||||
export class Entitlement extends DiscordBase<APIEntitlement> {
|
||||
get startsAtTimestamp() {
|
||||
return this.startsAt ? Date.parse(this.startsAt) : null;
|
||||
}
|
||||
|
||||
get endsAtTimestamp() {
|
||||
return this.endsAt ? Date.parse(this.endsAt) : null;
|
||||
}
|
||||
|
||||
consume() {
|
||||
return this.client.applications.consumeEntitlement(this.applicationId, this.id);
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ import {
|
||||
type OptionResolverStructure,
|
||||
} from '../client/transformers';
|
||||
import { mix } from '../deps/mixer';
|
||||
import { Entitlement } from './Entitlement';
|
||||
|
||||
export type ReplyInteractionBody =
|
||||
| { type: InteractionResponseType.Modal; data: ModalCreateBodyRequest }
|
||||
@ -123,6 +124,8 @@ export class BaseInteraction<
|
||||
this.channel = channelFrom(interaction.channel, client);
|
||||
}
|
||||
this.user = this.member?.user ?? Transformers.User(client, interaction.user!);
|
||||
|
||||
this.entitlements = interaction.entitlements.map(e => new Entitlement(this.client, e));
|
||||
}
|
||||
|
||||
static transformBodyRequest(
|
||||
|
Loading…
x
Reference in New Issue
Block a user