diff --git a/assets/countries.js b/assets/countries.js index 7d52ffc..6eca397 100644 --- a/assets/countries.js +++ b/assets/countries.js @@ -2,9 +2,13 @@ const fs = require('fs').promises; const crypto = require('crypto'); +const { argv } = require('yargs'); // const bhttp = require('bhttp'); const countries = require('./countries.json'); +const states = require('./states-us.json'); + +const data = { countries, states }; /* async function fetchCountries() { @@ -22,14 +26,16 @@ async function fetchCountries() { */ async function init() { - const countryImgs = await fs.readdir('./assets/countries'); - const countriesByCode = Object.fromEntries(countries.map((country) => [country.alpha2, country])); + const type = argv.states ? 'states' : 'countries'; + + const countryImgs = await fs.readdir(`./assets/${type}`); + const countriesByCode = Object.fromEntries(data[type].map((country) => [country.alpha2, country])); const imgCountries = await Promise.all(countryImgs.filter((file) => !['encoded', 'disabled'].includes(file)).map(async (file) => { const code = file.match(/(\w+).png/)[1]; const filename = `${crypto.createHash('md5').update(code).digest('hex').slice(0, 4)}.png`; - await fs.copyFile(`./assets/countries/${file}`, `./assets/countries/encoded/${filename}`); + await fs.copyFile(`./assets/${type}/${file}`, `./assets/${type}/encoded/${filename}`); return { file: filename, @@ -38,7 +44,7 @@ async function init() { }; })); - await fs.writeFile('./assets/countries-curated.json', JSON.stringify(imgCountries, null, 4)); + await fs.writeFile(`./assets/${type}-curated.json`, JSON.stringify(imgCountries, null, 4)); console.log('Done!'); } diff --git a/assets/states-curated.json b/assets/states-curated.json new file mode 100644 index 0000000..41183ae --- /dev/null +++ b/assets/states-curated.json @@ -0,0 +1,442 @@ +[ + { + "file": "631d.png", + "code": "AK", + "alpha2": "AK", + "alpah2Us": "US-AK", + "name": "Alaska", + "type": "state" + }, + { + "file": "e892.png", + "code": "AL", + "alpha2": "AL", + "alpah2Us": "US-AL", + "name": "Alabama", + "type": "state" + }, + { + "file": "5b61.png", + "code": "AR", + "alpha2": "AR", + "alpah2Us": "US-AR", + "name": "Arkansas", + "type": "state" + }, + { + "file": "a2c2.png", + "code": "AS", + "alpha2": "AS", + "alpah2Us": "US-AS", + "name": "American Samoa", + "type": "outlying area" + }, + { + "file": "546a.png", + "code": "AZ", + "alpha2": "AZ", + "alpah2Us": "US-AZ", + "name": "Arizona", + "type": "state" + }, + { + "file": "3e8d.png", + "code": "CA", + "alpha2": "CA", + "alpah2Us": "US-CA", + "name": "California", + "type": "state" + }, + { + "file": "4298.png", + "code": "CO", + "alpha2": "CO", + "alpah2Us": "US-CO", + "name": "Colorado", + "type": "state" + }, + { + "file": "112c.png", + "code": "CT", + "alpha2": "CT", + "alpah2Us": "US-CT", + "name": "Connecticut", + "type": "state" + }, + { + "file": "3a52.png", + "code": "DE", + "alpha2": "DE", + "alpah2Us": "US-DE", + "name": "Delaware", + "type": "state" + }, + { + "file": "ac71.png", + "code": "FL", + "alpha2": "FL", + "alpah2Us": "US-FL", + "name": "Florida", + "type": "state" + }, + { + "file": "cd95.png", + "code": "GA", + "alpha2": "GA", + "alpah2Us": "US-GA", + "name": "Georgia", + "type": "state" + }, + { + "file": "3053.png", + "code": "GU", + "alpha2": "GU", + "alpah2Us": "US-GU", + "name": "Guam", + "type": "outlying area" + }, + { + "file": "bf8c.png", + "code": "HI", + "alpha2": "HI", + "alpah2Us": "US-HI", + "name": "Hawaii", + "type": "state" + }, + { + "file": "b972.png", + "code": "IA", + "alpha2": "IA", + "alpah2Us": "US-IA", + "name": "Iowa", + "type": "state" + }, + { + "file": "b718.png", + "code": "ID", + "alpha2": "ID", + "alpah2Us": "US-ID", + "name": "Idaho", + "type": "state" + }, + { + "file": "8858.png", + "code": "IL", + "alpha2": "IL", + "alpah2Us": "US-IL", + "name": "Illinois", + "type": "state" + }, + { + "file": "c86e.png", + "code": "IN", + "alpha2": "IN", + "alpah2Us": "US-IN", + "name": "Indiana", + "type": "state" + }, + { + "file": "a323.png", + "code": "KS", + "alpha2": "KS", + "alpah2Us": "US-KS", + "name": "Kansas", + "type": "state" + }, + { + "file": "b8ea.png", + "code": "KY", + "alpha2": "KY", + "alpah2Us": "US-KY", + "name": "Kentucky", + "type": "state" + }, + { + "file": "6b40.png", + "code": "LA", + "alpha2": "LA", + "alpah2Us": "US-LA", + "name": "Louisiana", + "type": "state" + }, + { + "file": "2a60.png", + "code": "MA", + "alpha2": "MA", + "alpah2Us": "US-MA", + "name": "Massachusetts", + "type": "state" + }, + { + "file": "7dc1.png", + "code": "MD", + "alpha2": "MD", + "alpah2Us": "US-MD", + "name": "Maryland", + "type": "state" + }, + { + "file": "9ee9.png", + "code": "ME", + "alpha2": "ME", + "alpah2Us": "US-ME", + "name": "Maine", + "type": "state" + }, + { + "file": "9b38.png", + "code": "MI", + "alpha2": "MI", + "alpah2Us": "US-MI", + "name": "Michigan", + "type": "state" + }, + { + "file": "943a.png", + "code": "MN", + "alpha2": "MN", + "alpah2Us": "US-MN", + "name": "Minnesota", + "type": "state" + }, + { + "file": "eb04.png", + "code": "MO", + "alpha2": "MO", + "alpah2Us": "US-MO", + "name": "Missouri", + "type": "state" + }, + { + "file": "c90a.png", + "code": "MP", + "alpha2": "MP", + "alpah2Us": "US-MP", + "name": "Northern Mariana Islands", + "type": "outlying area" + }, + { + "file": "7a66.png", + "code": "MS", + "alpha2": "MS", + "alpah2Us": "US-MS", + "name": "Mississippi", + "type": "state" + }, + { + "file": "08ad.png", + "code": "MT", + "alpha2": "MT", + "alpah2Us": "US-MT", + "name": "Montana", + "type": "state" + }, + { + "file": "9058.png", + "code": "NC", + "alpha2": "NC", + "alpah2Us": "US-NC", + "name": "North Carolina", + "type": "state" + }, + { + "file": "9a11.png", + "code": "ND", + "alpha2": "ND", + "alpah2Us": "US-ND", + "name": "North Dakota", + "type": "state" + }, + { + "file": "dc33.png", + "code": "NE", + "alpha2": "NE", + "alpah2Us": "US-NE", + "name": "Nebraska", + "type": "state" + }, + { + "file": "d41b.png", + "code": "NH", + "alpha2": "NH", + "alpah2Us": "US-NH", + "name": "New Hampshire", + "type": "state" + }, + { + "file": "e223.png", + "code": "NJ", + "alpha2": "NJ", + "alpah2Us": "US-NJ", + "name": "New Jersey", + "type": "state" + }, + { + "file": "e0f3.png", + "code": "NM", + "alpha2": "NM", + "alpah2Us": "US-NM", + "name": "New Mexico", + "type": "state" + }, + { + "file": "5343.png", + "code": "NV", + "alpha2": "NV", + "alpah2Us": "US-NV", + "name": "Nevada", + "type": "state" + }, + { + "file": "93a2.png", + "code": "NY", + "alpha2": "NY", + "alpah2Us": "US-NY", + "name": "New York", + "type": "state" + }, + { + "file": "ec94.png", + "code": "OH", + "alpha2": "OH", + "alpah2Us": "US-OH", + "name": "Ohio", + "type": "state" + }, + { + "file": "e0aa.png", + "code": "OK", + "alpha2": "OK", + "alpah2Us": "US-OK", + "name": "Oklahoma", + "type": "state" + }, + { + "file": "1d00.png", + "code": "OR", + "alpha2": "OR", + "alpah2Us": "US-OR", + "name": "Oregon", + "type": "state" + }, + { + "file": "06f6.png", + "code": "PA", + "alpha2": "PA", + "alpah2Us": "US-PA", + "name": "Pennsylvania", + "type": "state" + }, + { + "file": "0fe7.png", + "code": "PR", + "alpha2": "PR", + "alpah2Us": "US-PR", + "name": "Puerto Rico", + "type": "outlying area" + }, + { + "file": "2cff.png", + "code": "RI", + "alpha2": "RI", + "alpah2Us": "US-RI", + "name": "Rhode Island", + "type": "state" + }, + { + "file": "6a65.png", + "code": "SC", + "alpha2": "SC", + "alpah2Us": "US-SC", + "name": "South Carolina", + "type": "state" + }, + { + "file": "38f9.png", + "code": "SD", + "alpha2": "SD", + "alpah2Us": "US-SD", + "name": "South Dakota", + "type": "state" + }, + { + "file": "947d.png", + "code": "TN", + "alpha2": "TN", + "alpah2Us": "US-TN", + "name": "Tennessee", + "type": "state" + }, + { + "file": "8690.png", + "code": "TX", + "alpha2": "TX", + "alpah2Us": "US-TX", + "name": "Texas", + "type": "state" + }, + { + "file": "87db.png", + "code": "UT", + "alpha2": "UT", + "alpah2Us": "US-UT", + "name": "Utah", + "type": "state" + }, + { + "file": "3a11.png", + "code": "VA", + "alpha2": "VA", + "alpah2Us": "US-VA", + "name": "Virginia", + "type": "state" + }, + { + "file": "8930.png", + "code": "VI", + "alpha2": "VI", + "alpah2Us": "US-VI", + "name": "Virgin Islands, U.S.", + "type": "outlying area" + }, + { + "file": "072b.png", + "code": "VT", + "alpha2": "VT", + "alpah2Us": "US-VT", + "name": "Vermont", + "type": "state" + }, + { + "file": "4306.png", + "code": "WA", + "alpha2": "WA", + "alpah2Us": "US-WA", + "name": "Washington", + "type": "state" + }, + { + "file": "04b0.png", + "code": "WI", + "alpha2": "WI", + "alpah2Us": "US-WI", + "name": "Wisconsin", + "type": "state" + }, + { + "file": "b484.png", + "code": "WV", + "alpha2": "WV", + "alpah2Us": "US-WV", + "name": "West Virginia", + "type": "state" + }, + { + "file": "0518.png", + "code": "WY", + "alpha2": "WY", + "alpah2Us": "US-WY", + "name": "Wyoming", + "type": "state" + } +] \ No newline at end of file diff --git a/assets/states-us.json b/assets/states-us.json new file mode 100644 index 0000000..6c14763 --- /dev/null +++ b/assets/states-us.json @@ -0,0 +1,344 @@ +[ + { + "alpha2": "AL", + "alpah2Us": "US-AL", + "name": "Alabama", + "type": "state" + }, + { + "alpha2": "AK", + "alpah2Us": "US-AK", + "name": "Alaska", + "type": "state" + }, + { + "alpha2": "AZ", + "alpah2Us": "US-AZ", + "name": "Arizona", + "type": "state" + }, + { + "alpha2": "AR", + "alpah2Us": "US-AR", + "name": "Arkansas", + "type": "state" + }, + { + "alpha2": "CA", + "alpah2Us": "US-CA", + "name": "California", + "type": "state" + }, + { + "alpha2": "CO", + "alpah2Us": "US-CO", + "name": "Colorado", + "type": "state" + }, + { + "alpha2": "CT", + "alpah2Us": "US-CT", + "name": "Connecticut", + "type": "state" + }, + { + "alpha2": "DE", + "alpah2Us": "US-DE", + "name": "Delaware", + "type": "state" + }, + { + "alpha2": "FL", + "alpah2Us": "US-FL", + "name": "Florida", + "type": "state" + }, + { + "alpha2": "GA", + "alpah2Us": "US-GA", + "name": "Georgia", + "type": "state" + }, + { + "alpha2": "HI", + "alpah2Us": "US-HI", + "name": "Hawaii", + "type": "state" + }, + { + "alpha2": "ID", + "alpah2Us": "US-ID", + "name": "Idaho", + "type": "state" + }, + { + "alpha2": "IL", + "alpah2Us": "US-IL", + "name": "Illinois", + "type": "state" + }, + { + "alpha2": "IN", + "alpah2Us": "US-IN", + "name": "Indiana", + "type": "state" + }, + { + "alpha2": "IA", + "alpah2Us": "US-IA", + "name": "Iowa", + "type": "state" + }, + { + "alpha2": "KS", + "alpah2Us": "US-KS", + "name": "Kansas", + "type": "state" + }, + { + "alpha2": "KY", + "alpah2Us": "US-KY", + "name": "Kentucky", + "type": "state" + }, + { + "alpha2": "LA", + "alpah2Us": "US-LA", + "name": "Louisiana", + "type": "state" + }, + { + "alpha2": "ME", + "alpah2Us": "US-ME", + "name": "Maine", + "type": "state" + }, + { + "alpha2": "MD", + "alpah2Us": "US-MD", + "name": "Maryland", + "type": "state" + }, + { + "alpha2": "MA", + "alpah2Us": "US-MA", + "name": "Massachusetts", + "type": "state" + }, + { + "alpha2": "MI", + "alpah2Us": "US-MI", + "name": "Michigan", + "type": "state" + }, + { + "alpha2": "MN", + "alpah2Us": "US-MN", + "name": "Minnesota", + "type": "state" + }, + { + "alpha2": "MS", + "alpah2Us": "US-MS", + "name": "Mississippi", + "type": "state" + }, + { + "alpha2": "MO", + "alpah2Us": "US-MO", + "name": "Missouri", + "type": "state" + }, + { + "alpha2": "MT", + "alpah2Us": "US-MT", + "name": "Montana", + "type": "state" + }, + { + "alpha2": "NE", + "alpah2Us": "US-NE", + "name": "Nebraska", + "type": "state" + }, + { + "alpha2": "NV", + "alpah2Us": "US-NV", + "name": "Nevada", + "type": "state" + }, + { + "alpha2": "NH", + "alpah2Us": "US-NH", + "name": "New Hampshire", + "type": "state" + }, + { + "alpha2": "NJ", + "alpah2Us": "US-NJ", + "name": "New Jersey", + "type": "state" + }, + { + "alpha2": "NM", + "alpah2Us": "US-NM", + "name": "New Mexico", + "type": "state" + }, + { + "alpha2": "NY", + "alpah2Us": "US-NY", + "name": "New York", + "type": "state" + }, + { + "alpha2": "NC", + "alpah2Us": "US-NC", + "name": "North Carolina", + "type": "state" + }, + { + "alpha2": "ND", + "alpah2Us": "US-ND", + "name": "North Dakota", + "type": "state" + }, + { + "alpha2": "OH", + "alpah2Us": "US-OH", + "name": "Ohio", + "type": "state" + }, + { + "alpha2": "OK", + "alpah2Us": "US-OK", + "name": "Oklahoma", + "type": "state" + }, + { + "alpha2": "OR", + "alpah2Us": "US-OR", + "name": "Oregon", + "type": "state" + }, + { + "alpha2": "PA", + "alpah2Us": "US-PA", + "name": "Pennsylvania", + "type": "state" + }, + { + "alpha2": "RI", + "alpah2Us": "US-RI", + "name": "Rhode Island", + "type": "state" + }, + { + "alpha2": "SC", + "alpah2Us": "US-SC", + "name": "South Carolina", + "type": "state" + }, + { + "alpha2": "SD", + "alpah2Us": "US-SD", + "name": "South Dakota", + "type": "state" + }, + { + "alpha2": "TN", + "alpah2Us": "US-TN", + "name": "Tennessee", + "type": "state" + }, + { + "alpha2": "TX", + "alpah2Us": "US-TX", + "name": "Texas", + "type": "state" + }, + { + "alpha2": "UT", + "alpah2Us": "US-UT", + "name": "Utah", + "type": "state" + }, + { + "alpha2": "VT", + "alpah2Us": "US-VT", + "name": "Vermont", + "type": "state" + }, + { + "alpha2": "VA", + "alpah2Us": "US-VA", + "name": "Virginia", + "type": "state" + }, + { + "alpha2": "WA", + "alpah2Us": "US-WA", + "name": "Washington", + "type": "state" + }, + { + "alpha2": "WV", + "alpah2Us": "US-WV", + "name": "West Virginia", + "type": "state" + }, + { + "alpha2": "WI", + "alpah2Us": "US-WI", + "name": "Wisconsin", + "type": "state" + }, + { + "alpha2": "WY", + "alpah2Us": "US-WY", + "name": "Wyoming", + "type": "state" + }, + { + "alpha2": "DC", + "alpah2Us": "US-DC", + "name": "District of Columbia", + "type": "district" + }, + { + "alpha2": "AS", + "alpah2Us": "US-AS", + "name": "American Samoa", + "type": "outlying area" + }, + { + "alpha2": "GU", + "alpah2Us": "US-GU", + "name": "Guam", + "type": "outlying area" + }, + { + "alpha2": "MP", + "alpah2Us": "US-MP", + "name": "Northern Mariana Islands", + "type": "outlying area" + }, + { + "alpha2": "PR", + "alpah2Us": "US-PR", + "name": "Puerto Rico", + "type": "outlying area" + }, + { + "alpha2": "UM", + "alpah2Us": "US-UM", + "name": "United States Minor Outlying Islands", + "type": "outlying area" + }, + { + "alpha2": "VI", + "alpah2Us": "US-VI", + "name": "Virgin Islands, U.S.", + "type": "outlying area" + } +] diff --git a/assets/states/AK.png b/assets/states/AK.png new file mode 100644 index 0000000..48d1c18 Binary files /dev/null and b/assets/states/AK.png differ diff --git a/assets/states/AL.png b/assets/states/AL.png new file mode 100644 index 0000000..70ed581 Binary files /dev/null and b/assets/states/AL.png differ diff --git a/assets/states/AR.png b/assets/states/AR.png new file mode 100644 index 0000000..5f90291 Binary files /dev/null and b/assets/states/AR.png differ diff --git a/assets/states/AS.png b/assets/states/AS.png new file mode 100644 index 0000000..9bd0404 Binary files /dev/null and b/assets/states/AS.png differ diff --git a/assets/states/AZ.png b/assets/states/AZ.png new file mode 100644 index 0000000..3f0f851 Binary files /dev/null and b/assets/states/AZ.png differ diff --git a/assets/states/CA.png b/assets/states/CA.png new file mode 100644 index 0000000..e6dbc99 Binary files /dev/null and b/assets/states/CA.png differ diff --git a/assets/states/CO.png b/assets/states/CO.png new file mode 100644 index 0000000..deef48d Binary files /dev/null and b/assets/states/CO.png differ diff --git a/assets/states/CT.png b/assets/states/CT.png new file mode 100644 index 0000000..7146aa8 Binary files /dev/null and b/assets/states/CT.png differ diff --git a/assets/states/DE.png b/assets/states/DE.png new file mode 100644 index 0000000..ff6ff13 Binary files /dev/null and b/assets/states/DE.png differ diff --git a/assets/states/FL.png b/assets/states/FL.png new file mode 100644 index 0000000..9710d63 Binary files /dev/null and b/assets/states/FL.png differ diff --git a/assets/states/GA.png b/assets/states/GA.png new file mode 100644 index 0000000..16b1b4d Binary files /dev/null and b/assets/states/GA.png differ diff --git a/assets/states/GU.png b/assets/states/GU.png new file mode 100644 index 0000000..178a818 Binary files /dev/null and b/assets/states/GU.png differ diff --git a/assets/states/HI.png b/assets/states/HI.png new file mode 100644 index 0000000..ca02f7c Binary files /dev/null and b/assets/states/HI.png differ diff --git a/assets/states/IA.png b/assets/states/IA.png new file mode 100644 index 0000000..d045fd4 Binary files /dev/null and b/assets/states/IA.png differ diff --git a/assets/states/ID.png b/assets/states/ID.png new file mode 100644 index 0000000..07686b2 Binary files /dev/null and b/assets/states/ID.png differ diff --git a/assets/states/IL.png b/assets/states/IL.png new file mode 100644 index 0000000..6ac342f Binary files /dev/null and b/assets/states/IL.png differ diff --git a/assets/states/IN.png b/assets/states/IN.png new file mode 100644 index 0000000..db8d8b0 Binary files /dev/null and b/assets/states/IN.png differ diff --git a/assets/states/KS.png b/assets/states/KS.png new file mode 100644 index 0000000..912ce5c Binary files /dev/null and b/assets/states/KS.png differ diff --git a/assets/states/KY.png b/assets/states/KY.png new file mode 100644 index 0000000..a16e8b8 Binary files /dev/null and b/assets/states/KY.png differ diff --git a/assets/states/LA.png b/assets/states/LA.png new file mode 100644 index 0000000..0176fa1 Binary files /dev/null and b/assets/states/LA.png differ diff --git a/assets/states/MA.png b/assets/states/MA.png new file mode 100644 index 0000000..a9a2080 Binary files /dev/null and b/assets/states/MA.png differ diff --git a/assets/states/MD.png b/assets/states/MD.png new file mode 100644 index 0000000..c4a143e Binary files /dev/null and b/assets/states/MD.png differ diff --git a/assets/states/ME.png b/assets/states/ME.png new file mode 100644 index 0000000..016db7f Binary files /dev/null and b/assets/states/ME.png differ diff --git a/assets/states/MI.png b/assets/states/MI.png new file mode 100644 index 0000000..0e4a79d Binary files /dev/null and b/assets/states/MI.png differ diff --git a/assets/states/MN.png b/assets/states/MN.png new file mode 100644 index 0000000..a9ebd60 Binary files /dev/null and b/assets/states/MN.png differ diff --git a/assets/states/MO.png b/assets/states/MO.png new file mode 100644 index 0000000..676bb66 Binary files /dev/null and b/assets/states/MO.png differ diff --git a/assets/states/MP.png b/assets/states/MP.png new file mode 100644 index 0000000..4ad13fd Binary files /dev/null and b/assets/states/MP.png differ diff --git a/assets/states/MS.png b/assets/states/MS.png new file mode 100644 index 0000000..625bb74 Binary files /dev/null and b/assets/states/MS.png differ diff --git a/assets/states/MT.png b/assets/states/MT.png new file mode 100644 index 0000000..1936f08 Binary files /dev/null and b/assets/states/MT.png differ diff --git a/assets/states/NC.png b/assets/states/NC.png new file mode 100644 index 0000000..c81eb1b Binary files /dev/null and b/assets/states/NC.png differ diff --git a/assets/states/ND.png b/assets/states/ND.png new file mode 100644 index 0000000..9b5eaa3 Binary files /dev/null and b/assets/states/ND.png differ diff --git a/assets/states/NE.png b/assets/states/NE.png new file mode 100644 index 0000000..216b089 Binary files /dev/null and b/assets/states/NE.png differ diff --git a/assets/states/NH.png b/assets/states/NH.png new file mode 100644 index 0000000..24d7153 Binary files /dev/null and b/assets/states/NH.png differ diff --git a/assets/states/NJ.png b/assets/states/NJ.png new file mode 100644 index 0000000..bded751 Binary files /dev/null and b/assets/states/NJ.png differ diff --git a/assets/states/NM.png b/assets/states/NM.png new file mode 100644 index 0000000..b0296c4 Binary files /dev/null and b/assets/states/NM.png differ diff --git a/assets/states/NV.png b/assets/states/NV.png new file mode 100644 index 0000000..2411d44 Binary files /dev/null and b/assets/states/NV.png differ diff --git a/assets/states/NY.png b/assets/states/NY.png new file mode 100644 index 0000000..56a49f4 Binary files /dev/null and b/assets/states/NY.png differ diff --git a/assets/states/OH.png b/assets/states/OH.png new file mode 100644 index 0000000..20df388 Binary files /dev/null and b/assets/states/OH.png differ diff --git a/assets/states/OK.png b/assets/states/OK.png new file mode 100644 index 0000000..5b49ab3 Binary files /dev/null and b/assets/states/OK.png differ diff --git a/assets/states/OR.png b/assets/states/OR.png new file mode 100644 index 0000000..d3b76cc Binary files /dev/null and b/assets/states/OR.png differ diff --git a/assets/states/PA.png b/assets/states/PA.png new file mode 100644 index 0000000..3691f58 Binary files /dev/null and b/assets/states/PA.png differ diff --git a/assets/states/PR.png b/assets/states/PR.png new file mode 100644 index 0000000..d2469c4 Binary files /dev/null and b/assets/states/PR.png differ diff --git a/assets/states/RI.png b/assets/states/RI.png new file mode 100644 index 0000000..5294ae9 Binary files /dev/null and b/assets/states/RI.png differ diff --git a/assets/states/SC.png b/assets/states/SC.png new file mode 100644 index 0000000..15a2f1e Binary files /dev/null and b/assets/states/SC.png differ diff --git a/assets/states/SD.png b/assets/states/SD.png new file mode 100644 index 0000000..e8e7d11 Binary files /dev/null and b/assets/states/SD.png differ diff --git a/assets/states/TN.png b/assets/states/TN.png new file mode 100644 index 0000000..f3c4c31 Binary files /dev/null and b/assets/states/TN.png differ diff --git a/assets/states/TX.png b/assets/states/TX.png new file mode 100644 index 0000000..a0dd2ba Binary files /dev/null and b/assets/states/TX.png differ diff --git a/assets/states/UT.png b/assets/states/UT.png new file mode 100644 index 0000000..a982f61 Binary files /dev/null and b/assets/states/UT.png differ diff --git a/assets/states/VA.png b/assets/states/VA.png new file mode 100644 index 0000000..255e166 Binary files /dev/null and b/assets/states/VA.png differ diff --git a/assets/states/VI.png b/assets/states/VI.png new file mode 100644 index 0000000..1902626 Binary files /dev/null and b/assets/states/VI.png differ diff --git a/assets/states/VT.png b/assets/states/VT.png new file mode 100644 index 0000000..8e55fc2 Binary files /dev/null and b/assets/states/VT.png differ diff --git a/assets/states/WA.png b/assets/states/WA.png new file mode 100644 index 0000000..ab04af6 Binary files /dev/null and b/assets/states/WA.png differ diff --git a/assets/states/WI.png b/assets/states/WI.png new file mode 100644 index 0000000..79c88a5 Binary files /dev/null and b/assets/states/WI.png differ diff --git a/assets/states/WV.png b/assets/states/WV.png new file mode 100644 index 0000000..9a86199 Binary files /dev/null and b/assets/states/WV.png differ diff --git a/assets/states/WY.png b/assets/states/WY.png new file mode 100644 index 0000000..9807748 Binary files /dev/null and b/assets/states/WY.png differ diff --git a/assets/states/encoded/04b0.png b/assets/states/encoded/04b0.png new file mode 100644 index 0000000..79c88a5 Binary files /dev/null and b/assets/states/encoded/04b0.png differ diff --git a/assets/states/encoded/0518.png b/assets/states/encoded/0518.png new file mode 100644 index 0000000..9807748 Binary files /dev/null and b/assets/states/encoded/0518.png differ diff --git a/assets/states/encoded/06f6.png b/assets/states/encoded/06f6.png new file mode 100644 index 0000000..3691f58 Binary files /dev/null and b/assets/states/encoded/06f6.png differ diff --git a/assets/states/encoded/072b.png b/assets/states/encoded/072b.png new file mode 100644 index 0000000..8e55fc2 Binary files /dev/null and b/assets/states/encoded/072b.png differ diff --git a/assets/states/encoded/08ad.png b/assets/states/encoded/08ad.png new file mode 100644 index 0000000..1936f08 Binary files /dev/null and b/assets/states/encoded/08ad.png differ diff --git a/assets/states/encoded/0fe7.png b/assets/states/encoded/0fe7.png new file mode 100644 index 0000000..d2469c4 Binary files /dev/null and b/assets/states/encoded/0fe7.png differ diff --git a/assets/states/encoded/112c.png b/assets/states/encoded/112c.png new file mode 100644 index 0000000..7146aa8 Binary files /dev/null and b/assets/states/encoded/112c.png differ diff --git a/assets/states/encoded/1d00.png b/assets/states/encoded/1d00.png new file mode 100644 index 0000000..d3b76cc Binary files /dev/null and b/assets/states/encoded/1d00.png differ diff --git a/assets/states/encoded/2a60.png b/assets/states/encoded/2a60.png new file mode 100644 index 0000000..a9a2080 Binary files /dev/null and b/assets/states/encoded/2a60.png differ diff --git a/assets/states/encoded/2cff.png b/assets/states/encoded/2cff.png new file mode 100644 index 0000000..5294ae9 Binary files /dev/null and b/assets/states/encoded/2cff.png differ diff --git a/assets/states/encoded/3053.png b/assets/states/encoded/3053.png new file mode 100644 index 0000000..178a818 Binary files /dev/null and b/assets/states/encoded/3053.png differ diff --git a/assets/states/encoded/38f9.png b/assets/states/encoded/38f9.png new file mode 100644 index 0000000..e8e7d11 Binary files /dev/null and b/assets/states/encoded/38f9.png differ diff --git a/assets/states/encoded/3a11.png b/assets/states/encoded/3a11.png new file mode 100644 index 0000000..255e166 Binary files /dev/null and b/assets/states/encoded/3a11.png differ diff --git a/assets/states/encoded/3a52.png b/assets/states/encoded/3a52.png new file mode 100644 index 0000000..ff6ff13 Binary files /dev/null and b/assets/states/encoded/3a52.png differ diff --git a/assets/states/encoded/3e8d.png b/assets/states/encoded/3e8d.png new file mode 100644 index 0000000..e6dbc99 Binary files /dev/null and b/assets/states/encoded/3e8d.png differ diff --git a/assets/states/encoded/4298.png b/assets/states/encoded/4298.png new file mode 100644 index 0000000..deef48d Binary files /dev/null and b/assets/states/encoded/4298.png differ diff --git a/assets/states/encoded/4306.png b/assets/states/encoded/4306.png new file mode 100644 index 0000000..ab04af6 Binary files /dev/null and b/assets/states/encoded/4306.png differ diff --git a/assets/states/encoded/5343.png b/assets/states/encoded/5343.png new file mode 100644 index 0000000..2411d44 Binary files /dev/null and b/assets/states/encoded/5343.png differ diff --git a/assets/states/encoded/546a.png b/assets/states/encoded/546a.png new file mode 100644 index 0000000..3f0f851 Binary files /dev/null and b/assets/states/encoded/546a.png differ diff --git a/assets/states/encoded/5b61.png b/assets/states/encoded/5b61.png new file mode 100644 index 0000000..5f90291 Binary files /dev/null and b/assets/states/encoded/5b61.png differ diff --git a/assets/states/encoded/631d.png b/assets/states/encoded/631d.png new file mode 100644 index 0000000..48d1c18 Binary files /dev/null and b/assets/states/encoded/631d.png differ diff --git a/assets/states/encoded/6a65.png b/assets/states/encoded/6a65.png new file mode 100644 index 0000000..15a2f1e Binary files /dev/null and b/assets/states/encoded/6a65.png differ diff --git a/assets/states/encoded/6b40.png b/assets/states/encoded/6b40.png new file mode 100644 index 0000000..0176fa1 Binary files /dev/null and b/assets/states/encoded/6b40.png differ diff --git a/assets/states/encoded/7a66.png b/assets/states/encoded/7a66.png new file mode 100644 index 0000000..625bb74 Binary files /dev/null and b/assets/states/encoded/7a66.png differ diff --git a/assets/states/encoded/7dc1.png b/assets/states/encoded/7dc1.png new file mode 100644 index 0000000..c4a143e Binary files /dev/null and b/assets/states/encoded/7dc1.png differ diff --git a/assets/states/encoded/8690.png b/assets/states/encoded/8690.png new file mode 100644 index 0000000..a0dd2ba Binary files /dev/null and b/assets/states/encoded/8690.png differ diff --git a/assets/states/encoded/87db.png b/assets/states/encoded/87db.png new file mode 100644 index 0000000..a982f61 Binary files /dev/null and b/assets/states/encoded/87db.png differ diff --git a/assets/states/encoded/8858.png b/assets/states/encoded/8858.png new file mode 100644 index 0000000..6ac342f Binary files /dev/null and b/assets/states/encoded/8858.png differ diff --git a/assets/states/encoded/8930.png b/assets/states/encoded/8930.png new file mode 100644 index 0000000..1902626 Binary files /dev/null and b/assets/states/encoded/8930.png differ diff --git a/assets/states/encoded/9058.png b/assets/states/encoded/9058.png new file mode 100644 index 0000000..c81eb1b Binary files /dev/null and b/assets/states/encoded/9058.png differ diff --git a/assets/states/encoded/93a2.png b/assets/states/encoded/93a2.png new file mode 100644 index 0000000..56a49f4 Binary files /dev/null and b/assets/states/encoded/93a2.png differ diff --git a/assets/states/encoded/943a.png b/assets/states/encoded/943a.png new file mode 100644 index 0000000..a9ebd60 Binary files /dev/null and b/assets/states/encoded/943a.png differ diff --git a/assets/states/encoded/947d.png b/assets/states/encoded/947d.png new file mode 100644 index 0000000..f3c4c31 Binary files /dev/null and b/assets/states/encoded/947d.png differ diff --git a/assets/states/encoded/9a11.png b/assets/states/encoded/9a11.png new file mode 100644 index 0000000..9b5eaa3 Binary files /dev/null and b/assets/states/encoded/9a11.png differ diff --git a/assets/states/encoded/9b38.png b/assets/states/encoded/9b38.png new file mode 100644 index 0000000..0e4a79d Binary files /dev/null and b/assets/states/encoded/9b38.png differ diff --git a/assets/states/encoded/9ee9.png b/assets/states/encoded/9ee9.png new file mode 100644 index 0000000..016db7f Binary files /dev/null and b/assets/states/encoded/9ee9.png differ diff --git a/assets/states/encoded/a2c2.png b/assets/states/encoded/a2c2.png new file mode 100644 index 0000000..9bd0404 Binary files /dev/null and b/assets/states/encoded/a2c2.png differ diff --git a/assets/states/encoded/a323.png b/assets/states/encoded/a323.png new file mode 100644 index 0000000..912ce5c Binary files /dev/null and b/assets/states/encoded/a323.png differ diff --git a/assets/states/encoded/ac71.png b/assets/states/encoded/ac71.png new file mode 100644 index 0000000..9710d63 Binary files /dev/null and b/assets/states/encoded/ac71.png differ diff --git a/assets/states/encoded/b484.png b/assets/states/encoded/b484.png new file mode 100644 index 0000000..9a86199 Binary files /dev/null and b/assets/states/encoded/b484.png differ diff --git a/assets/states/encoded/b718.png b/assets/states/encoded/b718.png new file mode 100644 index 0000000..07686b2 Binary files /dev/null and b/assets/states/encoded/b718.png differ diff --git a/assets/states/encoded/b8ea.png b/assets/states/encoded/b8ea.png new file mode 100644 index 0000000..a16e8b8 Binary files /dev/null and b/assets/states/encoded/b8ea.png differ diff --git a/assets/states/encoded/b972.png b/assets/states/encoded/b972.png new file mode 100644 index 0000000..d045fd4 Binary files /dev/null and b/assets/states/encoded/b972.png differ diff --git a/assets/states/encoded/bf8c.png b/assets/states/encoded/bf8c.png new file mode 100644 index 0000000..ca02f7c Binary files /dev/null and b/assets/states/encoded/bf8c.png differ diff --git a/assets/states/encoded/c86e.png b/assets/states/encoded/c86e.png new file mode 100644 index 0000000..db8d8b0 Binary files /dev/null and b/assets/states/encoded/c86e.png differ diff --git a/assets/states/encoded/c90a.png b/assets/states/encoded/c90a.png new file mode 100644 index 0000000..4ad13fd Binary files /dev/null and b/assets/states/encoded/c90a.png differ diff --git a/assets/states/encoded/cd95.png b/assets/states/encoded/cd95.png new file mode 100644 index 0000000..16b1b4d Binary files /dev/null and b/assets/states/encoded/cd95.png differ diff --git a/assets/states/encoded/d41b.png b/assets/states/encoded/d41b.png new file mode 100644 index 0000000..24d7153 Binary files /dev/null and b/assets/states/encoded/d41b.png differ diff --git a/assets/states/encoded/dc33.png b/assets/states/encoded/dc33.png new file mode 100644 index 0000000..216b089 Binary files /dev/null and b/assets/states/encoded/dc33.png differ diff --git a/assets/states/encoded/e0aa.png b/assets/states/encoded/e0aa.png new file mode 100644 index 0000000..5b49ab3 Binary files /dev/null and b/assets/states/encoded/e0aa.png differ diff --git a/assets/states/encoded/e0f3.png b/assets/states/encoded/e0f3.png new file mode 100644 index 0000000..b0296c4 Binary files /dev/null and b/assets/states/encoded/e0f3.png differ diff --git a/assets/states/encoded/e223.png b/assets/states/encoded/e223.png new file mode 100644 index 0000000..bded751 Binary files /dev/null and b/assets/states/encoded/e223.png differ diff --git a/assets/states/encoded/e892.png b/assets/states/encoded/e892.png new file mode 100644 index 0000000..70ed581 Binary files /dev/null and b/assets/states/encoded/e892.png differ diff --git a/assets/states/encoded/eb04.png b/assets/states/encoded/eb04.png new file mode 100644 index 0000000..676bb66 Binary files /dev/null and b/assets/states/encoded/eb04.png differ diff --git a/assets/states/encoded/ec94.png b/assets/states/encoded/ec94.png new file mode 100644 index 0000000..20df388 Binary files /dev/null and b/assets/states/encoded/ec94.png differ diff --git a/config/default.js b/config/default.js index 226df9e..e4b0f7e 100755 --- a/config/default.js +++ b/config/default.js @@ -94,6 +94,6 @@ module.exports = { // guesses: [2, 3, 4, 5, 6, 7], // by word length, last number repeats for longer words }, geo: { - url: 'https://countries.unknown.name/', + url: 'https://geo.unknown.name/', }, }; diff --git a/src/games/geo.js b/src/games/geo.js index d97a107..89d2162 100644 --- a/src/games/geo.js +++ b/src/games/geo.js @@ -4,10 +4,16 @@ const config = require('config'); const timers = require('timers/promises'); const countries = require('../../assets/countries-curated.json'); +const states = require('../../assets/states-curated.json'); const pickRandom = require('../utils/pick-random'); const style = require('../utils/style'); -const games = new Map(); +const data = { countries, states }; + +const games = { + countries: new Map(), + states: new Map(), +}; const questions = [ 'What\'s this country?', @@ -27,12 +33,13 @@ function hint(game, context) { context.sendMessage(`${style.bold(`${game.name.slice(0, 1)} ${game.name.slice(1).replace(/\s/g, ' ').replace(/[^\s]/g, '_ ').trim()}`.toUpperCase())}, the country code is ${style.bold(game.alpha2)}`, context.room.id); // eslint-disable-line no-irregular-whitespace } -function play(context) { - const country = pickRandom(countries); - const url = `${config.geo.url}${country.file}`; +function play(context, type = 'countries') { + const country = pickRandom(data[type]); + const url = `${config.geo.url}${type}/${country.file}`; - games.set(context.room.id, { + games[type].set(context.room.id, { ...country, + type, url, regexp: new RegExp(country.fullName ? `(${country.name})|(${country.fullName})` : country.name, 'i'), }); @@ -42,21 +49,23 @@ function play(context) { } async function onCommand(args, context) { - if (context.subcommand && !games.has(context.room.id)) { + const type = ['state', 'america'].includes(context.command) ? 'states' : 'countries'; + + if (context.subcommand && !games[type].has(context.room.id)) { context.sendMessage(`There is no country in play right now. Start a new round with ${config.prefix}geo!`, context.room.id); return; } if (['skip', 'stop', 'reset'].includes(context.subcommand)) { - const game = games.get(context.room.id); + const game = games[type].get(context.room.id); - games.delete(context.room.id); + games[type].delete(context.room.id); context.sendMessage(`Geo was skipped by ${context.user.prefixedUsername}. The country was ${style.bold(game.fullName ? `${game.fullName} (${game.name})` : game.name)}.`, context.room.id); await timers.setTimeout(2000); } - const game = games.get(context.room.id); + const game = games[type].get(context.room.id); if (context.subcommand === 'hint') { hint(game, context); @@ -68,31 +77,33 @@ async function onCommand(args, context) { return; } - play(context); + play(context, type); } async function onMessage(message, context) { - const game = games.get(context.room.id); + ['countries', 'states'].forEach(async (type) => { + const game = games[type].get(context.room.id); - if (!game) { - return; - } + if (!game) { + return; + } - if (game.regexp.test(message.body)) { - context.sendMessage(`${style.answer(game.fullName || game.name)} is the right answer! ${style.username(context.user.prefixedUsername)} gets a point.`, context.room.id); - context.setPoints(context.user); + if (game.regexp.test(message.body)) { + context.sendMessage(`${style.answer(game.fullName || game.name)} is the right answer! ${style.username(context.user.prefixedUsername)} gets a point.`, context.room.id); + context.setPoints(context.user); - games.delete(context.room.id); + games[type].delete(context.room.id); - await timers.setTimeout(3000); + await timers.setTimeout(3000); - play(context); - } + play(context, type); + } + }); } module.exports = { onCommand, onMessage, - commands: ['country', 'atlas'], + commands: ['country', 'atlas', 'state', 'america'], help: 'Name the country on the map! Too hard? Try ~geo:hint or ~geo:skip.', };