MCPcopy Create free account
hub / github.com/chokcoco/iCSS / getRandomCssTip

Method getRandomCssTip

MCP/server.js:688–762  ·  view source on GitHub ↗
(source = 'both')

Source from the content-addressed store, hash-verified

686 }
687
688 async getRandomCssTip(source = 'both') {
689 debugLog(`🎲 Getting random CSS tip (source: ${source})`);
690
691 return new Promise((resolve, reject) => {
692 let queries = [];
693
694 if (source === 'both' || source === 'icss') {
695 queries.push({
696 sql: 'SELECT *, "icss" as source_type FROM issues ORDER BY RANDOM() LIMIT 1',
697 params: []
698 });
699 }
700
701 if (source === 'both' || source === 'inspiration') {
702 queries.push({
703 sql: 'SELECT *, "inspiration" as source_type FROM css_inspiration ORDER BY RANDOM() LIMIT 1',
704 params: []
705 });
706 }
707
708 // 随机选择一个查询
709 const randomQuery = queries[Math.floor(Math.random() * queries.length)];
710
711 this.db.get(randomQuery.sql, randomQuery.params, (err, row) => {
712 if (err) {
713 debugLog('❌ Error getting random tip:', err);
714 reject(err);
715 return;
716 }
717
718 if (!row) {
719 reject(new Error('No content available'));
720 return;
721 }
722
723 if (row.source_type === 'icss') {
724 debugLog(`✅ Random iCSS tip: "${row.title}" (Issue #${row.number})`);
725
726 const labels = row.labels ? JSON.parse(row.labels) : [];
727 const preview = this.extractPreview(row.body);
728
729 resolve({
730 content: [
731 {
732 type: 'text',
733 text: `🎲 **Random CSS Tip** (from iCSS): ${row.title}\n\n` +
734 `**Issue #${row.number}** | **Tags:** ${labels.join(', ')}\n\n` +
735 `${preview}\n\n` +
736 `[Read full article](${row.html_url})`
737 }
738 ]
739 });
740 } else {
741 debugLog(`✅ Random CSS-Inspiration demo: "${row.title}" (ID #${row.id})`);
742
743 const tags = row.tags ? JSON.parse(row.tags) : [];
744
745 resolve({

Callers 1

setupHandlersMethod · 0.95

Calls 3

extractPreviewMethod · 0.95
getMethod · 0.80
debugLogFunction · 0.70

Tested by

no test coverage detected