Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: wrong branch #98

Merged
merged 7 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"author": "Paul Makles <insrt.uk>",
"license": "MIT",
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"build:esm": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc && cp package-esm.json lib/esm/package.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:watch": "tsc-watch --onSuccess \"node .\"",
"lint": "eslint --ext .ts,.tsx src/",
Expand Down
21 changes: 14 additions & 7 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Accessor, Setter, batch, createSignal } from "solid-js";

import EventEmitter from "eventemitter3";
import { API, Role } from "revolt-api";
import type { DataLogin, RevoltConfig } from "revolt-api";
import { API, Role } from "revolt-api";

import { Channel, Emoji, Message, Server, ServerMember, User } from "./classes";
import {
Channel,
Emoji,
Message,
Server,
ServerMember,
User,
} from "./classes/index.js";
import { AccountCollection } from "./collections/AccountCollection.js";
import {
BotCollection,
ChannelCollection,
Expand All @@ -16,23 +24,22 @@ import {
ServerMemberCollection,
SessionCollection,
UserCollection,
} from "./collections";
import { AccountCollection } from "./collections/AccountCollection";
} from "./collections/index.js";
import {
ConnectionState,
EventClient,
EventClientOptions,
handleEventV1,
} from "./events";
} from "./events/index.js";
import {
HydratedChannel,
HydratedEmoji,
HydratedMessage,
HydratedServer,
HydratedServerMember,
HydratedUser,
} from "./hydration";
import { RE_CHANNELS, RE_MENTIONS, RE_SPOILER } from "./lib/regex";
} from "./hydration/index.js";
import { RE_CHANNELS, RE_MENTIONS, RE_SPOILER } from "./lib/regex.js";

export type Session = { _id: string; token: string; user_id: string } | string;

Expand Down
2 changes: 1 addition & 1 deletion src/classes/Bot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataEditBot } from "revolt-api";
import { decodeTime } from "ulid";

import { BotCollection } from "../collections";
import { BotCollection } from "../collections/index.js";

