'use strict'; const express = require('express'); const { CJbot } = require('../model/minecraft'); const ACTIVITY_PLUGINS = ['Swing', 'Craft', 'GuardianFarm', 'GoldFarm', 'AutoEat']; function createRouter() { const router = express.Router(); router.get('/api/activity', (req, res) => { try { const result = {}; for (const [name, bot] of Object.entries(CJbot.bots)) { const plugins = {}; for (const pluginName of ACTIVITY_PLUGINS) { const instance = bot.plunginsLoaded[pluginName]; if (!instance) continue; const cls = CJbot.plungins[pluginName]; if (cls && typeof cls.getStatus === 'function') { plugins[pluginName] = cls.getStatus(instance); } else { plugins[pluginName] = { active: true }; } } if (Object.keys(plugins).length > 0) { result[name] = { connected: bot.isReady, plugins }; } } res.json({ bots: result }); } catch (error) { console.error('API Error /api/activity:', error); res.status(500).json({ error: error.message }); } }); return router; } const webUI = { tabId: 'activity', tabLabel: 'Activity', tabOrder: 20, html: `
Loading activity...
`, css: ` .activity-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(340px,1fr));gap:16px} .activity-card{background:#111827;border:1px solid #374151;border-radius:8px;padding:16px;transition:border-color .2s} .activity-card:hover{border-color:#60a5fa} .activity-card h3{font-size:1em;color:#60a5fa;margin-bottom:12px;display:flex;align-items:center;gap:8px} .activity-plugin{background:#1f2937;border:1px solid #374151;border-radius:6px;padding:10px 14px;margin-bottom:8px} .activity-plugin:last-child{margin-bottom:0} .activity-plugin-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:4px} .activity-plugin-name{font-size:.9em;font-weight:600;color:#e5e7eb} .activity-badge{padding:2px 8px;border-radius:10px;font-size:.75em;font-weight:600} .activity-badge.active{background:#059669;color:#fff} .activity-detail{font-size:.8em;color:#9ca3af;margin-top:4px} .hunger-bar{display:flex;gap:2px;margin-top:4px} .hunger-pip{width:12px;height:12px;border-radius:2px;background:#374151} .hunger-pip.filled{background:#f59e0b} .hunger-pip.low{background:#ef4444} .activity-empty{padding:40px 20px;color:#6b7280;text-align:center;font-size:.9em} `, onTabActive: 'onActivityTabActive', js: ` let activityInterval=null; function onActivityTabActive() { loadActivity(); if (!activityInterval) activityInterval = setInterval(() => { if (currentTab === 'activity') loadActivity(); }, 5000); } async function loadActivity() { try { const r = await fetch('/api/activity'); if (!r.ok) { document.getElementById('activityArea').innerHTML='
Failed to load activity
'; return; } const d = await r.json(); renderActivity(d.bots || {}); updateTimestamp('ts-activity'); } catch(e) { document.getElementById('activityArea').innerHTML='
Failed to load activity
'; } } function renderActivity(bots) { const area = document.getElementById('activityArea'); const names = Object.keys(bots); if (names.length === 0) { area.innerHTML='
No active automation plugins
'; return; } area.innerHTML = '
' + names.map(name => { const bot = bots[name]; const pluginHtml = Object.entries(bot.plugins).map(([pName, status]) => { let detail = ''; // Special case: AutoEat gets a hunger bar if (pName === 'AutoEat' && status.hunger != null) { let hungerBar = '
'; for (let i = 0; i < 20; i++) { const filled = i < status.hunger; const low = status.hunger < (status.threshold || 0); hungerBar += '
'; } hungerBar += '
'; detail += hungerBar; } // Render all status keys generically const skipKeys = new Set(['active']); for (const [key, val] of Object.entries(status)) { if (skipKeys.has(key)) continue; if (val === null || val === undefined) continue; const label = fmtName(key.replace(/([A-Z])/g, '_$1').toLowerCase()); let display; if (typeof val === 'boolean') display = val ? 'Yes' : 'No'; else if (Array.isArray(val)) display = val.map(fmtName).join(', ') || 'None'; else display = escHtml(String(val)); detail += '
' + escHtml(label) + ': ' + display + '
'; } if (!detail) detail = '
Running
'; return '
' + '
' + '' + escHtml(pName) + '' + 'Active' + '
' + detail + '
'; }).join(''); return '
' + '

' + escHtml(name) + '

' + pluginHtml + '
'; }).join('') + '
'; } `, }; module.exports = { name: 'Activity', createRouter, webUI };