mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
so far so good
This commit is contained in:
parent
9cd9d307c5
commit
0dcbdbdef7
@ -1,4 +1,7 @@
|
|||||||
// structures
|
// structures
|
||||||
|
import { Session } from "./Session.ts";
|
||||||
|
export default Session;
|
||||||
|
|
||||||
export * from "./structures/Attachment.ts";
|
export * from "./structures/Attachment.ts";
|
||||||
export * from "./structures/Base.ts";
|
export * from "./structures/Base.ts";
|
||||||
export * from "./structures/Embed.ts";
|
export * from "./structures/Embed.ts";
|
||||||
|
@ -361,6 +361,18 @@ export class Message implements Model {
|
|||||||
return new Message(this.session, message);
|
return new Message(this.session, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetch() {
|
||||||
|
const message = await this.session.rest.runMethod<DiscordMessage>(
|
||||||
|
this.session.rest,
|
||||||
|
"GET",
|
||||||
|
Routes.CHANNEL_MESSAGE(this.channelId, this.message),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!message?.id) return;
|
||||||
|
|
||||||
|
return new Message(this.session, message);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* alias of Message.crosspost
|
* alias of Message.crosspost
|
||||||
* */
|
* */
|
||||||
|
0
packages/cache/Channels.ts
vendored
Normal file
0
packages/cache/Channels.ts
vendored
Normal file
14
packages/cache/Collection.ts
vendored
Normal file
14
packages/cache/Collection.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import type { Session } from "./deps.ts";
|
||||||
|
|
||||||
|
export class Collection<K, V> extends Map<K, V> {
|
||||||
|
constructor(session: Session, entries: Iterable<readonly [K, V]>) {
|
||||||
|
super(entries);
|
||||||
|
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reference to a session */
|
||||||
|
readonly session: Session;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Collection;
|
0
packages/cache/Guilds.ts
vendored
Normal file
0
packages/cache/Guilds.ts
vendored
Normal file
0
packages/cache/Members.ts
vendored
Normal file
0
packages/cache/Members.ts
vendored
Normal file
43
packages/cache/Messages.ts
vendored
Normal file
43
packages/cache/Messages.ts
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import type { DiscordMessage, Session } from "./deps.ts";
|
||||||
|
import { Message } from "./deps.ts";
|
||||||
|
import { Collection } from "./Collection.ts";
|
||||||
|
|
||||||
|
export class CachedMessage extends Message {
|
||||||
|
constructor(session: Session, data: DiscordMessage) {
|
||||||
|
super(session, data);
|
||||||
|
|
||||||
|
CachedMessage.from(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_id!: bigint;
|
||||||
|
|
||||||
|
static from(message: Message): CachedMessage {
|
||||||
|
const target: CachedMessage = Object.assign(message, { _id: BigInt(message.id) });
|
||||||
|
|
||||||
|
Object.defineProperty(target, "id", {
|
||||||
|
get(this: CachedMessage) {
|
||||||
|
return String(this._id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MessageCache extends Collection<bigint, CachedMessage> {
|
||||||
|
constructor(session: Session, entries: Iterable<readonly [bigint, Message]>) {
|
||||||
|
super(session, entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetch(channelId: bigint, id: bigint) {
|
||||||
|
const message = this.get(id) ?? await Message.prototype.fetch.call({
|
||||||
|
session: this.session,
|
||||||
|
channelId: String(channelId),
|
||||||
|
id: String(id)
|
||||||
|
});
|
||||||
|
|
||||||
|
return CachedMessage.from(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MessageCache;
|
33
packages/cache/Users.ts
vendored
Normal file
33
packages/cache/Users.ts
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { DiscordUser, Session } from "./deps.ts";
|
||||||
|
import { User } from "./deps.ts";
|
||||||
|
import { Collection } from "./Collection.ts";
|
||||||
|
|
||||||
|
export class CachedUser extends User {
|
||||||
|
constructor(session: Session, data: DiscordUser) {
|
||||||
|
super(session, data);
|
||||||
|
|
||||||
|
CachedUser.from(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_id!: bigint;
|
||||||
|
|
||||||
|
static from(user: User): CachedUser {
|
||||||
|
const target: CachedUser = Object.assign(user, { _id: BigInt(user.id) });
|
||||||
|
|
||||||
|
Object.defineProperty(target, "id", {
|
||||||
|
get(this: CachedUser) {
|
||||||
|
return String(this._id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UserCache extends Collection<bigint, CachedUser> {
|
||||||
|
constructor(session: Session, entries: Iterable<readonly [bigint, User]>) {
|
||||||
|
super(session, entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserCache;
|
2
packages/cache/deps.ts
vendored
Normal file
2
packages/cache/deps.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from "../biscuit/mod.ts";
|
||||||
|
export * from "../discordeno/mod.ts";
|
0
packages/cache/mod.ts
vendored
Normal file
0
packages/cache/mod.ts
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user