/**
* Bot Class
Expand Down
11 changes: 7 additions & 4 deletions src/classes/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import type {
import { APIRoutes } from "revolt-api/dist/routes";
import { decodeTime, ulid } from "ulid";

import { Message } from "..";
import { ChannelCollection } from "../collections";
import { bitwiseAndEq, calculatePermission } from "../permissions/calculator";
import { Permission } from "../permissions/definitions";
import { ChannelCollection } from "../collections/index.js";
import { Message } from "../index.js";
import {
bitwiseAndEq,
calculatePermission,
} from "../permissions/calculator.js";
import { Permission } from "../permissions/definitions.js";

/**
* Channel Class
Expand Down
2 changes: 1 addition & 1 deletion src/classes/ChannelUnread.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChannelUnreadCollection } from "../collections";
import { ChannelUnreadCollection } from "../collections/index.js";

/**
* Channel Unread Class
Expand Down
4 changes: 2 additions & 2 deletions src/classes/ChannelWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataEditWebhook } from "revolt-api";

import { ChannelWebhookCollection } from "../collections";
import { hydrate } from "../hydration";
import { ChannelWebhookCollection } from "../collections/index.js";
import { hydrate } from "../hydration/index.js";

/**
* Channel Webhook Class
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Emoji.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeTime } from "ulid";

import { EmojiCollection } from "../collections";
import { EmojiCollection } from "../collections/index.js";

/**
* Emoji Class
Expand Down
2 changes: 1 addition & 1 deletion src/classes/File.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Metadata } from "revolt-api";

import { API, Client } from "..";
import { API, Client } from "../index.js";

/**
* Uploaded File
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Invite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Client } from "..";
import { API, Client } from "../index.js";

/**
* Channel Invite
Expand Down
2 changes: 1 addition & 1 deletion src/classes/MFA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MFATicket as TicketType,
} from "revolt-api";

import { Client } from "..";
import { Client } from "../index.js";

/**
* Multi-Factor Authentication
Expand Down
4 changes: 2 additions & 2 deletions src/classes/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from "revolt-api";
import { decodeTime } from "ulid";

import { Client, File } from "..";
import { MessageCollection } from "../collections";
import { MessageCollection } from "../collections/index.js";
import { Client, File } from "../index.js";

/**
* Message Class
Expand Down
2 changes: 1 addition & 1 deletion src/classes/MessageEmbed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Client, File } from "..";
import { API, Client, File } from "../index.js";

/**
* Message Embed
Expand Down
2 changes: 1 addition & 1 deletion src/classes/PublicBot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Channel, Client, File, Server } from "..";
import { API, Channel, Client, File, Server } from "../index.js";

/**
* Public Bot Class
Expand Down
4 changes: 2 additions & 2 deletions src/classes/PublicInvite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { batch } from "solid-js";

import { API, Client, File } from "..";
import { ServerFlags } from "../hydration/server";
import { ServerFlags } from "../hydration/server.js";
import { API, Client, File } from "../index.js";

/**
* Public Channel Invite
Expand Down
31 changes: 22 additions & 9 deletions src/classes/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import type {
} from "revolt-api";
import { decodeTime } from "ulid";

import { ServerMember, User } from "..";
import { ServerCollection } from "../collections";
import { hydrate } from "../hydration";
import { bitwiseAndEq, calculatePermission } from "../permissions/calculator";
import { Permission } from "../permissions/definitions";

import { Channel } from "./Channel";
import { ChannelInvite } from "./Invite";
import { ServerBan } from "./ServerBan";
import { ServerCollection } from "../collections/index.js";
import { hydrate } from "../hydration/index.js";
import { ServerMember, User } from "../index.js";
import {
bitwiseAndEq,
calculatePermission,
} from "../permissions/calculator.js";
import { Permission } from "../permissions/definitions.js";

import { Channel } from "./Channel.js";
import { ChannelInvite } from "./Invite.js";
import { ServerBan } from "./ServerBan.js";

/**
* Server Class
Expand Down Expand Up @@ -711,4 +714,14 @@ export class Server {
)
);
}

/**
* Delete emoji
* @param emojiId Emoji ID
*/
async deleteEmoji(emojiId: string) {
return await this.#collection.client.api.delete(
`/custom/emoji/${emojiId}`
);
}
}
2 changes: 1 addition & 1 deletion src/classes/ServerBan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemberCompositeKey } from "revolt-api";

import { API, Client } from "..";
import { API, Client } from "../index.js";

/**
* Server Ban
Expand Down
15 changes: 9 additions & 6 deletions src/classes/ServerMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import type {
MemberCompositeKey,
} from "revolt-api";

import { ServerMemberCollection } from "../collections";
import { bitwiseAndEq, calculatePermission } from "../permissions/calculator";
import { Permission } from "../permissions/definitions";

import { Channel } from "./Channel";
import { Server } from "./Server";
import { ServerMemberCollection } from "../collections/index.js";
import {
bitwiseAndEq,
calculatePermission,
} from "../permissions/calculator.js";
import { Permission } from "../permissions/definitions.js";

import { Channel } from "./Channel.js";
import { Server } from "./Server.js";

/**
* Deterministic conversion of member composite key to string ID
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeTime } from "ulid";

import { SessionCollection } from "../collections";
import { SessionCollection } from "../collections/index.js";

/**
* Session Class
Expand Down
2 changes: 1 addition & 1 deletion src/classes/SystemMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Client } from "..";
import { API, Client } from "../index.js";

/**
* System Message
Expand Down
7 changes: 5 additions & 2 deletions src/classes/User.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DataEditUser, Presence } from "revolt-api";
import { decodeTime } from "ulid";

import { UserCollection } from "../collections";
import { U32_MAX, UserPermission } from "../permissions/definitions";
import { UserCollection } from "../collections/index.js";
import { U32_MAX, UserPermission } from "../permissions/definitions.js";

/**
* User Class
Expand Down Expand Up @@ -85,6 +85,9 @@ export class User {
* User Status
*/
get status() {
// TODO: issue with API, upstream fix required #319
if (!this.online)
return { text: undefined, presence: "Invisible" as const };
return this.#collection.getUnderlyingObject(this.id).status;
}

Expand Down
35 changes: 18 additions & 17 deletions src/classes/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export * from "./Bot";
export * from "./Channel";
export * from "./ChannelUnread";
export * from "./ChannelWebhook";
export * from "./Emoji";
export * from "./File";
export * from "./Invite";
export * from "./Message";
export * from "./MessageEmbed";
export * from "./PublicBot";
export * from "./PublicInvite";
export * from "./Server";
export * from "./ServerBan";
export * from "./ServerMember";
export * from "./SystemMessage";
export * from "./Session";
export * from "./User";
export * from "./Bot.js";
export * from "./Channel.js";
export * from "./ChannelUnread.js";
export * from "./ChannelWebhook.js";
export * from "./Emoji.js";
export * from "./File.js";
export * from "./Invite.js";
export * from "./Message.js";
export * from "./MessageEmbed.js";
export * from "./PublicBot.js";
export * from "./PublicInvite.js";
export * from "./Server.js";
export * from "./ServerBan.js";
export * from "./ServerMember.js";
export * from "./Session.js";
export * from "./SystemMessage.js";
export * from "./User.js";

4 changes: 2 additions & 2 deletions src/collections/AccountCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataCreateAccount, WebPushSubscription } from "revolt-api";

import { Client } from "..";
import { MFA } from "../classes/MFA";
import { MFA } from "../classes/MFA.js";
import { Client } from "../index.js";

/**
* Utility functions for working with accounts
Expand Down
6 changes: 3 additions & 3 deletions src/collections/BotCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { batch } from "solid-js";

import { OwnedBotsResponse } from "revolt-api";

import { API, Bot, PublicBot } from "..";
import { HydratedBot } from "../hydration/bot";
import { HydratedBot } from "../hydration/bot.js";
import { API, Bot, PublicBot } from "../index.js";

import { ClassCollection } from ".";
import { ClassCollection } from "./index.js";

/**
* Collection of Bots
Expand Down
10 changes: 5 additions & 5 deletions src/collections/ChannelCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { API, Channel, User } from "..";
import { HydratedChannel } from "../hydration";
import { HydratedChannel } from "../hydration/index.js";
import { API, Channel, User } from "../index.js";

import { ClassCollection } from ".";
import { ClassCollection } from "./index.js";

/**
* Collection of Channels
Expand All @@ -27,7 +27,7 @@ export class ChannelCollection extends ClassCollection<
*/
async fetch(id: string): Promise<Channel> {
const channel = this.get(id);
if (channel) return channel;
if (channel && !this.isPartial(id)) return channel;
const data = await this.client.api.get(`/channels/${id as ""}`);
return this.getOrCreate(data._id, data);
}
Expand All @@ -39,7 +39,7 @@ export class ChannelCollection extends ClassCollection<
* @param isNew Whether this object is new
*/
getOrCreate(id: string, data: API.Channel, isNew = false) {
if (this.has(id)) {
if (this.has(id) && !this.isPartial(id)) {
return this.get(id)!;
} else {
const instance = new Channel(this, id);
Expand Down
8 changes: 4 additions & 4 deletions src/collections/ChannelUnreadCollection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { API } from "..";
import { ChannelUnread } from "../classes/ChannelUnread";
import { HydratedChannelUnread } from "../hydration";
import { ChannelUnread } from "../classes/ChannelUnread.js";
import { HydratedChannelUnread } from "../hydration/index.js";
import { API } from "../index.js";

import { ClassCollection } from ".";
import { ClassCollection } from "./index.js";

/**
* Collection of Channel Unreads
Expand Down
8 changes: 4 additions & 4 deletions src/collections/ChannelWebhookCollection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { API } from "..";
import { ChannelWebhook } from "../classes/ChannelWebhook";
import { HydratedChannelWebhook } from "../hydration/channelWebhook";
import { ChannelWebhook } from "../classes/ChannelWebhook.js";
import { HydratedChannelWebhook } from "../hydration/channelWebhook.js";
import { API } from "../index.js";

import { ClassCollection } from ".";
import { ClassCollection } from "./index.js";

/**
* Collection of Channel Webhooks
Expand Down
Loading
Loading