MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/sudoku.js:11–114  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

9 description: 'Generate Sudoku puzzles or solve them',
10 usage: '.sudoku generate [easy|medium|hard]\n.sudoku solve <81 digits, 0 for empty>',
11 async handler(sock, message, args, context) {
12 const { chatId, channelInfo } = context;
13 const scriptPath = path.join(process.cwd(), 'lib', 'sudoku.py');
14 if (!args.length || args[0] === 'help') {
15 return await sock.sendMessage(chatId, {
16 text: `🧩 *Sudoku*\n\n` +
17 `*Generate a puzzle:*\n` +
18 `\`.sudoku generate easy\`\n` +
19 `\`.sudoku generate medium\`\n` +
20 `\`.sudoku generate hard\`\n\n` +
21 `*Solve a puzzle:*\n` +
22 `\`.sudoku solve 530070000600195000098000060800060003400803001700020006060000280000419005000080079\`\n\n` +
23 `ℹ️ For solve: send 81 digits, use 0 for empty cells`,
24 ...channelInfo
25 }, { quoted: message });
26 }
27 const subCmd = args[0].toLowerCase();
28 if (subCmd === 'generate') {
29 const difficulty = (args[1] || 'medium').toLowerCase();
30 if (!['easy', 'medium', 'hard'].includes(difficulty)) {
31 return await sock.sendMessage(chatId, {
32 text: `❌ Invalid difficulty. Use: \`easy\`, \`medium\`, or \`hard\``,
33 ...channelInfo
34 }, { quoted: message });
35 }
36 await sock.sendMessage(chatId, {
37 text: `🧩 Generating ${difficulty} puzzle...`,
38 ...channelInfo
39 }, { quoted: message });
40 try {
41 const { stdout } = await execAsync(`python3 "${scriptPath}" generate ${difficulty}`, { timeout: 30000 });
42 const data = JSON.parse(stdout.trim());
43 if (data.error) {
44 return await sock.sendMessage(chatId, {
45 text: `❌ ${data.error}`,
46 ...channelInfo
47 }, { quoted: message });
48 }
49 const diffEmoji = { easy: '🟢', medium: '🟡', hard: '🔴' };
50 await sock.sendMessage(chatId, {
51 text: `🧩 *Sudoku — ${diffEmoji[difficulty]} ${difficulty.toUpperCase()}*\n` +
52 `📊 *Clues:* ${data.clues}/81\n\n` +
53 `*Puzzle:*\n\`\`\`\n${data.formatted_puzzle}\n\`\`\`\n\n` +
54 `*Puzzle code (to solve later):*\n\`${data.puzzle}\`\n\n` +
55 `_Use \`.sudoku solve ${data.puzzle}\` to reveal solution_`,
56 ...channelInfo
57 }, { quoted: message });
58 }
59 catch (error) {
60 await sock.sendMessage(chatId, {
61 text: `❌ Failed to generate: ${error.message}`,
62 ...channelInfo
63 }, { quoted: message });
64 }
65 }
66 else if (subCmd === 'solve') {
67 const grid = args[1]?.trim();
68 if (!grid) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected