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