mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-19 09:05:59 -04:00
fix: typing issues since revolt-api bump
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { BannedUser as ApiBannedUser } from "revolt-api";
|
||||
|
||||
import { Client, File } from "../index.js";
|
||||
|
||||
/**
|
||||
* Banned User
|
||||
*/
|
||||
export class BannedUser {
|
||||
readonly id: string;
|
||||
readonly avatar?: File;
|
||||
readonly username: string;
|
||||
readonly discriminator: string;
|
||||
|
||||
/**
|
||||
* Construct Banned User
|
||||
* @param client Client
|
||||
* @param data Data
|
||||
*/
|
||||
constructor(client: Client, data: ApiBannedUser) {
|
||||
this.id = data._id;
|
||||
this.avatar = data.avatar ? new File(client, data.avatar) : undefined;
|
||||
this.username = data.username;
|
||||
this.discriminator = data.discriminator;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import type {
|
||||
Message as ApiMessage,
|
||||
User as ApiUser,
|
||||
DataEditChannel,
|
||||
DataMessageSearch,
|
||||
DataMessageSend,
|
||||
OptionsMessageSearch,
|
||||
Override,
|
||||
} from "revolt-api";
|
||||
import { APIRoutes } from "revolt-api/dist/routes";
|
||||
@@ -573,7 +573,7 @@ export class Channel {
|
||||
* @requires `SavedMessages`, `DirectMessage`, `Group`, `TextChannel`
|
||||
* @returns Messages
|
||||
*/
|
||||
async search(params: Omit<OptionsMessageSearch, "include_users">) {
|
||||
async search(params: Omit<DataMessageSearch, "include_users">) {
|
||||
const messages = (await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/search`,
|
||||
params
|
||||
@@ -592,7 +592,7 @@ export class Channel {
|
||||
* @requires `SavedMessages`, `DirectMessage`, `Group`, `TextChannel`
|
||||
* @returns Object including messages and users
|
||||
*/
|
||||
async searchWithUsers(params: Omit<OptionsMessageSearch, "include_users">) {
|
||||
async searchWithUsers(params: Omit<DataMessageSearch, "include_users">) {
|
||||
const data = (await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/search`,
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { DataEditWebhook } from "revolt-api";
|
||||
|
||||
import { ChannelWebhookCollection } from "../collections/index.js";
|
||||
import { hydrate } from "../hydration/index.js";
|
||||
|
||||
@@ -75,24 +73,29 @@ export class ChannelWebhook {
|
||||
|
||||
/**
|
||||
* Edit this webhook
|
||||
* TODO: not in production
|
||||
*/
|
||||
async edit(data: DataEditWebhook) {
|
||||
async edit(data: any /*: DataEditWebhook*/) {
|
||||
const webhook = await this.#collection.client.api.patch(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${this.id as ""}/${this.token as ""}`,
|
||||
data
|
||||
);
|
||||
|
||||
this.#collection.updateUnderlyingObject(
|
||||
this.id,
|
||||
// @ts-expect-error not in prod
|
||||
hydrate("channelWebhook", webhook, this.#collection.client)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this webhook
|
||||
* TODO: not in production
|
||||
*/
|
||||
async delete() {
|
||||
await this.#collection.client.api.delete(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${this.id}/${this.token}`
|
||||
);
|
||||
|
||||
|
||||
@@ -97,16 +97,22 @@ export class ServerPublicInvite extends PublicChannelInvite {
|
||||
const existingServer = this.client!.servers.get(this.serverId);
|
||||
if (existingServer) return existingServer;
|
||||
|
||||
const { server, channels } = await this.client!.api.post(
|
||||
`/invites/${this.code as ""}`
|
||||
);
|
||||
const invite = await this.client!.api.post(`/invites/${this.code as ""}`);
|
||||
|
||||
return batch(() => {
|
||||
for (const channel of channels) {
|
||||
this.client!.channels.getOrCreate(channel._id, channel);
|
||||
}
|
||||
if (invite.type === "Server") {
|
||||
return batch(() => {
|
||||
for (const channel of invite.channels) {
|
||||
this.client!.channels.getOrCreate(channel._id, channel);
|
||||
}
|
||||
|
||||
return this.client!.servers.getOrCreate(server._id, server, true);
|
||||
});
|
||||
return this.client!.servers.getOrCreate(
|
||||
invite.server._id,
|
||||
invite.server,
|
||||
true
|
||||
);
|
||||
});
|
||||
} else {
|
||||
throw "unreachable";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { batch } from "solid-js";
|
||||
|
||||
import type {
|
||||
AllMemberResponse,
|
||||
BannedUser,
|
||||
Category,
|
||||
DataBanCreate,
|
||||
DataCreateEmoji,
|
||||
@@ -514,11 +515,15 @@ export class Server {
|
||||
`/servers/${this.id as ""}/bans`
|
||||
);
|
||||
|
||||
users.forEach((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
const userDict = users.reduce(
|
||||
(d, c) => ({ ...d, [c._id]: c }),
|
||||
{} as Record<string, BannedUser>
|
||||
);
|
||||
|
||||
return bans.map((ban) => new ServerBan(this.#collection.client, ban));
|
||||
return bans.map(
|
||||
(ban) =>
|
||||
new ServerBan(this.#collection.client, ban, userDict[ban._id.user])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -720,8 +725,6 @@ export class Server {
|
||||
* @param emojiId Emoji ID
|
||||
*/
|
||||
async deleteEmoji(emojiId: string) {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/custom/emoji/${emojiId}`
|
||||
);
|
||||
return await this.#collection.client.api.delete(`/custom/emoji/${emojiId}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { MemberCompositeKey } from "revolt-api";
|
||||
import {
|
||||
BannedUser as ApiBannedUser,
|
||||
ServerBan as ApiServerBan,
|
||||
MemberCompositeKey,
|
||||
} from "revolt-api";
|
||||
|
||||
import { API, Client } from "../index.js";
|
||||
import { BannedUser, Client } from "../index.js";
|
||||
|
||||
/**
|
||||
* Server Ban
|
||||
@@ -9,23 +13,18 @@ export class ServerBan {
|
||||
protected client: Client;
|
||||
readonly id: MemberCompositeKey;
|
||||
readonly reason?: string;
|
||||
readonly user?: BannedUser;
|
||||
|
||||
/**
|
||||
* Construct Server Ban
|
||||
* @param client Client
|
||||
* @param data Data
|
||||
*/
|
||||
constructor(client: Client, data: API.ServerBan) {
|
||||
constructor(client: Client, data: ApiServerBan, user?: ApiBannedUser) {
|
||||
this.client = client;
|
||||
this.id = data._id;
|
||||
this.reason = data.reason!;
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
get user() {
|
||||
return this.client.users.get(this.id.user);
|
||||
this.user = user ? new BannedUser(client, user) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./BannedUser.js";
|
||||
export * from "./Bot.js";
|
||||
export * from "./Channel.js";
|
||||
export * from "./ChannelUnread.js";
|
||||
@@ -15,4 +16,3 @@ export * from "./ServerMember.js";
|
||||
export * from "./Session.js";
|
||||
export * from "./SystemMessage.js";
|
||||
export * from "./User.js";
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ export class ChannelWebhookCollection extends ClassCollection<
|
||||
async fetch(id: string): Promise<ChannelWebhook> {
|
||||
const webhook = this.get(id);
|
||||
if (webhook) return webhook;
|
||||
// @ts-expect-error not in prod
|
||||
const data = await this.client.api.get(`/webhooks/${id as ""}`);
|
||||
// @ts-expect-error not in prod
|
||||
return this.getOrCreate(data.id, data as API.Webhook);
|
||||
}
|
||||
|
||||
@@ -33,8 +35,10 @@ export class ChannelWebhookCollection extends ClassCollection<
|
||||
const webhook = this.get(id);
|
||||
if (webhook) return webhook;
|
||||
const data = await this.client.api.get(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${id as ""}/${token as ""}`
|
||||
);
|
||||
// @ts-expect-error not in prod
|
||||
return this.getOrCreate(data.id, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ export class ServerCollection extends ClassCollection<Server, HydratedServer> {
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error TODO
|
||||
return this.getOrCreate(data._id, data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ export class UserCollection extends ClassCollection<User, HydratedUser> {
|
||||
_id: SYSTEM_ID,
|
||||
username: "Revolt",
|
||||
discriminator: "0000",
|
||||
online: true,
|
||||
relationship: "None",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user