Download plugins/check-code.js from ravenbs1/mmm: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/ravenbs1/mmm/resolve/main/plugins/check-code.js
- Command line
-
hf download hf://spaces/ravenbs1/mmm/plugins/check-code.js
-
curl -L -o check-code.js https://huggingface.co/spaces/ravenbs1/mmm/resolve/main/plugins/check-code.js
1.8 kB
| const axios = require("axios"); | |
| const { cmd } = require("../command"); | |
| // Helper function to convert a country ISO code to its flag emoji | |
| function getFlagEmoji(countryCode) { | |
| if (!countryCode) return ""; | |
| return countryCode | |
| .toUpperCase() | |
| .split("") | |
| .map(letter => String.fromCodePoint(letter.charCodeAt(0) + 127397)) | |
| .join(""); | |
| } | |
| cmd({ | |
| pattern: "check", | |
| desc: "Checks the country calling code and returns the corresponding country name(s) with flag", | |
| category: "utility", | |
| filename: __filename | |
| }, async (conn, mek, m, { from, args, reply }) => { | |
| try { | |
| let code = args[0]; | |
| if (!code) { | |
| return reply("*🎐 ᴘʟᴇᴀsᴇ ᴘʀᴏᴠɪᴅᴇ ᴀ ᴄᴏᴜɴᴛʀʏ ᴄᴏᴅᴇ. ᴇxᴀᴍᴘʟᴇ: `.ᴄʜᴇᴄᴋ 𝟿𝟸`*"); | |
| } | |
| // Remove any '+' signs from the code | |
| code = code.replace(/\+/g, ''); | |
| // Fetch all countries using the REST Countries v2 API | |
| const url = "https://restcountries.com/v2/all"; | |
| const { data } = await axios.get(url); | |
| // Filter countries whose callingCodes include the given code | |
| const matchingCountries = data.filter(country => | |
| country.callingCodes && country.callingCodes.includes(code) | |
| ); | |
| if (matchingCountries.length > 0) { | |
| const countryNames = matchingCountries | |
| .map(country => `${getFlagEmoji(country.alpha2Code)} ${country.name}`) | |
| .join("\n"); | |
| reply(`📮 *Country Code*: ${code}\n🌍 *Countries*:\n${countryNames}`); | |
| } else { | |
| reply(`❌ No country found for the code ${code}.`); | |
| } | |
| } catch (error) { | |
| console.error(error); | |
| reply("❌ An error occurred while checking the country code."); | |
| } | |
| }); | |