From 58695ae51bbe893bdc217ca43b0918a4c8d5fcfa Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Sun, 10 May 2026 23:25:18 +0300 Subject: [PATCH] feat: rich presenceContents with emoji and activity support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - presenceContents entries now accept plain strings (backwards compatible) or rich objects with: text — status text (required) emoji_name — unicode emoji or custom emoji name emoji_id — snowflake ID for custom guild emojis activity — { name, type, url? } where type follows Fluxer activity types (0=Playing 1=Streaming 2=Listening 3=Watching 5=Competing) - Both index.mjs (initial presence on login) and GatewayHandler.mjs (rotating presence loop) updated to resolve each entry: builds custom_status from text/emoji fields and appends activities[] if an activity object is provided - Add presenceContents-Comment field to config_example.json documenting the schema with three example entries (custom guild emoji + Listening activity, unicode emoji, credits entry) fix: safe-load storage/modules.json on startup - index.mjs wrapped modules.json read in try/catch; logs a clear warning and starts with an empty modules array instead of crashing on ENOENT or malformed JSON --- config_example.json | 20 +++++++++++++++++- index.mjs | 47 +++++++++++++++++++++++++++++++++++------- src/GatewayHandler.mjs | 28 ++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 9 deletions(-) diff --git a/config_example.json b/config_example.json index 5624206..e4a7f20 100644 --- a/config_example.json +++ b/config_example.json @@ -13,7 +13,25 @@ }, "prefix": "your desired prefix (such as %)", "presenceInterval": null, - "presenceContents": [], + "presenceContents-Comment": "Each entry can be a plain string (e.g. 'Ping for Prefix') or an object. Objects support: text (required), emoji_name (unicode emoji or custom emoji name), emoji_id (snowflake ID for custom guild emojis only), activity ({ name, type, url? }). Activity types: 0=Playing, 1=Streaming, 2=Listening, 3=Watching, 5=Competing. For custom guild emojis, provide both emoji_name AND emoji_id. For unicode emojis, only emoji_name is needed.", + "presenceContents": [ + { + "text": "Ping for Prefix | Hosted by https://kyun.sh/", + "emoji_name": "Remix", + "emoji_id": "1487652011819025844", + "activity": { "name": "kyun.sh", "type": 2 } + }, + { + "text": "Ping for Prefix", + "emoji_name": "🎧", + "activity": { "name": "music", "type": 2 } + }, + { + "text": "Ping for Prefix | By RedTech & NoLogicAlan", + "emoji_name": "🎶", + "activity": { "name": "RedTech & NoLogicAlan", "type": 2 } + } + ], "spotify": { "clientId": "your spotify client id", "clientSecret": "your spotify client secret" diff --git a/index.mjs b/index.mjs index be8860a..c9806c3 100644 --- a/index.mjs +++ b/index.mjs @@ -68,12 +68,37 @@ export class Remix { const client = new Client({ intents: config["fluxer.js"]?.intents ?? 0, ...config["fluxer.js"], - presence: presenceContents.length > 0 ? { - status: "online", - mobile: false, - afk: false, - custom_status: { text: presenceContents[0] }, - } : undefined, + presence: (() => { + if (presenceContents.length === 0) return undefined; + const entry = presenceContents[0]; + const isObj = typeof entry === "object" && entry !== null; + + const custom_status = {}; + if (isObj) { + if (entry.text) custom_status.text = entry.text; + if (entry.emoji_name) custom_status.emoji_name = entry.emoji_name; + if (entry.emoji_id) custom_status.emoji_id = entry.emoji_id; + } else { + custom_status.text = String(entry); + } + + const p = { + status: "online", + mobile: false, + afk: false, + custom_status, + }; + + if (isObj && entry.activity) { + p.activities = [{ + name: entry.activity.name ?? "music", + type: entry.activity.type ?? 0, + url: entry.activity.url ?? undefined, + }]; + } + + return p; + })(), }); client.setMaxListeners(50); @@ -478,7 +503,15 @@ export class Remix { // ── Modules ─────────────────────────────────────────────────────────────── logger.commands("Loading Modules."); this.loadedModules = new Map(); - this.modules = JSON.parse(fs.readFileSync("./storage/modules.json")); + try { + this.modules = JSON.parse(fs.readFileSync("./storage/modules.json")); + } catch (e) { + const reason = e.code === "ENOENT" + ? "storage/modules.json not found." + : `storage/modules.json is malformed JSON: ${e.message}`; + console.error(`[Startup] WARN: ${reason} — starting with no modules.`); + this.modules = []; + } Promise.allSettled(this.modules.map(async m => { if (!m.enabled) return; try { diff --git a/src/GatewayHandler.mjs b/src/GatewayHandler.mjs index fae1fb5..e50c72c 100644 --- a/src/GatewayHandler.mjs +++ b/src/GatewayHandler.mjs @@ -362,12 +362,38 @@ export class GatewayHandler { const client = remix.client; const setPresence = () => { + const entry = this.presenceContents[this.presenceIndex]; + + // Support both plain strings and rich objects: + // String: "Ping for Prefix" + // Object: { text: "...", emoji_name: "🎵", activity: { name: "kyun.sh", type: 2 } } + const isObj = typeof entry === "object" && entry !== null; + + const custom_status = {}; + if (isObj) { + if (entry.text) custom_status.text = entry.text; + if (entry.emoji_name) custom_status.emoji_name = entry.emoji_name; + if (entry.emoji_id) custom_status.emoji_id = entry.emoji_id; + } else { + custom_status.text = String(entry); + } + const presence = { status: "online", mobile: false, afk: false, - custom_status: { text: this.presenceContents[this.presenceIndex] }, + custom_status, }; + + // Add activity (e.g. "Listening to kyun.sh") if provided + if (isObj && entry.activity) { + presence.activities = [{ + name: entry.activity.name ?? "music", + type: entry.activity.type ?? 0, + url: entry.activity.url ?? undefined, + }]; + } + if (client.ws?.send) { client.ws.send(0, { op: GatewayOpcodes.PresenceUpdate, d: presence }); } else {