From 04dc5762c186bb5d4da8384c44a6802de7ef238a Mon Sep 17 00:00:00 2001 From: Jersey Date: Sat, 17 Aug 2024 11:55:27 -0400 Subject: [PATCH] fix #9 --- src/api/uploads.ts | 20 ++++++++++++++++++++ src/interfaces/chat.ts | 14 +++++++------- src/interfaces/post.ts | 8 ++++---- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/api/uploads.ts b/src/api/uploads.ts index 4068593..f4745f4 100644 --- a/src/api/uploads.ts +++ b/src/api/uploads.ts @@ -14,6 +14,16 @@ export interface api_attachment { id: string; } +/** api emoji */ +export interface api_emoji { + /** file id */ + _id: string; + /** emoji name */ + name: string; + /** animated */ + animated: boolean; +} + /** uploads class construction options */ export interface uploads_opts { /** base url for uploads */ @@ -42,6 +52,16 @@ export function is_api_attachment(obj: unknown): obj is api_attachment { return true; } +/** check if object is an api emoji */ +export function is_api_emoji(obj: unknown): obj is api_emoji { + if (obj === null || typeof obj !== 'object') return false; + if (!('_id' in obj) || typeof obj._id !== 'string') return false; + if (!('name' in obj) || typeof obj.name !== 'string') return false; + if (!('animated' in obj) || typeof obj.animated !== 'boolean') return false; + + return true; +} + /** access to meower uploads */ export class uploads { private opts: uploads_opts; diff --git a/src/interfaces/chat.ts b/src/interfaces/chat.ts index 9dcde31..e9fbcc1 100644 --- a/src/interfaces/chat.ts +++ b/src/interfaces/chat.ts @@ -1,4 +1,4 @@ -import { type api_attachment, is_api_attachment } from '../api/uploads.ts'; +import { type api_emoji, is_api_emoji } from '../api/uploads.ts'; import { type api_post, post } from './post.ts'; /** chat types */ @@ -34,9 +34,9 @@ export interface api_chat { /** chat type */ type: chat_type; /** emojis */ - emojis: api_attachment[]; + emojis: api_emoji[]; /** stickers */ - stickers: api_attachment[]; + stickers: api_emoji[]; } /** chat construction options */ @@ -95,11 +95,11 @@ export function is_api_chat(obj: unknown): obj is api_chat { if (!('type' in obj) || typeof obj.type !== 'number') return false; if (!('emojis' in obj) || !Array.isArray(obj.emojis)) return false; for (const i of obj.emojis) { - if (!is_api_attachment(i)) return false; + if (!is_api_emoji(i)) return false; } if (!('stickers' in obj) || !Array.isArray(obj.stickers)) return false; for (const i of obj.stickers) { - if (!is_api_attachment(i)) return false; + if (!is_api_emoji(i)) return false; } return true; @@ -134,9 +134,9 @@ export class chat { /** chat type */ type!: chat_type; /** emojis */ - emojis!: api_attachment[]; + emojis!: api_emoji[]; /** stickers */ - stickers!: api_attachment[]; + stickers!: api_emoji[]; constructor(opts: chat_construction_opts) { this.api_url = opts.api_url; diff --git a/src/interfaces/post.ts b/src/interfaces/post.ts index 961ef1e..1670d8f 100644 --- a/src/interfaces/post.ts +++ b/src/interfaces/post.ts @@ -1,4 +1,4 @@ -import { type api_attachment, is_api_attachment } from '../api/uploads.ts'; +import { type api_attachment, type api_emoji, is_api_attachment, is_api_emoji } from '../api/uploads.ts'; import type { message_send_opts } from './chat.ts'; /** types of posts */ @@ -35,7 +35,7 @@ export interface api_post { /** username */ u: string; /** stickers */ - stickers: api_attachment[]; + stickers: api_emoji[]; /** reply to */ reply_to: api_post[]; /** reactions */ @@ -97,7 +97,7 @@ export function is_api_post(obj: unknown): obj is api_post { if (!('u' in obj) || typeof obj.u !== 'string') return false; if (!('stickers' in obj) || !Array.isArray(obj.stickers)) return false; for (const i of obj.stickers) { - if (!is_api_attachment(i)) return false; + if (!is_api_emoji(i)) return false; } if (!('reply_to' in obj) || !Array.isArray(obj.reply_to)) return false; for (const i of obj.reply_to) { @@ -138,7 +138,7 @@ export class post { /** reply to */ replies!: post[]; /** stickers */ - stickers!: api_attachment[]; + stickers!: api_emoji[]; /** reactions */ reactions!: api_post['reactions'];