(sock, message, args, context)
| 114 | description: 'Calculate distance between two cities with flight and driving time estimates', |
| 115 | usage: '.distance <city1> to <city2>\nExample: .distance karachi to dubai', |
| 116 | async handler(sock, message, args, context) { |
| 117 | const { chatId, channelInfo } = context; |
| 118 | const input = args.join(' ').trim().toLowerCase(); |
| 119 | if (!input) { |
| 120 | return await sock.sendMessage(chatId, { |
| 121 | text: `🌍 *Distance Calculator*\n\n` + |
| 122 | `*Usage:* \`.distance <city1> to <city2>\`\n\n` + |
| 123 | `*Examples:*\n` + |
| 124 | `• \`.distance karachi to dubai\`\n` + |
| 125 | `• \`.distance lahore to islamabad\`\n` + |
| 126 | `• \`.distance london to newyork\`\n` + |
| 127 | `• \`.distance tokyo to singapore\`\n\n` + |
| 128 | `*Supported cities include:*\n` + |
| 129 | `🇵🇰 PK · 🇮🇳 IN · 🇦🇪 UAE · 🇸🇦 SA · 🇬🇧 UK\n` + |
| 130 | `🇺🇸 USA · 🇨🇳 CN · 🇯🇵 JP · 🇫🇷 FR · 🇩🇪 DE\n` + |
| 131 | `🇧🇩 BD · 🇦🇫 AF · 🇮🇷 IR · 🇹🇷 TR · + many more`, |
| 132 | ...channelInfo |
| 133 | }, { quoted: message }); |
| 134 | } |
| 135 | const toIndex = args.findIndex((a) => a.toLowerCase() === 'to'); |
| 136 | if (toIndex === -1 || toIndex === 0 || toIndex === args.length - 1) { |
| 137 | return await sock.sendMessage(chatId, { |
| 138 | text: `❌ Use: \`.distance <city1> to <city2>\``, |
| 139 | ...channelInfo |
| 140 | }, { quoted: message }); |
| 141 | } |
| 142 | const city1Input = args.slice(0, toIndex).join('').toLowerCase(); |
| 143 | const city2Input = args.slice(toIndex + 1).join('').toLowerCase(); |
| 144 | const city1 = findCity(city1Input); |
| 145 | const city2 = findCity(city2Input); |
| 146 | if (!city1) { |
| 147 | return await sock.sendMessage(chatId, { |
| 148 | text: `❌ City not found: *${args.slice(0, toIndex).join(' ')}*\n\nTry common city names like: karachi, dubai, london, newyork`, |
| 149 | ...channelInfo |
| 150 | }, { quoted: message }); |
| 151 | } |
| 152 | if (!city2) { |
| 153 | return await sock.sendMessage(chatId, { |
| 154 | text: `❌ City not found: *${args.slice(toIndex + 1).join(' ')}*\n\nTry common city names like: karachi, dubai, london, newyork`, |
| 155 | ...channelInfo |
| 156 | }, { quoted: message }); |
| 157 | } |
| 158 | if (city1.name === city2.name) { |
| 159 | return await sock.sendMessage(chatId, { |
| 160 | text: `😄 Both cities are the same! Distance is 0 km.`, |
| 161 | ...channelInfo |
| 162 | }, { quoted: message }); |
| 163 | } |
| 164 | const km = haversine(city1.lat, city1.lon, city2.lat, city2.lon); |
| 165 | const miles = km * 0.621371; |
| 166 | const nm = km * 0.539957; |
| 167 | await sock.sendMessage(chatId, { |
| 168 | text: `🌍 *Distance Calculator*\n\n` + |
| 169 | `${city1.flag} *From:* ${city1.name}, ${city1.country}\n` + |
| 170 | `${city2.flag} *To:* ${city2.name}, ${city2.country}\n\n` + |
| 171 | `━━━━━━━━━━━━━━━━━\n` + |
| 172 | `📏 *Distance:*\n` + |
| 173 | ` • ${Math.round(km).toLocaleString()} km\n` + |
nothing calls this directly
no test coverage detected