serchat.ts 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -426,7 +426,7 @@ export type MessageReaction = {
426
426
  emojiUrl?: string;
427
427
  };
428
428
  export interface IMessageServer {
429
- messageId: string;
429
+ messageId?: string;
430
430
  id: string;
431
431
  serverId: string;
432
432
  channelId: string;
@@ -876,9 +876,9 @@ export declare class EmbedBuilder {
876
876
  * like replying, reacting, and deleting.
877
877
  */
878
878
  export declare class Message implements IMessageServer {
879
- /** Primary message identifier. Normalised from either `messageId` or `id`. */
879
+ /** Compatibility alias for the public message id. */
880
880
  messageId: string;
881
- /** MongoDB `id` field. */
881
+ /** Public message identifier. */
882
882
  id: string;
883
883
  /** ID of the server this message belongs to. */
884
884
  serverId: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{EventEmitter as de}from"events";var X=class extends Error{constructor(e){super(e),this.name="SerchatError"}},m=class extends X{status;data;headers;response;constructor(e,t,s){let r=typeof t=="string"?`"${t}"`:t&&typeof t=="object"&&!Array.isArray(t)&&"message"in t?`"${t.message}"`:JSON.stringify(t);if(super(`Serchat API Error (${e}): ${r}`),this.status=e,this.data=t,this.response=s,this.headers={},this.name="APIError",s){let i=["authorization","cookie","set-cookie","x-csrf-token"];s.headers.forEach((n,o)=>{i.includes(o.toLowerCase())?this.headers[o]="[REDACTED]":this.headers[o]=n})}}},C=class extends m{constructor(e,t){super(400,e,t),this.name="BadRequestError"}},R=class extends m{constructor(e,t){super(401,e,t),this.name="UnauthorizedError"}},k=class extends m{constructor(e,t){super(403,e,t),this.name="ForbiddenError"}},M=class extends m{constructor(e,t){super(404,e,t),this.name="NotFoundError"}},x=class extends m{constructor(e,t){super(429,e,t),this.name="RateLimitError"}},T=class extends m{constructor(e,t){super(500,e,t),this.name="InternalServerError"}},$=class extends m{constructor(e,t){super(502,e,t),this.name="BadGatewayError"}},U=class extends m{constructor(e,t){super(503,e,t),this.name="ServiceUnavailableError"}},O=class extends m{constructor(e,t){super(504,e,t),this.name="GatewayTimeoutError"}};function u({data:a}){if(a===null)throw new Error("Expected data but received empty response (204)");return a}var A=class a{options;_headers;_pending;interceptors={request:[],response:[],error:[]};constructor(e,t){let s=e.baseURL.trim();if(s!==e.baseURL&&console.warn("RESTClient: baseURL contains leading/trailing whitespace"),!s.startsWith("http://")&&!s.startsWith("https://"))throw new Error("baseURL must be an absolute URL starting with http:// or https://");let r=s.endsWith("/")?s:s+"/";this.options={...e,baseURL:r},this._headers=Object.fromEntries(Object.entries(e.headers??{}).filter(([,i])=>i!==void 0)),this._pending=t||new Set}get headers(){return Object.fromEntries(Object.entries(this._headers).filter(e=>e[1]!==void 0))}setDefaultHeader(e,t){t===void 0?delete this._headers[e]:this._headers[e]=t}scoped(e){let t=new a({...this.options,headers:{...this._headers},baseURL:this.buildURL(e)+"/"},this._pending);return t.interceptors.request=this.interceptors.request,t.interceptors.response=this.interceptors.response,t.interceptors.error=this.interceptors.error,t}abortAll(){for(let e of this._pending)e.abort();this._pending.clear()}buildURL(e){let t=new URL(e.replace(/^\/+/,""),this.options.baseURL);if(!t.href.startsWith(this.options.baseURL))throw new Error(`Path "${e}" escapes baseURL`);return t.href}combineSignals(e){if("any"in AbortSignal&&typeof AbortSignal.any=="function")return AbortSignal.any(e);let t=new AbortController,s=[];t.signal.addEventListener("abort",()=>{for(let r of s)r()},{once:!0});for(let r of e){if(r.aborted){t.abort(r.reason);break}let i=()=>t.abort(r.reason);r.addEventListener("abort",i,{once:!0}),s.push(()=>r.removeEventListener("abort",i))}return t.signal}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}limitResponseBody(e,t){if(!e.body)return e;let s=0,r=t,i=e,n=e.body.pipeThrough(new TransformStream({transform(o,h){s+=o.byteLength,s>r?h.error(new m(413,{error:"Response too large",message:`Body exceeded limit of ${r} bytes`},i)):h.enqueue(o)}}));return new Response(n,{status:e.status,statusText:e.statusText,headers:e.headers})}async request(e,t){let s;try{s=this.buildURL(e)}catch(l){return Promise.reject(l)}let r={...t,url:s,headers:{}},i={},n=l=>{if(l)for(let[y,d]of Object.entries(l))d!==void 0?i[y]=d:delete i[y]};n(this._headers),n(t.headers);let o=["POST","PUT","PATCH","DELETE"].includes(t.method||"GET"),h=new URL(s).origin===(typeof window<"u"?window.location.origin:new URL(this.options.baseURL).origin);if(o&&h&&this.options.csrfCookieName&&this.options.csrfHeaderName){let l=this.getCookie(this.options.csrfCookieName);l&&(i[this.options.csrfHeaderName]=l)}r.headers=i;for(let l of this.interceptors.request)r=l(r);let b=async l=>{let y=t.timeout??this.options.timeout,d=new AbortController;this._pending.add(d);let c;y&&(c=setTimeout(()=>{d.abort(new DOMException("Request timed out","TimeoutError"))},y));let f=r.signal?this.combineSignals([r.signal,d.signal]):d.signal;try{let p=await fetch(r.url,{...r,credentials:this.options.credentials||"same-origin",redirect:this.options.redirect??"error",signal:f});for(let I of this.interceptors.response)p=await I(p);if(this.options.maxResponseBytes!==void 0&&(p=this.limitResponseBody(p,this.options.maxResponseBytes)),!p.ok){let I;if(p.headers.get("Content-Type")?.includes("application/json"))try{I=await p.json()}catch{I=await p.text()}else I=await p.text();let ie=typeof I=="string"?{error:"Non-JSON response",message:I}:I,H=this.mapError(p.status,ie,p),w=this.options.retry;if(w&&l<w.maxAttempts&&(w.retryOn||[429,500,502,503,504]).includes(p.status)){let oe=w.backoff?w.backoff(l):1e3*Math.pow(2,l-1);if(await new Promise((ae,le)=>{let ce=setTimeout(ae,oe);d.signal.addEventListener("abort",()=>{clearTimeout(ce),le(d.signal.reason)},{once:!0})}),d.signal.aborted)throw d.signal.reason;return await b(l+1)}let S=H,ne=typeof r.headers=="object"&&r.headers!==null&&!Array.isArray(r.headers)?r.headers.Authorization:void 0;for(let Z of this.interceptors.error)S=await Z(S);let G=this._headers.Authorization;if(p.status===401&&l<2&&G!==void 0&&G!==ne)return r.headers={...r.headers,Authorization:G},await b(l+1);throw S instanceof m||(S=new m(H.status??0,{error:"Interceptor returned invalid error type"},H.response)),S}if(p.status===204)return null;let F;try{F=await p.json()}catch{throw new m(p.status,{error:"Invalid JSON in response"},p)}return this.options.transformResponse?this.options.transformResponse(F,p):F}finally{c&&clearTimeout(c),this._pending.delete(d)}};return b(1)}getCookie(e){if(typeof document>"u")return;let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${this.escapeRegExp(e)}=([^;]*)`));return t?decodeURIComponent(t[1]):void 0}serializeParams(e,t=""){let s=[];for(let[r,i]of Object.entries(e)){let n=t?`${t}[${r}]`:r;if(i!=null)if(Array.isArray(i))for(let[o,h]of i.entries())if(h!==null&&typeof h=="object"){let b=this.serializeParams(h,`${n}[${o}]`);b&&s.push(b)}else s.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(h))}`);else if(typeof i=="object"&&i!==null&&!Array.isArray(i)&&(Object.getPrototypeOf(i)===Object.prototype||Object.getPrototypeOf(i)===null)){let o=this.serializeParams(i,n);o&&s.push(o)}else s.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(i))}`)}return s.join("&")}mapError(e,t,s){switch(e){case 400:return new C(t,s);case 401:return new R(t,s);case 403:return new k(t,s);case 404:return new M(t,s);case 429:return new x(t,s);case 500:return new T(t,s);case 502:return new $(t,s);case 503:return new U(t,s);case 504:return new O(t,s);default:return new m(e,t,s)}}async get(e,t){let s=e;if(t?.params){let i=this.serializeParams(t.params);i&&(s+=(s.includes("?")?"&":"?")+i)}return{data:await this.request(s,{method:"GET",headers:t?.headers,signal:t?.signal,timeout:t?.timeout})}}async mutate(e,t,s,r){let i=s instanceof FormData,n=s instanceof Blob||s instanceof ArrayBuffer||typeof ReadableStream<"u"&&s instanceof ReadableStream,o=s!==void 0&&!i&&!n;return{data:await this.request(t,{method:e,headers:{...o?{"Content-Type":"application/json"}:{},...r?.headers},body:i||n?s:s!==void 0?JSON.stringify(s):void 0,signal:r?.signal,timeout:r?.timeout})}}async post(e,t,s){return this.mutate("POST",e,t,s)}async put(e,t,s){return this.mutate("PUT",e,t,s)}async patch(e,t,s){return this.mutate("PATCH",e,t,s)}async delete(e,t,s){return this.mutate("DELETE",e,t,s)}};import Y from"ws";import Q from"node:crypto";var g=class{data;constructor(e){this.data=e??{type:"rich"}}setTitle(e){return this.data.title=e,this}setDescription(e){return this.data.description=e,this}setURL(e){return this.data.url=e,this}setColor(e){return this.data.color=e,this}setTimestamp(e=new Date){return e instanceof Date?this.data.timestamp=e.toISOString():typeof e=="number"?this.data.timestamp=new Date(e).toISOString():this.data.timestamp=e,this}setAuthor(e){return this.data.author=e??void 0,this}setFooter(e){return this.data.footer=e??void 0,this}setThumbnail(e,t,s){return this.data.thumbnail=e?{url:e,width:t,height:s}:void 0,this}setImage(e,t,s){return this.data.image=e?{url:e,width:t,height:s}:void 0,this}addFields(...e){return this.data.fields||(this.data.fields=[]),this.data.fields.push(...e),this}setFields(...e){return this.data.fields=e,this}toJSON(){return{...this.data}}};var E=class{messageId;id;serverId;channelId;senderId;senderUsername;text;createdAt;replyToId;repliedTo;isEdited;isPinned;isSticky;isWebhook;webhookUsername;webhookAvatarUrl;embeds;components;attachments;reactions;interaction;poll;stickerId;senderIsBot;client;constructor(e,t){this.client=e;let s=t.messageId??t.id;if(!s)throw new Error("Message payload is missing both messageId and id");this.messageId=s,this.id=t.id??s,this.serverId=t.serverId,this.channelId=t.channelId,this.senderId=t.senderId,this.senderUsername=t.senderUsername,this.text=t.text,this.createdAt=t.createdAt,this.replyToId=t.replyToId,this.repliedTo=t.repliedTo,this.isEdited=t.isEdited,this.isPinned=t.isPinned,this.isSticky=t.isSticky,this.isWebhook=t.isWebhook,this.webhookUsername=t.webhookUsername,this.webhookAvatarUrl=t.webhookAvatarUrl,this.embeds=t.embeds??[],this.components=t.components??[],this.attachments=t.attachments??[],this.reactions=t.reactions??[],this.interaction=t.interaction??null,this.poll=t.poll??null,this.stickerId=t.stickerId??null,this.senderIsBot=t.senderIsBot??!1}async reply(e){let t;return e instanceof g?t={embeds:[e.toJSON()],replyToId:this.messageId}:typeof e=="string"?t={content:e,replyToId:this.messageId}:t={...e,replyToId:this.messageId},this.client.sendMessage(this.serverId,this.channelId,t)}async react(e){return this.client.reactToMessage(this.serverId,this.channelId,this.messageId,e)}async delete(){return this.client.deleteMessage(this.serverId,this.channelId,this.messageId)}async vote(e){return this.client.votePoll(this.serverId,this.channelId,this.messageId,e)}hasAttachments(){return Array.isArray(this.attachments)&&this.attachments.length>0}getAttachmentUrl(e){return`${this.client.getApiOrigin()}/api/v1/files/download/${encodeURIComponent(e.attachmentId)}`}getAttachmentsByType(e){return this.attachments.filter(t=>t.type===e)}get isEmpty(){return!this.text.trim()}get isOwnMessage(){return this.client.user?.id===this.senderId}get isFromBot(){return this.senderIsBot||this.isOwnMessage}};var P=class{content="";indentation=0;constructor(e="graph TD"){this.content=e+`
1
+ import{EventEmitter as de}from"events";var X=class extends Error{constructor(e){super(e),this.name="SerchatError"}},m=class extends X{status;data;headers;response;constructor(e,t,s){let r=typeof t=="string"?`"${t}"`:t&&typeof t=="object"&&!Array.isArray(t)&&"message"in t?`"${t.message}"`:JSON.stringify(t);if(super(`Serchat API Error (${e}): ${r}`),this.status=e,this.data=t,this.response=s,this.headers={},this.name="APIError",s){let i=["authorization","cookie","set-cookie","x-csrf-token"];s.headers.forEach((n,o)=>{i.includes(o.toLowerCase())?this.headers[o]="[REDACTED]":this.headers[o]=n})}}},C=class extends m{constructor(e,t){super(400,e,t),this.name="BadRequestError"}},R=class extends m{constructor(e,t){super(401,e,t),this.name="UnauthorizedError"}},k=class extends m{constructor(e,t){super(403,e,t),this.name="ForbiddenError"}},M=class extends m{constructor(e,t){super(404,e,t),this.name="NotFoundError"}},x=class extends m{constructor(e,t){super(429,e,t),this.name="RateLimitError"}},T=class extends m{constructor(e,t){super(500,e,t),this.name="InternalServerError"}},$=class extends m{constructor(e,t){super(502,e,t),this.name="BadGatewayError"}},U=class extends m{constructor(e,t){super(503,e,t),this.name="ServiceUnavailableError"}},O=class extends m{constructor(e,t){super(504,e,t),this.name="GatewayTimeoutError"}};function u({data:a}){if(a===null)throw new Error("Expected data but received empty response (204)");return a}var A=class a{options;_headers;_pending;interceptors={request:[],response:[],error:[]};constructor(e,t){let s=e.baseURL.trim();if(s!==e.baseURL&&console.warn("RESTClient: baseURL contains leading/trailing whitespace"),!s.startsWith("http://")&&!s.startsWith("https://"))throw new Error("baseURL must be an absolute URL starting with http:// or https://");let r=s.endsWith("/")?s:s+"/";this.options={...e,baseURL:r},this._headers=Object.fromEntries(Object.entries(e.headers??{}).filter(([,i])=>i!==void 0)),this._pending=t||new Set}get headers(){return Object.fromEntries(Object.entries(this._headers).filter(e=>e[1]!==void 0))}setDefaultHeader(e,t){t===void 0?delete this._headers[e]:this._headers[e]=t}scoped(e){let t=new a({...this.options,headers:{...this._headers},baseURL:this.buildURL(e)+"/"},this._pending);return t.interceptors.request=this.interceptors.request,t.interceptors.response=this.interceptors.response,t.interceptors.error=this.interceptors.error,t}abortAll(){for(let e of this._pending)e.abort();this._pending.clear()}buildURL(e){let t=new URL(e.replace(/^\/+/,""),this.options.baseURL);if(!t.href.startsWith(this.options.baseURL))throw new Error(`Path "${e}" escapes baseURL`);return t.href}combineSignals(e){if("any"in AbortSignal&&typeof AbortSignal.any=="function")return AbortSignal.any(e);let t=new AbortController,s=[];t.signal.addEventListener("abort",()=>{for(let r of s)r()},{once:!0});for(let r of e){if(r.aborted){t.abort(r.reason);break}let i=()=>t.abort(r.reason);r.addEventListener("abort",i,{once:!0}),s.push(()=>r.removeEventListener("abort",i))}return t.signal}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}limitResponseBody(e,t){if(!e.body)return e;let s=0,r=t,i=e,n=e.body.pipeThrough(new TransformStream({transform(o,h){s+=o.byteLength,s>r?h.error(new m(413,{error:"Response too large",message:`Body exceeded limit of ${r} bytes`},i)):h.enqueue(o)}}));return new Response(n,{status:e.status,statusText:e.statusText,headers:e.headers})}async request(e,t){let s;try{s=this.buildURL(e)}catch(l){return Promise.reject(l)}let r={...t,url:s,headers:{}},i={},n=l=>{if(l)for(let[y,d]of Object.entries(l))d!==void 0?i[y]=d:delete i[y]};n(this._headers),n(t.headers);let o=["POST","PUT","PATCH","DELETE"].includes(t.method||"GET"),h=new URL(s).origin===(typeof window<"u"?window.location.origin:new URL(this.options.baseURL).origin);if(o&&h&&this.options.csrfCookieName&&this.options.csrfHeaderName){let l=this.getCookie(this.options.csrfCookieName);l&&(i[this.options.csrfHeaderName]=l)}r.headers=i;for(let l of this.interceptors.request)r=l(r);let b=async l=>{let y=t.timeout??this.options.timeout,d=new AbortController;this._pending.add(d);let c;y&&(c=setTimeout(()=>{d.abort(new DOMException("Request timed out","TimeoutError"))},y));let f=r.signal?this.combineSignals([r.signal,d.signal]):d.signal;try{let p=await fetch(r.url,{...r,credentials:this.options.credentials||"same-origin",redirect:this.options.redirect??"error",signal:f});for(let I of this.interceptors.response)p=await I(p);if(this.options.maxResponseBytes!==void 0&&(p=this.limitResponseBody(p,this.options.maxResponseBytes)),!p.ok){let I;if(p.headers.get("Content-Type")?.includes("application/json"))try{I=await p.json()}catch{I=await p.text()}else I=await p.text();let ie=typeof I=="string"?{error:"Non-JSON response",message:I}:I,H=this.mapError(p.status,ie,p),w=this.options.retry;if(w&&l<w.maxAttempts&&(w.retryOn||[429,500,502,503,504]).includes(p.status)){let oe=w.backoff?w.backoff(l):1e3*Math.pow(2,l-1);if(await new Promise((ae,le)=>{let ce=setTimeout(ae,oe);d.signal.addEventListener("abort",()=>{clearTimeout(ce),le(d.signal.reason)},{once:!0})}),d.signal.aborted)throw d.signal.reason;return await b(l+1)}let S=H,ne=typeof r.headers=="object"&&r.headers!==null&&!Array.isArray(r.headers)?r.headers.Authorization:void 0;for(let Z of this.interceptors.error)S=await Z(S);let G=this._headers.Authorization;if(p.status===401&&l<2&&G!==void 0&&G!==ne)return r.headers={...r.headers,Authorization:G},await b(l+1);throw S instanceof m||(S=new m(H.status??0,{error:"Interceptor returned invalid error type"},H.response)),S}if(p.status===204)return null;let F;try{F=await p.json()}catch{throw new m(p.status,{error:"Invalid JSON in response"},p)}return this.options.transformResponse?this.options.transformResponse(F,p):F}finally{c&&clearTimeout(c),this._pending.delete(d)}};return b(1)}getCookie(e){if(typeof document>"u")return;let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${this.escapeRegExp(e)}=([^;]*)`));return t?decodeURIComponent(t[1]):void 0}serializeParams(e,t=""){let s=[];for(let[r,i]of Object.entries(e)){let n=t?`${t}[${r}]`:r;if(i!=null)if(Array.isArray(i))for(let[o,h]of i.entries())if(h!==null&&typeof h=="object"){let b=this.serializeParams(h,`${n}[${o}]`);b&&s.push(b)}else s.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(h))}`);else if(typeof i=="object"&&i!==null&&!Array.isArray(i)&&(Object.getPrototypeOf(i)===Object.prototype||Object.getPrototypeOf(i)===null)){let o=this.serializeParams(i,n);o&&s.push(o)}else s.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(i))}`)}return s.join("&")}mapError(e,t,s){switch(e){case 400:return new C(t,s);case 401:return new R(t,s);case 403:return new k(t,s);case 404:return new M(t,s);case 429:return new x(t,s);case 500:return new T(t,s);case 502:return new $(t,s);case 503:return new U(t,s);case 504:return new O(t,s);default:return new m(e,t,s)}}async get(e,t){let s=e;if(t?.params){let i=this.serializeParams(t.params);i&&(s+=(s.includes("?")?"&":"?")+i)}return{data:await this.request(s,{method:"GET",headers:t?.headers,signal:t?.signal,timeout:t?.timeout})}}async mutate(e,t,s,r){let i=s instanceof FormData,n=s instanceof Blob||s instanceof ArrayBuffer||typeof ReadableStream<"u"&&s instanceof ReadableStream,o=s!==void 0&&!i&&!n;return{data:await this.request(t,{method:e,headers:{...o?{"Content-Type":"application/json"}:{},...r?.headers},body:i||n?s:s!==void 0?JSON.stringify(s):void 0,signal:r?.signal,timeout:r?.timeout})}}async post(e,t,s){return this.mutate("POST",e,t,s)}async put(e,t,s){return this.mutate("PUT",e,t,s)}async patch(e,t,s){return this.mutate("PATCH",e,t,s)}async delete(e,t,s){return this.mutate("DELETE",e,t,s)}};import Y from"ws";import Q from"node:crypto";var g=class{data;constructor(e){this.data=e??{type:"rich"}}setTitle(e){return this.data.title=e,this}setDescription(e){return this.data.description=e,this}setURL(e){return this.data.url=e,this}setColor(e){return this.data.color=e,this}setTimestamp(e=new Date){return e instanceof Date?this.data.timestamp=e.toISOString():typeof e=="number"?this.data.timestamp=new Date(e).toISOString():this.data.timestamp=e,this}setAuthor(e){return this.data.author=e??void 0,this}setFooter(e){return this.data.footer=e??void 0,this}setThumbnail(e,t,s){return this.data.thumbnail=e?{url:e,width:t,height:s}:void 0,this}setImage(e,t,s){return this.data.image=e?{url:e,width:t,height:s}:void 0,this}addFields(...e){return this.data.fields||(this.data.fields=[]),this.data.fields.push(...e),this}setFields(...e){return this.data.fields=e,this}toJSON(){return{...this.data}}};var E=class{messageId;id;serverId;channelId;senderId;senderUsername;text;createdAt;replyToId;repliedTo;isEdited;isPinned;isSticky;isWebhook;webhookUsername;webhookAvatarUrl;embeds;components;attachments;reactions;interaction;poll;stickerId;senderIsBot;client;constructor(e,t){this.client=e;let s=t.id??t.messageId;if(!s)throw new Error("Message payload is missing id");this.id=s,this.messageId=t.messageId??s,this.serverId=t.serverId,this.channelId=t.channelId,this.senderId=t.senderId,this.senderUsername=t.senderUsername,this.text=t.text,this.createdAt=t.createdAt,this.replyToId=t.replyToId,this.repliedTo=t.repliedTo,this.isEdited=t.isEdited,this.isPinned=t.isPinned,this.isSticky=t.isSticky,this.isWebhook=t.isWebhook,this.webhookUsername=t.webhookUsername,this.webhookAvatarUrl=t.webhookAvatarUrl,this.embeds=t.embeds??[],this.components=t.components??[],this.attachments=t.attachments??[],this.reactions=t.reactions??[],this.interaction=t.interaction??null,this.poll=t.poll??null,this.stickerId=t.stickerId??null,this.senderIsBot=t.senderIsBot??!1}async reply(e){let t;return e instanceof g?t={embeds:[e.toJSON()],replyToId:this.messageId}:typeof e=="string"?t={content:e,replyToId:this.messageId}:t={...e,replyToId:this.messageId},this.client.sendMessage(this.serverId,this.channelId,t)}async react(e){return this.client.reactToMessage(this.serverId,this.channelId,this.messageId,e)}async delete(){return this.client.deleteMessage(this.serverId,this.channelId,this.messageId)}async vote(e){return this.client.votePoll(this.serverId,this.channelId,this.messageId,e)}hasAttachments(){return Array.isArray(this.attachments)&&this.attachments.length>0}getAttachmentUrl(e){return`${this.client.getApiOrigin()}/api/v1/files/download/${encodeURIComponent(e.attachmentId)}`}getAttachmentsByType(e){return this.attachments.filter(t=>t.type===e)}get isEmpty(){return!this.text.trim()}get isOwnMessage(){return this.client.user?.id===this.senderId}get isFromBot(){return this.senderIsBot||this.isOwnMessage}};var P=class{content="";indentation=0;constructor(e="graph TD"){this.content=e+`
2
2
  `}get indent(){return" ".repeat(this.indentation)}add(e){return this.content+=`${this.indent}${e}
