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

+19 -1
View File
@@ -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"
+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 {
+27 -1
View File
@@ -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 {