(sock, message, args, context)
| 6 | description: 'Search a word on Dictionary', |
| 7 | usage: '.define <word>', |
| 8 | async handler(sock, message, args, context) { |
| 9 | const chatId = context.chatId || message.key.remoteJid; |
| 10 | const query = args?.join(' ')?.trim(); |
| 11 | if (!query) { |
| 12 | return await sock.sendMessage(chatId, { text: '*Please provide a word to search for.*\nExample: .define hello' }, { quoted: message }); |
| 13 | } |
| 14 | try { |
| 15 | const url = `https://api.urbandictionary.com/v0/define?term=${encodeURIComponent(query)}`; |
| 16 | const { data: json } = await axios.get(url); |
| 17 | if (!json?.list || json.list.length === 0) { |
| 18 | return await sock.sendMessage(chatId, { text: '❌ Word not found in the dictionary.' }, { quoted: message }); |
| 19 | } |
| 20 | const firstEntry = json.list[0]; |
| 21 | const definition = firstEntry.definition || 'No definition available'; |
| 22 | const example = firstEntry.example ? `*Example:* ${firstEntry.example}` : ''; |
| 23 | const text = `🔍 *Dictionary*\n\n*Word:* ${query}\n*Definition:* ${definition}\n${example}`; |
| 24 | await sock.sendMessage(chatId, { text }, { quoted: message }); |
| 25 | } |
| 26 | catch (error) { |
| 27 | console.error('Urban plugin error:', error); |
| 28 | await sock.sendMessage(chatId, { text: '❌ Failed to fetch definition.', }, { quoted: message }); |
| 29 | } |
| 30 | } |
| 31 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected