add forum thread viewing and replying
parent
c46a573596
commit
d2180c8717
|
@ -1,5 +1,6 @@
|
|||
import { AskModule } from "./ask";
|
||||
import { MessagesModule } from "./messages";
|
||||
import { ForumModule } from "./forum";
|
||||
import { MethodCall, TCJSONResponse, TCResponse, TCResponseRaw } from "./types";
|
||||
|
||||
/**
|
||||
|
@ -11,6 +12,7 @@ export class Client {
|
|||
|
||||
#messages: MessagesModule;
|
||||
#ask: AskModule;
|
||||
#forum: ForumModule;
|
||||
|
||||
/** @internal */
|
||||
public _cache: { [key: string]: any; } = { };
|
||||
|
@ -27,12 +29,17 @@ export class Client {
|
|||
return this.#ask;
|
||||
}
|
||||
|
||||
public get forum(): ForumModule {
|
||||
return this.#forum;
|
||||
}
|
||||
|
||||
public constructor(auth?: string) {
|
||||
this.auth = auth;
|
||||
|
||||
// init modules
|
||||
this.#messages = new MessagesModule(this);
|
||||
this.#ask = new AskModule(this);
|
||||
this.#forum = new ForumModule(this);
|
||||
}
|
||||
|
||||
//public login(username: string, password: string) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import { Module } from "../module";
|
||||
import { TCResponse } from "../types";
|
||||
import { ViewPostsResponse } from "./types";
|
||||
|
||||
export class ForumModule extends Module {
|
||||
public async viewPosts(
|
||||
threadId: number,
|
||||
fetchType: string,
|
||||
postId = 0,
|
||||
reverse = false,
|
||||
includePost = true,
|
||||
) {
|
||||
return await this.client._call(
|
||||
ViewPostsResponse,
|
||||
"forum.viewposts",
|
||||
{
|
||||
getSomeBackscroll: reverse,
|
||||
includePost,
|
||||
threadId,
|
||||
postId,
|
||||
type: fetchType,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public async replyThread(text: string, threadId: number) {
|
||||
return await this.client._call(
|
||||
TCResponse,
|
||||
"forum.replythread",
|
||||
{
|
||||
text,
|
||||
threadId,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { TCResponse, TCResponseRaw } from "../types";
|
||||
|
||||
export class ViewPostsResponse extends TCResponse {
|
||||
posts: Post[];
|
||||
numPostsBefore: number;
|
||||
numPostsAfter: number;
|
||||
jumpTo: number;
|
||||
|
||||
public constructor(response: TCResponseRaw) {
|
||||
super(response);
|
||||
this.posts = response["posts"] ?? [];
|
||||
this.numPostsBefore = response["numPostsBefore"] ?? 0;
|
||||
this.numPostsAfter = response["numPostsAfter"] ?? 0;
|
||||
this.jumpTo = response["jumpTo"] ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Post {
|
||||
readonly id: number;
|
||||
readonly user: string;
|
||||
readonly text: string;
|
||||
readonly time: number;
|
||||
}
|
|
@ -5,3 +5,5 @@ export * from "./messages";
|
|||
export * as messages from "./messages/types";
|
||||
export * from "./ask";
|
||||
export * as ask from "./ask/types";
|
||||
export * from "./forum";
|
||||
export * as forum from "./forum/types";
|
||||
|
|
Loading…
Reference in New Issue