From eeff93db285c508b0e2b082859f8e42d5933c439 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 21 May 2026 21:32:45 -0500 Subject: [PATCH] user notes --- src/webpage/jsontypes.ts | 22 ++++++++++++++++++++++ src/webpage/localuser.ts | 5 +++++ src/webpage/style.css | 3 +++ src/webpage/user.ts | 35 +++++++++++++++++++++++++++++++++++ translations/en.json | 3 ++- 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/webpage/jsontypes.ts b/src/webpage/jsontypes.ts index 4949e78..24031c4 100644 --- a/src/webpage/jsontypes.ts +++ b/src/webpage/jsontypes.ts @@ -939,6 +939,27 @@ type messageCreateJson = { s: number; t: "MESSAGE_CREATE"; }; +type userNote = { + op: 0; + t: "USER_NOTE_UPDATE"; + d: { + note: string; + id: string; + }; + s: number; +}; +export type pollUpdateJson = { + op: 0; + d: { + user_id: string; + channel_id: string; + message_id: string; + guild_id?: string; + answer_id: number; + }; + s: number; + t: "MESSAGE_POLL_VOTE_ADD" | "MESSAGE_POLL_VOTE_REMOVE"; +}; export interface relationJson { id: string; type: 0 | 1 | 2 | 3 | 4; @@ -1030,6 +1051,7 @@ type wsjson = heartbeat_interval: number; }; } + | userNote | { op: 0; t: "MESSAGE_REACTION_ADD"; diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 096be62..1f4d386 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -769,6 +769,11 @@ class Localuser { this.messageCreate(temp); } break; + case "USER_NOTE_UPDATE": { + const u = this.userMap.get(temp.d.id); + if (u) u.note = temp.d.note; + break; + } case "USER_CONNECTIONS_UPDATE": { this.conectionChange(); break; diff --git a/src/webpage/style.css b/src/webpage/style.css index e0e7883..aa69231 100644 --- a/src/webpage/style.css +++ b/src/webpage/style.css @@ -422,6 +422,9 @@ body { padding: 0; border: 0; } +.userNote { + max-width: 100% !important; +} #player { flex-grow: 0; diff --git a/src/webpage/user.ts b/src/webpage/user.ts index 1017641..a85a9cf 100644 --- a/src/webpage/user.ts +++ b/src/webpage/user.ts @@ -1173,6 +1173,33 @@ class User extends SnowFlake { } } } + note?: string; + async saveNotes(note: string) { + this.note = note; + await fetch(`${this.info.api}/users/@me/notes/${this.id}`, { + method: "PUT", + headers: this.headers, + body: JSON.stringify({note}), + }); + } + async getNotes() { + try { + if (this.note === undefined) { + this.note = + ( + await ( + await fetch(`${this.info.api}/users/@me/notes/${this.id}`, { + method: "GET", + headers: this.headers, + }) + ).json() + ).note || ""; + } + } catch { + this.note = ""; + } + return this.note as string; + } async fullProfile(guild: Guild | null | Member = null) { console.log(guild); const membres = (async () => { @@ -1380,6 +1407,14 @@ class User extends SnowFlake { document.body.append(background); background.append(div); console.log(background); + const notes = buttons.add(I18n.profile.notes()); + const textArea = document.createElement("textarea"); + textArea.classList.add("userNote"); + notes.addHTMLArea(textArea); + this.getNotes().then((_) => (textArea.textContent = _)); + textArea.onblur = () => { + this.saveNotes(textArea.value); + }; (async () => { const high = await this.highInfo(); const mut = buttons.add(I18n.profile.mut()); diff --git a/translations/en.json b/translations/en.json index f6138e7..2d23705 100644 --- a/translations/en.json +++ b/translations/en.json @@ -773,7 +773,8 @@ "mut": "Mutual guilds", "mutFriends": "Mutual friends", "permInfo": "Permissions", - "userInfo": "User info" + "userInfo": "User info", + "notes":"User notes" }, "profileColor": "Profile color", "pronouns": "Pronouns:",