add answer and drawing modules

master
John Montagu, the 4th Earl of Sandvich 2024-05-10 14:45:59 -07:00
parent 9e638d94f1
commit 3ba31a794e
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
4 changed files with 72 additions and 4 deletions

View File

@ -0,0 +1,24 @@
import { DismissAction, QuestionFetchResponse } from "./types";
import { Module } from "../module";
import { TCResponse } from "../types";
export class AnswerModule extends Module {
public async fetchNext() {
return await this.client._call(
QuestionFetchResponse,
"answer.getnext",
{ }
);
}
public async dismissQuestion(questionId: number, action: DismissAction) {
return await this.client._call(
TCResponse,
"answer.dismissquestion",
{
questionId,
action: action as string,
}
)
}
}

View File

@ -0,0 +1,37 @@
import { TCResponse, TCResponseRaw } from "../types";
export class QuestionFetchResponse extends TCResponse {
id: number;
time: number;
text: string;
author?: string;
poll?: Poll;
public constructor(res: TCResponseRaw) {
super(res);
this.id = res["id"];
this.time = res["time"];
this.text = res["text"];
this.poll = res["poll"];
this.author = res["author"];
}
}
export interface Poll {
readonly options: PollOption[];
readonly answered: boolean;
}
export interface PollOption {
readonly text: string;
readonly color: string;
readonly votes?: number;
readonly yours?: boolean;
}
export enum DismissAction {
SNOOZE = "SNOOZE",
DISCARD = "DISCARD",
}

View File

@ -3,6 +3,7 @@ import { AskModule } from "./ask";
import { MessagesModule } from "./messages"; import { MessagesModule } from "./messages";
import { ForumModule } from "./forum"; import { ForumModule } from "./forum";
import { DrawingModule } from "./drawing"; import { DrawingModule } from "./drawing";
import { AnswerModule } from "./answer";
interface QueuedCall { interface QueuedCall {
methodCall: MethodCall; methodCall: MethodCall;
@ -22,6 +23,7 @@ export class Client {
#ask: AskModule; #ask: AskModule;
#forum: ForumModule; #forum: ForumModule;
#drawing: DrawingModule; #drawing: DrawingModule;
#answer: AnswerModule;
#requestQueue: QueuedCall[] = []; #requestQueue: QueuedCall[] = [];
#isBatching: boolean = false; #isBatching: boolean = false;
@ -49,6 +51,10 @@ export class Client {
return this.#drawing; return this.#drawing;
} }
public get answer(): AnswerModule {
return this.#answer;
}
public get isBatching(): boolean { public get isBatching(): boolean {
return this.#isBatching; return this.#isBatching;
} }
@ -69,12 +75,9 @@ export class Client {
this.#ask = new AskModule(this); this.#ask = new AskModule(this);
this.#forum = new ForumModule(this); this.#forum = new ForumModule(this);
this.#drawing = new DrawingModule(this); this.#drawing = new DrawingModule(this);
this.#answer = new AnswerModule(this);
} }
//public login(username: string, password: string) {
// this.call();
//}
/** /**
* Calls an API method. * Calls an API method.
* @param creator The type that should be constructed from the response. * @param creator The type that should be constructed from the response.

View File

@ -7,3 +7,7 @@ export * from "./ask";
export * as ask from "./ask/types"; export * as ask from "./ask/types";
export * from "./forum"; export * from "./forum";
export * as forum from "./forum/types"; export * as forum from "./forum/types";
export * from "./drawing";
export * as drawings from "./drawing/types";
export * from "./answer";
export * as answer from "./answer/types";