From 3ba31a794e58dbe6dbd5708046741289547ea5cd Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Fri, 10 May 2024 14:45:59 -0700 Subject: [PATCH] add answer and drawing modules --- src/answer/index.ts | 24 ++++++++++++++++++++++++ src/answer/types.ts | 37 +++++++++++++++++++++++++++++++++++++ src/client.ts | 11 +++++++---- src/index.ts | 4 ++++ 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/answer/index.ts create mode 100644 src/answer/types.ts diff --git a/src/answer/index.ts b/src/answer/index.ts new file mode 100644 index 0000000..16d3cf5 --- /dev/null +++ b/src/answer/index.ts @@ -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, + } + ) + } +} diff --git a/src/answer/types.ts b/src/answer/types.ts new file mode 100644 index 0000000..530b79e --- /dev/null +++ b/src/answer/types.ts @@ -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", +} diff --git a/src/client.ts b/src/client.ts index 9bf99e5..bdfee28 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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. diff --git a/src/index.ts b/src/index.ts index 4e2b584..dd2e0bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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";