3
3
  `,this}node(e,t,s="box"){if(!t)return this.add(e),this;let r={box:["[","]"],round:["(",")"],stadium:["([","])"],subroutine:["[[","]]"],cylindrical:["[(",")]"],circle:["((","))"],asymmetric:[">","]"],rhombus:["{","}"],hexagon:["{{","}}"]},[i,n]=r[s]||r.box;return this.add(`${e}${i}"${t}"${n}`),this}edge(e,t,s,r="arrow"){let i={arrow:"-->",line:"---",dotted:"-.->",thick:"==>"},n=i[r]||i.arrow;return s?this.add(`${e} ${n}|"${s}"| ${t}`):this.add(`${e} ${n} ${t}`),this}subgraph(e,t){return this.add(`subgraph "${e}"`),this.indentation++,t(this),this.indentation--,this.add("end"),this}style(e,t){return this.add(`style ${e} ${t}`),this}comment(e){return this.add(`%% ${e}`),this}build(){return this.content.trim()}toString(){return this.build()}};var j=class{content="";constructor(e=""){this.content=e}wrap(e,t,s){return this.content+=e+s+t,this}text(e){return this.content+=e,this}italic(e){return this.wrap("*","*",e)}bold(e){return this.wrap("**","**",e)}boldItalic(e){return this.wrap("***","***",e)}strikethrough(e){return this.wrap("~~","~~",e)}underline(e){return this.wrap("__","__",e)}doubleUnderline(e){return this.wrap("___","___",e)}curlyUnderline(e){return this.wrap("_~","~_",e)}jaggedUnderline(e){return this.wrap("_^","^_",e)}doubleCurlyUnderline(e){return this.wrap("_~~","~~_",e)}dashedUnderline(e){return this.wrap("_-","-_",e)}dottedUnderline(e){return this.wrap("_.","._",e)}rhythmUnderline(e){return this.wrap("_-.",".-_",e)}spoiler(e){return this.wrap("||","||",e)}inlineCode(e){return this.wrap("`","`",e)}inlineLatex(e){return this.wrap("$$","$$",e)}superscript(e){return this.wrap("^","^",e)}subscript(e){return this.wrap("~","~",e)}stackedScript(e,t){return this.content+=`^${e}|${t}^`,this}link(e,t){return this.content+=`[${e}](${t})`,this}userMention(e){return this.content+=`<userid:'${e}'>`,this}roleMention(e){return this.content+=`<roleid:'${e}'>`,this}channelMention(e,t){return this.content+=`https://catfla.re/chat/@server/${e}/channel/${t}`,this}everyoneMention(){return this.content+="<everyone>",this}customEmoji(e){return this.content+=`<emoji:${e}>`,this}timestamp(e,t){let s=e instanceof Date?Math.floor(e.getTime()/1e3):e>1e10?Math.floor(e/1e3):Math.floor(e);return this.content+=`<t:${s}${t?`:${t}`:""}>`,this}build(){return this.content}toString(){return this.content}},v=class extends j{p(e){if(typeof e=="string")this.content+=e+`
4
4
  `;else{let t=new j;e(t),this.content+=t.build()+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serchat.ts",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "TypeScript SDK for Serchat",
5
5
  "author": "Serchat",
6
6
  "license": "MIT",