add answer and drawing modules
parent
9e638d94f1
commit
3ba31a794e
|
@ -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,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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",
|
||||
}
|
|
@ -3,6 +3,7 @@ import { AskModule } from "./ask";
|
|||
import { MessagesModule } from "./messages";
|
||||
import { ForumModule } from "./forum";
|
||||
import { DrawingModule } from "./drawing";
|
||||
import { AnswerModule } from "./answer";
|
||||
|
||||
interface QueuedCall {
|
||||
methodCall: MethodCall;
|
||||
|
@ -22,6 +23,7 @@ export class Client {
|
|||
#ask: AskModule;
|
||||
#forum: ForumModule;
|
||||
#drawing: DrawingModule;
|
||||
#answer: AnswerModule;
|
||||
|
||||
#requestQueue: QueuedCall[] = [];
|
||||
#isBatching: boolean = false;
|
||||
|
@ -49,6 +51,10 @@ export class Client {
|
|||
return this.#drawing;
|
||||
}
|
||||
|
||||
public get answer(): AnswerModule {
|
||||
return this.#answer;
|
||||
}
|
||||
|
||||
public get isBatching(): boolean {
|
||||
return this.#isBatching;
|
||||
}
|
||||
|
@ -69,12 +75,9 @@ export class Client {
|
|||
this.#ask = new AskModule(this);
|
||||
this.#forum = new ForumModule(this);
|
||||
this.#drawing = new DrawingModule(this);
|
||||
this.#answer = new AnswerModule(this);
|
||||
}
|
||||
|
||||
//public login(username: string, password: string) {
|
||||
// this.call();
|
||||
//}
|
||||
|
||||
/**
|
||||
* Calls an API method.
|
||||
* @param creator The type that should be constructed from the response.
|
||||
|
|
|
@ -7,3 +7,7 @@ export * from "./ask";
|
|||
export * as ask from "./ask/types";
|
||||
export * from "./forum";
|
||||
export * as forum from "./forum/types";
|
||||
export * from "./drawing";
|
||||
export * as drawings from "./drawing/types";
|
||||
export * from "./answer";
|
||||
export * as answer from "./answer/types";
|
||||
|
|
Loading…
Reference in New Issue