feat: rich presenceContents with emoji and activity support

- 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
This commit is contained in:
NoLogicAlan committed 2026-05-10 23:25:18 +03:00
1 parent 0048a33099
commit 58695ae51b
3 files changed
+86 -9

No files matched your search

+40 -7
View File
@@ -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 {