(sock: any, message: any, args: any[], context: BotContext)
| 126 | usage: '.distance <city1> to <city2>\nExample: .distance karachi to dubai', |
| 127 | |
| 128 | async handler(sock: any, message: any, args: any[], context: BotContext) { |
| 129 | const { chatId, channelInfo } = context; |
| 130 | const input = args.join(' ').trim().toLowerCase(); |
| 131 | |
| 132 | if (!input) { |
| 133 | return await sock.sendMessage(chatId, { |
| 134 | text: `🌍 *Distance Calculator*\n\n` + |
| 135 | `*Usage:* \`.distance <city1> to <city2>\`\n\n` + |
| 136 | `*Examples:*\n` + |
| 137 | `• \`.distance karachi to dubai\`\n` + |
| 138 | `• \`.distance lahore to islamabad\`\n` + |
| 139 | `• \`.distance london to newyork\`\n` + |
| 140 | `• \`.distance tokyo to singapore\`\n\n` + |
| 141 | `*Supported cities include:*\n` + |
| 142 | `🇵🇰 PK · 🇮🇳 IN · 🇦🇪 UAE · 🇸🇦 SA · 🇬🇧 UK\n` + |
| 143 | `🇺🇸 USA · 🇨🇳 CN · 🇯🇵 JP · 🇫🇷 FR · 🇩🇪 DE\n` + |
| 144 | `🇧🇩 BD · 🇦🇫 AF · 🇮🇷 IR · 🇹🇷 TR · + many more`, |
| 145 | ...channelInfo |
| 146 | }, { quoted: message }); |
| 147 | } |
| 148 | |
| 149 | const toIndex = args.findIndex((a: string) => a.toLowerCase() === 'to'); |
| 150 | if (toIndex === -1 || toIndex === 0 || toIndex === args.length - 1) { |
| 151 | return await sock.sendMessage(chatId, { |
| 152 | text: `❌ Use: \`.distance <city1> to <city2>\``, |
| 153 | ...channelInfo |
| 154 | }, { quoted: message }); |
| 155 | } |
| 156 | |
| 157 | const city1Input = args.slice(0, toIndex).join('').toLowerCase(); |
| 158 | const city2Input = args.slice(toIndex + 1).join('').toLowerCase(); |
| 159 | |
| 160 | const city1 = findCity(city1Input); |
| 161 | const city2 = findCity(city2Input); |
| 162 | |
| 163 | if (!city1) { |
| 164 | return await sock.sendMessage(chatId, { |
| 165 | text: `❌ City not found: *${args.slice(0, toIndex).join(' ')}*\n\nTry common city names like: karachi, dubai, london, newyork`, |
| 166 | ...channelInfo |
| 167 | }, { quoted: message }); |
| 168 | } |
| 169 | if (!city2) { |
| 170 | return await sock.sendMessage(chatId, { |
| 171 | text: `❌ City not found: *${args.slice(toIndex + 1).join(' ')}*\n\nTry common city names like: karachi, dubai, london, newyork`, |
| 172 | ...channelInfo |
| 173 | }, { quoted: message }); |
| 174 | } |
| 175 | |
| 176 | if (city1.name === city2.name) { |
| 177 | return await sock.sendMessage(chatId, { |
| 178 | text: `😄 Both cities are the same! Distance is 0 km.`, |
| 179 | ...channelInfo |
| 180 | }, { quoted: message }); |
| 181 | } |
| 182 | |
| 183 | const km = haversine(city1.lat, city1.lon, city2.lat, city2.lon); |
| 184 | const miles = km * 0.621371; |
| 185 | const nm = km * 0.539957; |
nothing calls this directly
no test coverage detected