From 2263059c501877e892fafd0d4a7c6c0fe99d17cb Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 27 Jun 2021 15:12:02 -0600 Subject: [PATCH] Add lookup table for country codes --- jarvis/cogs/dbrand.py | 16 ++- jarvis/data/dbrand.py | 254 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+), 4 deletions(-) diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index 18f79fe..88b5c08 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -5,7 +5,7 @@ import html from jarvis.config import get_config from jarvis.utils import build_embed from jarvis.utils.field import Field -from jarvis.data.dbrand import shipping_array +from jarvis.data.dbrand import shipping_lookup from discord.ext import commands @@ -35,18 +35,26 @@ class DbrandCog(commands.Cog): async def _skin(self, ctx): await ctx.send(self.base_url + "shop/skins") - @_db.command(name="grip") + @_db.command(name="grip", aliases=["g", "case"]) async def _grip(self, ctx): await ctx.send(self.base_url + "shop/grip/#grip-devices") - @_db.command(name="support") + @_db.command(name="support", aliases=["help", "contact"]) async def _support(self, ctx): await ctx.send(self.base_url + "contact") - @_db.command(name="shipping") + @_db.command(name="shipping", aliases=["ship", "s"]) async def _shipping(self, ctx, *, search: str): if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE): await ctx.send("Please use text to search for shipping.") + if len(search) > 2: + matches = [ + x["code"] + for x in shipping_lookup + if search.lower() in x["country"] + ] + if len(matches) > 0: + search = matches[0] dest = search api_link = self.api_url + dest try: diff --git a/jarvis/data/dbrand.py b/jarvis/data/dbrand.py index 77b877b..5c96d6e 100644 --- a/jarvis/data/dbrand.py +++ b/jarvis/data/dbrand.py @@ -250,6 +250,260 @@ shipping_array = [ "zambia", "zimbabwe", ] +shipping_lookup = [ + {"country": "afghanistan", "code": "AF"}, + {"country": "albania", "code": "AL"}, + {"country": "algeria", "code": "DZ"}, + {"country": "american samoa", "code": "AS"}, + {"country": "andorra", "code": "AD"}, + {"country": "angola", "code": "AO"}, + {"country": "anguilla", "code": "AI"}, + {"country": "antarctica", "code": "AQ"}, + {"country": "antigua and barbuda", "code": "AG"}, + {"country": "argentina", "code": "AR"}, + {"country": "armenia", "code": "AM"}, + {"country": "aruba", "code": "AW"}, + {"country": "australia", "code": "AU"}, + {"country": "austria", "code": "AT"}, + {"country": "azerbaijan", "code": "AZ"}, + {"country": "bahamas (the)", "code": "BS"}, + {"country": "bahrain", "code": "BH"}, + {"country": "bangladesh", "code": "BD"}, + {"country": "barbados", "code": "BB"}, + {"country": "belarus", "code": "BY"}, + {"country": "belgium", "code": "BE"}, + {"country": "belize", "code": "BZ"}, + {"country": "benin", "code": "BJ"}, + {"country": "bermuda", "code": "BM"}, + {"country": "bhutan", "code": "BT"}, + {"country": "bolivia (plurinational state of)", "code": "BO"}, + {"country": "bonaire, sint eustatius and saba", "code": "BQ"}, + {"country": "bosnia and herzegovina", "code": "BA"}, + {"country": "botswana", "code": "BW"}, + {"country": "bouvet island", "code": "BV"}, + {"country": "brazil", "code": "BR"}, + {"country": "british indian ocean territory (the)", "code": "IO"}, + {"country": "brunei darussalam", "code": "BN"}, + {"country": "bulgaria", "code": "BG"}, + {"country": "burkina faso", "code": "BF"}, + {"country": "burundi", "code": "BI"}, + {"country": "cabo verde", "code": "CV"}, + {"country": "cambodia", "code": "KH"}, + {"country": "cameroon", "code": "CM"}, + {"country": "canada", "code": "CA"}, + {"country": "cayman islands (the)", "code": "KY"}, + {"country": "central african republic (the)", "code": "CF"}, + {"country": "chad", "code": "TD"}, + {"country": "chile", "code": "CL"}, + {"country": "china", "code": "CN"}, + {"country": "christmas island", "code": "CX"}, + {"country": "cocos (keeling) islands (the)", "code": "CC"}, + {"country": "colombia", "code": "CO"}, + {"country": "comoros (the)", "code": "KM"}, + {"country": "congo (the democratic republic of the)", "code": "CD"}, + {"country": "congo (the)", "code": "CG"}, + {"country": "cook islands (the)", "code": "CK"}, + {"country": "costa rica", "code": "CR"}, + {"country": "croatia", "code": "HR"}, + {"country": "cuba", "code": "CU"}, + {"country": "curaçao", "code": "CW"}, + {"country": "cyprus", "code": "CY"}, + {"country": "czechia", "code": "CZ"}, + {"country": "côte d'ivoire", "code": "CI"}, + {"country": "denmark", "code": "DK"}, + {"country": "djibouti", "code": "DJ"}, + {"country": "dominica", "code": "DM"}, + {"country": "dominican republic (the)", "code": "DO"}, + {"country": "ecuador", "code": "EC"}, + {"country": "egypt", "code": "EG"}, + {"country": "el salvador", "code": "SV"}, + {"country": "equatorial guinea", "code": "GQ"}, + {"country": "eritrea", "code": "ER"}, + {"country": "estonia", "code": "EE"}, + {"country": "eswatini", "code": "SZ"}, + {"country": "ethiopia", "code": "ET"}, + {"country": "falkland islands (the) [malvinas]", "code": "FK"}, + {"country": "faroe islands (the)", "code": "FO"}, + {"country": "fiji", "code": "FJ"}, + {"country": "finland", "code": "FI"}, + {"country": "france", "code": "FR"}, + {"country": "french guiana", "code": "GF"}, + {"country": "french polynesia", "code": "PF"}, + {"country": "french southern territories (the)", "code": "TF"}, + {"country": "gabon", "code": "GA"}, + {"country": "gambia (the)", "code": "GM"}, + {"country": "georgia", "code": "GE"}, + {"country": "germany", "code": "DE"}, + {"country": "ghana", "code": "GH"}, + {"country": "gibraltar", "code": "GI"}, + {"country": "greece", "code": "GR"}, + {"country": "greenland", "code": "GL"}, + {"country": "grenada", "code": "GD"}, + {"country": "guadeloupe", "code": "GP"}, + {"country": "guam", "code": "GU"}, + {"country": "guatemala", "code": "GT"}, + {"country": "guernsey", "code": "GG"}, + {"country": "guinea", "code": "GN"}, + {"country": "guinea-bissau", "code": "GW"}, + {"country": "guyana", "code": "GY"}, + {"country": "haiti", "code": "HT"}, + {"country": "heard island and mcdonald islands", "code": "HM"}, + {"country": "holy see (the)", "code": "VA"}, + {"country": "honduras", "code": "HN"}, + {"country": "hong kong", "code": "HK"}, + {"country": "hungary", "code": "HU"}, + {"country": "iceland", "code": "IS"}, + {"country": "india", "code": "IN"}, + {"country": "indonesia", "code": "ID"}, + {"country": "iran (islamic republic of)", "code": "IR"}, + {"country": "iraq", "code": "IQ"}, + {"country": "ireland", "code": "IE"}, + {"country": "isle of man", "code": "IM"}, + {"country": "israel", "code": "IL"}, + {"country": "italy", "code": "IT"}, + {"country": "jamaica", "code": "JM"}, + {"country": "japan", "code": "JP"}, + {"country": "jersey", "code": "JE"}, + {"country": "jordan", "code": "JO"}, + {"country": "kazakhstan", "code": "KZ"}, + {"country": "kenya", "code": "KE"}, + {"country": "kiribati", "code": "KI"}, + {"country": "korea (the democratic people's republic of)", "code": "KP"}, + {"country": "korea (the republic of)", "code": "KR"}, + {"country": "kuwait", "code": "KW"}, + {"country": "kyrgyzstan", "code": "KG"}, + {"country": "lao people's democratic republic (the)", "code": "LA"}, + {"country": "latvia", "code": "LV"}, + {"country": "lebanon", "code": "LB"}, + {"country": "lesotho", "code": "LS"}, + {"country": "liberia", "code": "LR"}, + {"country": "libya", "code": "LY"}, + {"country": "liechtenstein", "code": "LI"}, + {"country": "lithuania", "code": "LT"}, + {"country": "luxembourg", "code": "LU"}, + {"country": "macao", "code": "MO"}, + {"country": "madagascar", "code": "MG"}, + {"country": "malawi", "code": "MW"}, + {"country": "malaysia", "code": "MY"}, + {"country": "maldives", "code": "MV"}, + {"country": "mali", "code": "ML"}, + {"country": "malta", "code": "MT"}, + {"country": "marshall islands (the)", "code": "MH"}, + {"country": "martinique", "code": "MQ"}, + {"country": "mauritania", "code": "MR"}, + {"country": "mauritius", "code": "MU"}, + {"country": "mayotte", "code": "YT"}, + {"country": "mexico", "code": "MX"}, + {"country": "micronesia (federated states of)", "code": "FM"}, + {"country": "moldova (the republic of)", "code": "MD"}, + {"country": "monaco", "code": "MC"}, + {"country": "mongolia", "code": "MN"}, + {"country": "montenegro", "code": "ME"}, + {"country": "montserrat", "code": "MS"}, + {"country": "morocco", "code": "MA"}, + {"country": "mozambique", "code": "MZ"}, + {"country": "myanmar", "code": "MM"}, + {"country": "namibia", "code": "NA"}, + {"country": "nauru", "code": "NR"}, + {"country": "nepal", "code": "NP"}, + {"country": "netherlands (the)", "code": "NL"}, + {"country": "new caledonia", "code": "NC"}, + {"country": "new zealand", "code": "NZ"}, + {"country": "nicaragua", "code": "NI"}, + {"country": "niger (the)", "code": "NE"}, + {"country": "nigeria", "code": "NG"}, + {"country": "niue", "code": "NU"}, + {"country": "norfolk island", "code": "NF"}, + {"country": "northern mariana islands (the)", "code": "MP"}, + {"country": "norway", "code": "NO"}, + {"country": "oman", "code": "OM"}, + {"country": "pakistan", "code": "PK"}, + {"country": "palau", "code": "PW"}, + {"country": "palestine, state of", "code": "PS"}, + {"country": "panama", "code": "PA"}, + {"country": "papua new guinea", "code": "PG"}, + {"country": "paraguay", "code": "PY"}, + {"country": "peru", "code": "PE"}, + {"country": "philippines (the)", "code": "PH"}, + {"country": "pitcairn", "code": "PN"}, + {"country": "poland", "code": "PL"}, + {"country": "portugal", "code": "PT"}, + {"country": "puerto rico", "code": "PR"}, + {"country": "qatar", "code": "QA"}, + {"country": "republic of north macedonia", "code": "MK"}, + {"country": "romania", "code": "RO"}, + {"country": "russian federation (the)", "code": "RU"}, + {"country": "rwanda", "code": "RW"}, + {"country": "réunion", "code": "RE"}, + {"country": "saint barthélemy", "code": "BL"}, + {"country": "saint helena, ascension and tristan da cunha", "code": "SH"}, + {"country": "saint kitts and nevis", "code": "KN"}, + {"country": "saint lucia", "code": "LC"}, + {"country": "saint martin (french part)", "code": "MF"}, + {"country": "saint pierre and miquelon", "code": "PM"}, + {"country": "saint vincent and the grenadines", "code": "VC"}, + {"country": "samoa", "code": "WS"}, + {"country": "san marino", "code": "SM"}, + {"country": "sao tome and principe", "code": "ST"}, + {"country": "saudi arabia", "code": "SA"}, + {"country": "senegal", "code": "SN"}, + {"country": "serbia", "code": "RS"}, + {"country": "seychelles", "code": "SC"}, + {"country": "sierra leone", "code": "SL"}, + {"country": "singapore", "code": "SG"}, + {"country": "sint maarten (dutch part)", "code": "SX"}, + {"country": "slovakia", "code": "SK"}, + {"country": "slovenia", "code": "SI"}, + {"country": "solomon islands", "code": "SB"}, + {"country": "somalia", "code": "SO"}, + {"country": "south africa", "code": "ZA"}, + {"country": "south georgia and the south sandwich islands", "code": "GS"}, + {"country": "south sudan", "code": "SS"}, + {"country": "spain", "code": "ES"}, + {"country": "sri lanka", "code": "LK"}, + {"country": "sudan (the)", "code": "SD"}, + {"country": "suriname", "code": "SR"}, + {"country": "svalbard and jan mayen", "code": "SJ"}, + {"country": "sweden", "code": "SE"}, + {"country": "switzerland", "code": "CH"}, + {"country": "syrian arab republic", "code": "SY"}, + {"country": "taiwan (province of china)", "code": "TW"}, + {"country": "tajikistan", "code": "TJ"}, + {"country": "tanzania, united republic of", "code": "TZ"}, + {"country": "thailand", "code": "TH"}, + {"country": "timor-leste", "code": "TL"}, + {"country": "togo", "code": "TG"}, + {"country": "tokelau", "code": "TK"}, + {"country": "tonga", "code": "TO"}, + {"country": "trinidad and tobago", "code": "TT"}, + {"country": "tunisia", "code": "TN"}, + {"country": "turkey", "code": "TR"}, + {"country": "turkmenistan", "code": "TM"}, + {"country": "turks and caicos islands (the)", "code": "TC"}, + {"country": "tuvalu", "code": "TV"}, + {"country": "uganda", "code": "UG"}, + {"country": "ukraine", "code": "UA"}, + {"country": "united arab emirates (the)", "code": "AE"}, + { + "country": "united kingdom of great britain and northern ireland (the)", + "code": "GB", + }, + {"country": "united states minor outlying islands (the)", "code": "UM"}, + {"country": "united states of america (the)", "code": "US"}, + {"country": "uruguay", "code": "UY"}, + {"country": "uzbekistan", "code": "UZ"}, + {"country": "vanuatu", "code": "VU"}, + {"country": "venezuela (bolivarian republic of)", "code": "VE"}, + {"country": "viet nam", "code": "VN"}, + {"country": "virgin islands (british)", "code": "VG"}, + {"country": "virgin islands (u.s.)", "code": "VI"}, + {"country": "wallis and futuna", "code": "WF"}, + {"country": "western sahara", "code": "EH"}, + {"country": "yemen", "code": "YE"}, + {"country": "zambia", "code": "ZM"}, + {"country": "zimbabwe", "code": "ZW"}, + {"country": "åland islands", "code": "AX"}, +] how_to_array = [ "https://dbrand.com/how-to-apply/airpower", "https://dbrand.com/how-to-apply/alienware-13-r3",