@haelp/teto
Version:
A typescript-based controllable TETR.IO client.
1 lines • 3.83 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/classes/social/relationship.ts"],"sourcesContent":["import { Social } from \".\";\nimport type { Social as SocialTypes } from \"../../types\";\nimport { Client } from \"../client\";\n\nexport class Relationship {\n private social: Social;\n private client: Client;\n\n /** ID of the account on the other side of the relationsihp */\n id: string;\n /** ID of the relationship */\n relationshipID: string;\n /** Username of the account on the other side of the relationship */\n username: string;\n /** Avatar ID of the account on the other side of the relationship */\n avatar: number;\n /** The DMs that have been sent and received. You may need to call `loadDms` to populate this information */\n dms: SocialTypes.DM[];\n\n /** Promise that resolves when the dms have been loaded. This will not resovle if `Relationship.lazyLoadDms` is set to true. */\n ready: Promise<void>;\n /** Whether or not the dms have been loaded */\n dmsLoaded = false;\n\n static lazyLoadDms = true;\n\n constructor(\n options: {\n id: string;\n relationshipID: string;\n username: string;\n avatar: number;\n },\n social: Social,\n client: Client\n ) {\n this.id = options.id;\n this.relationshipID = options.relationshipID;\n this.username = options.username;\n this.avatar = options.avatar;\n\n this.social = social;\n this.client = client;\n\n this.dms = [];\n\n this.ready = Relationship.lazyLoadDms\n ? new Promise<never>(() => {})\n : new Promise<void>(async (resolve) => {\n await this.loadDms();\n resolve();\n });\n }\n\n /**\n * Send a dm to the user.\n * @example\n * relationship.dm(\"Hello!\");\n */\n async dm(content: string) {\n await this.social.dm(this.id, content);\n }\n\n /**\n * Mark the dms as read\n * @example\n * relationship.markAsRead();\n */\n markAsRead() {\n this.client.emit(\"social.relation.ack\", this.id);\n }\n\n /**\n * Load the DMs for this relationship\n * @example\n * await relationship.loadDms();\n */\n async loadDms() {\n const dms = (await this.client.api.social.dms(this.id)).reverse();\n this.dms = dms;\n this.dmsLoaded = true;\n return dms;\n }\n\n /**\n * Invite the user to a game\n * @example\n * relationship.invite();\n */\n invite() {\n this.social.invite(this.id);\n }\n}\n"],"names":["Relationship","social","client","id","relationshipID","username","avatar","dms","ready","dmsLoaded","lazyLoadDms","options","Promise","resolve","loadDms","dm","content","markAsRead","emit","api","reverse","invite"],"mappings":"AAIA,OAAO,MAAMA;IACHC,OAAe;IACfC,OAAe;IAEvB,4DAA4D,GAC5DC,GAAW;IACX,2BAA2B,GAC3BC,eAAuB;IACvB,kEAAkE,GAClEC,SAAiB;IACjB,mEAAmE,GACnEC,OAAe;IACf,0GAA0G,GAC1GC,IAAsB;IAEtB,6HAA6H,GAC7HC,MAAqB;IACrB,4CAA4C,GAC5CC,YAAY,MAAM;IAElB,OAAOC,cAAc,KAAK;IAE1B,YACEC,OAKC,EACDV,MAAc,EACdC,MAAc,CACd;QACA,IAAI,CAACC,EAAE,GAAGQ,QAAQR,EAAE;QACpB,IAAI,CAACC,cAAc,GAAGO,QAAQP,cAAc;QAC5C,IAAI,CAACC,QAAQ,GAAGM,QAAQN,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGK,QAAQL,MAAM;QAE5B,IAAI,CAACL,MAAM,GAAGA;QACd,IAAI,CAACC,MAAM,GAAGA;QAEd,IAAI,CAACK,GAAG,GAAG,EAAE;QAEb,IAAI,CAACC,KAAK,GAAGR,aAAaU,WAAW,GACjC,IAAIE,QAAe,KAAO,KAC1B,IAAIA,QAAc,OAAOC;YACvB,MAAM,IAAI,CAACC,OAAO;YAClBD;QACF;IACN;IAEA;;;;GAIC,GACD,MAAME,GAAGC,OAAe,EAAE;QACxB,MAAM,IAAI,CAACf,MAAM,CAACc,EAAE,CAAC,IAAI,CAACZ,EAAE,EAAEa;IAChC;IAEA;;;;GAIC,GACDC,aAAa;QACX,IAAI,CAACf,MAAM,CAACgB,IAAI,CAAC,uBAAuB,IAAI,CAACf,EAAE;IACjD;IAEA;;;;GAIC,GACD,MAAMW,UAAU;QACd,MAAMP,MAAM,AAAC,CAAA,MAAM,IAAI,CAACL,MAAM,CAACiB,GAAG,CAAClB,MAAM,CAACM,GAAG,CAAC,IAAI,CAACJ,EAAE,CAAA,EAAGiB,OAAO;QAC/D,IAAI,CAACb,GAAG,GAAGA;QACX,IAAI,CAACE,SAAS,GAAG;QACjB,OAAOF;IACT;IAEA;;;;GAIC,GACDc,SAAS;QACP,IAAI,CAACpB,MAAM,CAACoB,MAAM,CAAC,IAAI,CAAClB,EAAE;IAC5B;AACF"}