From 924eb96c02976fcc265b72943f783b4d7d63f76c Mon Sep 17 00:00:00 2001 From: WlodekM Date: Fri, 24 Jan 2025 20:05:11 +0200 Subject: no hardcoded username in example --- bot.ts | 2 +- main.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bot.ts b/bot.ts index eed58db..2271cd5 100644 --- a/bot.ts +++ b/bot.ts @@ -19,7 +19,7 @@ interface Post { ml.on('post', ({p: post, _id}: Post) => { console.log(post) - if (!post.startsWith(`@wlod-bot`)) return; + if (!post.startsWith(`@${username}`)) return; ml.sendMessage({ message: 'hello', replyTo: _id diff --git a/main.ts b/main.ts index d0f95b9..4949eb1 100644 --- a/main.ts +++ b/main.ts @@ -5,6 +5,15 @@ interface MessageArg { replyTo?: string } +export interface Post { + _id: string, + p: string, + u: string, + e: string, + reply_to: null | string, + post_id: string +} + export default class MAELINK extends EventEmitter { private token: string | null = null; private _ws: WebSocket; @@ -16,7 +25,6 @@ export default class MAELINK extends EventEmitter { } get(path: string, headers: Record = {}) { - console.log(this.http + path); if (this.token) headers = {...headers, token: this.token}; return fetch(this.http + path, { headers, @@ -24,7 +32,6 @@ export default class MAELINK extends EventEmitter { } post(path: string, body: string | object, headers: Record = {}) { - console.log(this.http + path); if (this.token) headers = {...headers, token: this.token}; if (typeof body == "object") { headers['content-type'] = 'application/json' @@ -82,7 +89,7 @@ export default class MAELINK extends EventEmitter { })); } - fetchMessages(offset: number = 0): Promise { + fetchMessages(offset: number = 0): Promise { return new Promise((resolve, reject) => { this._ws.send(JSON.stringify({ cmd: "fetch", -- cgit 1.4.1-2-gfad0