diff --git a/config.example.yaml b/config.example.yaml index d654f45..16e45f4 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -12,3 +12,6 @@ password: pass host: localhost port: 27017 + api_urls: + url_name: url + url_name2: url2 diff --git a/jarvis/__init__.py b/jarvis/__init__.py index ab22306..53815bd 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -73,5 +73,9 @@ def run(ctx=None): + "{}&permissions=8&scope=bot".format(config.client_id) ) jarvis.run(config.token, bot=True, reconnect=True) + for cog in jarvis.cogs: + session = getattr(cog, "_session", None) + if session: + session.close() if restart_ctx: return restart_ctx diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index a4212e0..18f79fe 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -1,520 +1,27 @@ import jarvis import re +import aiohttp +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 discord.ext import commands -DBRAND_DATA = { - "shippingArray": [ - "afghanistan", - "aland-islands", - "albania", - "algeria", - "american-samoa", - "andorra", - "angola", - "anguilla", - "antarctica", - "antigua-and-barbuda", - "argentina", - "armenia", - "aruba", - "australia", - "austria", - "azerbaijan", - "bahamas", - "bahrain", - "bangladesh", - "barbados", - "belarus", - "belgium", - "belize", - "benin", - "bermuda", - "bhutan", - "bolivia", - "bosnia-and-herzegovina", - "botswana", - "bouvet-island", - "brazil", - "british-indian-ocean-territory", - "british-virgin-islands", - "brunei", - "bulgaria", - "burkina-faso", - "burundi", - "cambodia", - "cameroon", - "canada", - "cape-verde", - "caribbean-netherlands", - "cayman-islands", - "central-african-republic", - "chad", - "chile", - "china", - "christmas-island", - "cocos-keeling-islands", - "colombia", - "comoros", - "congo-brazzaville", - "congo-kinshasa", - "cook-islands", - "costa-rica", - "croatia", - "cuba", - "cura%C3%A7ao", - "cyprus", - "czech-republic", - "denmark", - "djibouti", - "dominica", - "dominican-republic", - "ecuador", - "egypt", - "el-salvador", - "equatorial-guinea", - "eritrea", - "estonia", - "ethiopia", - "falkland-islands", - "faroe-islands", - "fiji", - "finland", - "france", - "french-guiana", - "french-polynesia", - "french-southern-territories", - "gabon", - "gambia", - "georgia", - "germany", - "ghana", - "gibraltar", - "greece", - "greenland", - "grenada", - "guadeloupe", - "guam", - "guatemala", - "guernsey", - "guinea", - "guinea-bissau", - "guyana", - "haiti", - "heard-island-and-mcdonald-islands", - "honduras", - "hong-kong-sar-china", - "hungary", - "iceland", - "india", - "indonesia", - "iran", - "iraq", - "ireland", - "isle-of-man", - "israel", - "italy", - "ivory-coast", - "jamaica", - "japan", - "jersey", - "jordan", - "kazakhstan", - "kenya", - "kiribati", - "kuwait", - "kyrgyzstan", - "laos", - "latvia", - "lebanon", - "lesotho", - "liberia", - "libya", - "liechtenstein", - "lithuania", - "luxembourg", - "macao-sar-china", - "macedonia", - "madagascar", - "malawi", - "malaysia", - "maldives", - "mali", - "malta", - "marshall-islands", - "martinique", - "mauritania", - "mauritius", - "mayotte", - "mexico", - "micronesia", - "moldova", - "monaco", - "mongolia", - "montenegro", - "montserrat", - "morocco", - "mozambique", - "myanmar", - "namibia", - "nauru", - "nepal", - "netherlands", - "netherlands-antilles", - "new-caledonia", - "new-zealand", - "nicaragua", - "niger", - "nigeria", - "niue", - "norfolk-island", - "northern-mariana-islands", - "north-korea", - "norway", - "oman", - "pakistan", - "palau", - "palestinian-territory", - "panama", - "papua-new-guinea", - "paraguay", - "peru", - "philippines", - "pitcairn", - "poland", - "portugal", - "puerto-rico", - "qatar", - "reunion", - "romania", - "russia", - "rwanda", - "saint-barth%C3%A9lemy", - "saint-helena", - "saint-kitts-and-nevis", - "saint-lucia", - "saint-martin-french-part", - "saint-pierre-and-miquelon", - "saint-vincent-and-the-grenadines", - "samoa", - "san-marino", - "sao-tome-and-principe", - "saudi-arabia", - "senegal", - "serbia", - "seychelles", - "sierra-leone", - "singapore", - "sint-maarten", - "slovakia", - "slovenia", - "solomon-islands", - "somalia", - "south-africa", - "south-georgia-and-the-south-sandwich-islands", - "south-korea", - "south-sudan", - "spain", - "sri-lanka", - "sudan", - "suriname", - "svalbard-and-jan-mayen", - "swaziland", - "sweden", - "switzerland", - "syria", - "taiwan", - "tajikistan", - "tanzania", - "thailand", - "timor-leste", - "togo", - "tokelau", - "tonga", - "trinidad-and-tobago", - "tunisia", - "turkey", - "turkmenistan", - "turks-and-caicos-islands", - "tuvalu", - "uganda", - "ukraine", - "united-arab-emirates", - "united-kingdom", - "united-states", - "united-states-minor-outlying-islands", - "uruguay", - "us-virgin-islands", - "uzbekistan", - "vanuatu", - "vatican", - "venezuela", - "vietnam", - "wallis-and-futuna", - "western-sahara", - "yemen", - "zambia", - "zimbabwe", - ], - "howtoArray": [ - "https://dbrand.com/how-to-apply/airpower", - "https://dbrand.com/how-to-apply/alienware-13-r3", - "https://dbrand.com/how-to-apply/alienware-15-r3", - "https://dbrand.com/how-to-apply/alienware-17-r4-eye-tracking", - "https://dbrand.com/how-to-apply/alienware-17-r4-no-eye-tracking", - "https://dbrand.com/how-to-apply/alienware-17-r5-eye-tracking", - "https://dbrand.com/how-to-apply/alienware-17-r5-no-eye-tracking", - "https://dbrand.com/how-to-apply/anker-powercore-13000-usb-c", - "https://dbrand.com/how-to-apply/anker-powercore-plus-20100-usb-c", - "https://dbrand.com/how-to-apply/anker-powercore-plus-26800-pd", - "https://dbrand.com/how-to-apply/anker-powercore-slim-10000-pd", - "https://dbrand.com/how-to-apply/apple-18w-usb-c-power-adapter", - "https://dbrand.com/how-to-apply/apple-5w-usb-power-adapter", - "https://dbrand.com/how-to-apply/apple-airpods-gen-1", - "https://dbrand.com/how-to-apply/apple-airpods-gen-2-no-wireless-charging", - "https://dbrand.com/how-to-apply/apple-airpods-gen-2-wireless-charging", - "https://dbrand.com/how-to-apply/apple-airpods-pro", - "https://dbrand.com/how-to-apply/apple-card", - "https://dbrand.com/how-to-apply/apple-pencil", - "https://dbrand.com/how-to-apply/apple-pencil-2", - "https://dbrand.com/how-to-apply/axon-7", - "https://dbrand.com/how-to-apply/blade-14-2014-2016-gtx-970m", - "https://dbrand.com/how-to-apply/blade-14-2016-2017-gtx-1060", - "https://dbrand.com/how-to-apply/blade-stealth-125-early-2016-skylake", - "https://dbrand.com/how-to-apply/blade-stealth-125-late-2016-2017-kaby-lake", - "https://dbrand.com/how-to-apply/blade-stealth-13.3-2017-2018", - "https://dbrand.com/how-to-apply/blade-stealth-13.3-early-2019", - "https://dbrand.com/how-to-apply/blade-stealth-13.3-late-2019", - "https://dbrand.com/how-to-apply/dell-xps-13-2-in-1-7390", - "https://dbrand.com/how-to-apply/dell-xps-13-2-in-1-9365", - "https://dbrand.com/how-to-apply/dell-xps-13-7390", - "https://dbrand.com/how-to-apply/dell-xps-13-9350-9360", - "https://dbrand.com/how-to-apply/dell-xps-15-9550", - "https://dbrand.com/how-to-apply/dell-xps-15-9560", - "https://dbrand.com/how-to-apply/eluktronics-mag-15", - "https://dbrand.com/how-to-apply/essential-phone", - "https://dbrand.com/how-to-apply/eve-v", - "https://dbrand.com/how-to-apply/galaxy-a50", - "https://dbrand.com/how-to-apply/galaxy-a70", - "https://dbrand.com/how-to-apply/galaxy-buds", - "https://dbrand.com/how-to-apply/galaxy-fold", - "https://dbrand.com/how-to-apply/galaxy-note-10", - "https://dbrand.com/how-to-apply/galaxy-note-10-plus", - "https://dbrand.com/how-to-apply/galaxy-note-10-plus-5g", - "https://dbrand.com/how-to-apply/galaxy-note-4", - "https://dbrand.com/how-to-apply/galaxy-note-5", - "https://dbrand.com/how-to-apply/galaxy-note-7", - "https://dbrand.com/how-to-apply/galaxy-note-8", - "https://dbrand.com/how-to-apply/galaxy-note-9", - "https://dbrand.com/how-to-apply/galaxy-note-fe", - "https://dbrand.com/how-to-apply/galaxy-s10", - "https://dbrand.com/how-to-apply/galaxy-s10-5g", - "https://dbrand.com/how-to-apply/galaxy-s10e", - "https://dbrand.com/how-to-apply/galaxy-s10-plus", - "https://dbrand.com/how-to-apply/galaxy-s6", - "https://dbrand.com/how-to-apply/galaxy-s6-active", - "https://dbrand.com/how-to-apply/galaxy-s6-edge", - "https://dbrand.com/how-to-apply/galaxy-s6-edge-plus", - "https://dbrand.com/how-to-apply/galaxy-s7", - "https://dbrand.com/how-to-apply/galaxy-s7-active", - "https://dbrand.com/how-to-apply/galaxy-s7-edge", - "https://dbrand.com/how-to-apply/galaxy-s8", - "https://dbrand.com/how-to-apply/galaxy-s8-active", - "https://dbrand.com/how-to-apply/galaxy-s8-plus", - "https://dbrand.com/how-to-apply/galaxy-s9", - "https://dbrand.com/how-to-apply/galaxy-s9-plus", - "https://dbrand.com/how-to-apply/google-home", - "https://dbrand.com/how-to-apply/honor-8", - "https://dbrand.com/how-to-apply/htc-10", - "https://dbrand.com/how-to-apply/htc-one-m7", - "https://dbrand.com/how-to-apply/htc-one-m8", - "https://dbrand.com/how-to-apply/htc-one-m9", - "https://dbrand.com/how-to-apply/htc-u-ultra", - "https://dbrand.com/how-to-apply/huawei-mate-10", - "https://dbrand.com/how-to-apply/huawei-mate-10-pro", - "https://dbrand.com/how-to-apply/huawei-mate-20", - "https://dbrand.com/how-to-apply/huawei-mate-20-pro", - "https://dbrand.com/how-to-apply/huawei-mate-30-pro", - "https://dbrand.com/how-to-apply/huawei-matebook-x-pro-2018", - "https://dbrand.com/how-to-apply/huawei-matebook-x-pro-2019", - "https://dbrand.com/how-to-apply/huawei-p10", - "https://dbrand.com/how-to-apply/huawei-p10-plus", - "https://dbrand.com/how-to-apply/huawei-p20", - "https://dbrand.com/how-to-apply/huawei-p20-pro", - "https://dbrand.com/how-to-apply/huawei-p30", - "https://dbrand.com/how-to-apply/huawei-p30-pro", - "https://dbrand.com/how-to-apply/huawei-p9", - "https://dbrand.com/how-to-apply/intel-nuc-mainstream-mini-pc", - "https://dbrand.com/how-to-apply/ipad-10.2-2019-gen-7", - "https://dbrand.com/how-to-apply/ipad-9.7-skins-2017-2018", - "https://dbrand.com/how-to-apply/ipad-air-2", - "https://dbrand.com/how-to-apply/ipad-air-3", - "https://dbrand.com/how-to-apply/ipad-mini-4", - "https://dbrand.com/how-to-apply/ipad-mini-5", - "https://dbrand.com/how-to-apply/ipad-pro-105", - "https://dbrand.com/how-to-apply/ipad-pro-11", - "https://dbrand.com/how-to-apply/ipad-pro-12.9-2018-gen-3", - "https://dbrand.com/how-to-apply/ipad-pro-129-2016-gen-1", - "https://dbrand.com/how-to-apply/ipad-pro-129-2017-gen-2", - "https://dbrand.com/how-to-apply/ipad-pro-97-2016", - "https://dbrand.com/how-to-apply/iphone-11", - "https://dbrand.com/how-to-apply/iphone-11-pro", - "https://dbrand.com/how-to-apply/iphone-11-pro-max", - "https://dbrand.com/how-to-apply/iphone-4-4s", - "https://dbrand.com/how-to-apply/iphone-5", - "https://dbrand.com/how-to-apply/iphone-5s", - "https://dbrand.com/how-to-apply/iphone-6", - "https://dbrand.com/how-to-apply/iphone-6-plus", - "https://dbrand.com/how-to-apply/iphone-6s", - "https://dbrand.com/how-to-apply/iphone-6s-plus", - "https://dbrand.com/how-to-apply/iphone-7", - "https://dbrand.com/how-to-apply/iphone-7-plus", - "https://dbrand.com/how-to-apply/iphone-8", - "https://dbrand.com/how-to-apply/iphone-8-plus", - "https://dbrand.com/how-to-apply/iphone-se", - "https://dbrand.com/how-to-apply/iphone-x", - "https://dbrand.com/how-to-apply/iphone-xr", - "https://dbrand.com/how-to-apply/iphone-xs", - "https://dbrand.com/how-to-apply/iphone-xs-max", - "https://dbrand.com/how-to-apply/juul", - "https://dbrand.com/how-to-apply/juul-c1", - "https://dbrand.com/how-to-apply/lenovo-thinkpad-x1-carbon-6th-gen", - "https://dbrand.com/how-to-apply/lenovo-thinkpad-x1-carbon-7th-gen", - "https://dbrand.com/how-to-apply/lg-g3", - "https://dbrand.com/how-to-apply/lg-g4", - "https://dbrand.com/how-to-apply/lg-g5", - "https://dbrand.com/how-to-apply/lg-g6", - "https://dbrand.com/how-to-apply/lg-g7", - "https://dbrand.com/how-to-apply/lg-v20", - "https://dbrand.com/how-to-apply/lg-v30", - "https://dbrand.com/how-to-apply/m40x", - "https://dbrand.com/how-to-apply/m50", - "https://dbrand.com/how-to-apply/m50x", - "https://dbrand.com/how-to-apply/macbook-12-2015-2018-retina", - "https://dbrand.com/how-to-apply/macbook-air-11", - "https://dbrand.com/how-to-apply/macbook-air-13", - "https://dbrand.com/how-to-apply/macbook-air-13-2018-2019", - "https://dbrand.com/how-to-apply/macbook-pro-13-2013-2015-retina", - "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2016-2018-four-thunderbolt", - "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2016-2018-two-thunderbolt", - "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2019-four-thunderbolt", - "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2019-two-thunderbolt", - "https://dbrand.com/how-to-apply/macbook-pro-15-2013-2015-retina", - "https://dbrand.com/how-to-apply/macbook-pro-15-touch-bar", - "https://dbrand.com/how-to-apply/macbook-pro-16-2019", - "https://dbrand.com/how-to-apply/mac-pro-and-pro-display-xdr", - "https://dbrand.com/how-to-apply/maingear-element", - "https://dbrand.com/how-to-apply/moto-g-2013", - "https://dbrand.com/how-to-apply/moto-g-2014", - "https://dbrand.com/how-to-apply/moto-x-2013", - "https://dbrand.com/how-to-apply/moto-x-2014", - "https://dbrand.com/how-to-apply/moto-x4", - "https://dbrand.com/how-to-apply/moto-x-play", - "https://dbrand.com/how-to-apply/moto-x-style-pure", - "https://dbrand.com/how-to-apply/moto-z", - "https://dbrand.com/how-to-apply/moto-z-force", - "https://dbrand.com/how-to-apply/nextbit-robin", - "https://dbrand.com/how-to-apply/nexus-4", - "https://dbrand.com/how-to-apply/nexus-5", - "https://dbrand.com/how-to-apply/nexus-5x", - "https://dbrand.com/how-to-apply/nexus-6", - "https://dbrand.com/how-to-apply/nexus-6p", - "https://dbrand.com/how-to-apply/nexus-7-2012", - "https://dbrand.com/how-to-apply/nexus-7-2013", - "https://dbrand.com/how-to-apply/nexus-9", - "https://dbrand.com/how-to-apply/nintendo-switch", - "https://dbrand.com/how-to-apply/nintendo-switch-lite", - "https://dbrand.com/how-to-apply/nintendo-switch-pro-controller", - "https://dbrand.com/how-to-apply/oneplus-2", - "https://dbrand.com/how-to-apply/oneplus-3", - "https://dbrand.com/how-to-apply/oneplus-3t", - "https://dbrand.com/how-to-apply/oneplus-5", - "https://dbrand.com/how-to-apply/oneplus-5t", - "https://dbrand.com/how-to-apply/oneplus-6", - "https://dbrand.com/how-to-apply/oneplus-6t", - "https://dbrand.com/how-to-apply/oneplus-7", - "https://dbrand.com/how-to-apply/oneplus-7-pro", - "https://dbrand.com/how-to-apply/oneplus-7t", - "https://dbrand.com/how-to-apply/oneplus-7t-pro", - "https://dbrand.com/how-to-apply/oneplus-one", - "https://dbrand.com/how-to-apply/oneplus-x", - "https://dbrand.com/how-to-apply/pebble-time", - "https://dbrand.com/how-to-apply/pebble-watch", - "https://dbrand.com/how-to-apply/pixel", - "https://dbrand.com/how-to-apply/pixel-2", - "https://dbrand.com/how-to-apply/pixel-2-xl", - "https://dbrand.com/how-to-apply/pixel-3", - "https://dbrand.com/how-to-apply/pixel-3a", - "https://dbrand.com/how-to-apply/pixel-3a-xl", - "https://dbrand.com/how-to-apply/pixel-3-xl", - "https://dbrand.com/how-to-apply/pixel-4", - "https://dbrand.com/how-to-apply/pixel-4-xl", - "https://dbrand.com/how-to-apply/pixelbook", - "https://dbrand.com/how-to-apply/pixelbook-go", - "https://dbrand.com/how-to-apply/pixel-xl", - "https://dbrand.com/how-to-apply/playstation-3", - "https://dbrand.com/how-to-apply/playstation-4", - "https://dbrand.com/how-to-apply/playstation-4-pro", - "https://dbrand.com/how-to-apply/playstation-4-slim", - "https://dbrand.com/how-to-apply/playstation-vita", - "https://dbrand.com/how-to-apply/pocophone-f1", - "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2018-advanced-no-ethernet-gtx", - "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2018-base-with-ethernet-gtx", - "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2019-advanced-no-ethernet-rtx", - "https://dbrand.com/how-to-apply/razer-blade-pro-17-2019", - "https://dbrand.com/how-to-apply/razer-phone", - "https://dbrand.com/how-to-apply/razer-phone-2", - "https://dbrand.com/how-to-apply/redmi-k20", - "https://dbrand.com/how-to-apply/redmi-k20-pro", - "https://dbrand.com/how-to-apply/surface-book", - "https://dbrand.com/how-to-apply/surface-book-2-13", - "https://dbrand.com/how-to-apply/surface-book-2-15", - "https://dbrand.com/how-to-apply/surface-go", - "https://dbrand.com/how-to-apply/surface-laptop", - "https://dbrand.com/how-to-apply/surface-laptop-2", - "https://dbrand.com/how-to-apply/surface-laptop-3-13", - "https://dbrand.com/how-to-apply/surface-laptop-3-15", - "https://dbrand.com/how-to-apply/surface-pro-2017", - "https://dbrand.com/how-to-apply/surface-pro-4", - "https://dbrand.com/how-to-apply/surface-pro-6", - "https://dbrand.com/how-to-apply/surface-pro-7", - "https://dbrand.com/how-to-apply/surface-pro-x", - "https://dbrand.com/how-to-apply/tesla-cybertruck", - "https://dbrand.com/how-to-apply/xbox-360", - "https://dbrand.com/how-to-apply/xbox-one", - "https://dbrand.com/how-to-apply/xbox-one-s", - "https://dbrand.com/how-to-apply/xbox-one-x", - "https://dbrand.com/how-to-apply/xiaomi-mi-9t", - "https://dbrand.com/how-to-apply/xiaomi-mi-9t-pro", - "https://dbrand.com/how-to-apply/xperia-z1", - "https://dbrand.com/how-to-apply/xperia-z2", - "https://dbrand.com/how-to-apply/xperia-z3", - "https://dbrand.com/how-to-apply/xperia-z3-compact", - "https://dbrand.com/how-to-apply/xperia-z5", - "https://dbrand.com/how-to-apply/xperia-z5-compact", - "https://dbrand.com/how-to-apply/xperia-z5-premium", - "https://dbrand.com/how-to-apply/xperia-z-ultra", - "https://dbrand.com/how-to-apply/xps-13-9370", - "https://dbrand.com/how-to-apply/xps-13-9380", - "https://dbrand.com/how-to-apply/xps-15-2-in-1-9575", - "https://dbrand.com/how-to-apply/xps-15-7590", - "https://dbrand.com/how-to-apply/xps-15-9570", - "https://dbrand.com/how-to-apply/zenfone-2", - ], -} - class DbrandCog(commands.Cog): """ dbrand functions for J.A.R.V.I.S. - Mostly support functions + Mostly support functions. Credit @cpixl for the shipping API """ def __init__(self, bot): self.bot = bot self.base_url = "https://dbrand.com/" + self._session = aiohttp.ClientSession() + self._session.headers.update({"Content-Type": "application/json"}) + self.api_url = get_config().urls["dbrand_shipping"] @commands.group(name="db", aliases=["dbrand"], pass_context=True) async def _db(self, ctx): @@ -540,26 +47,69 @@ class DbrandCog(commands.Cog): 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.") - search = "-".join(search.split(" ")) - matches = [ - x for x in DBRAND_DATA["shippingArray"] if search.lower() in x - ] - if len(matches) > 0: - link = self.base_url + "/shipping/" + matches[0] - dest = matches[0] + dest = search + api_link = self.api_url + dest + try: + data = await self._session.get(api_link) + except Exception as e: + print(e) + fields = None + if 200 <= data.status < 400: + data = await data.json() + else: + data = None + if data is not None and data["is_valid"]: + fields = [] + if data["shipping_available"]: + fields.append(Field(data["short-name"], data["time-title"])) + for service in data["shipping_services_available"][1:]: + service_data = await self._session.get( + self.api_url + dest + "/" + service["url"] + ) + if service_data.status > 400: + continue + service_data = await service_data.json() + fields.append( + Field( + service_data["short-name"], + service_data["time-title"], + ) + ) + country = "-".join( + x for x in data["country"].split(" ") if x != "the" + ) + country_urlsafe = country.replace("-", "%20") + description = f"Click the link above to see shipping time to {data['country']}." + description += "\n[View all shipping destinations](https://dbrand.com/shipping)" + description += " | [Check shipping status]" + description += f"(https://dbrand.com/status#main-content:~:text={country_urlsafe})" embed = build_embed( - title="Shipping to {}".format(dest), - desc="[View all shipping destinations]" - + "(https://dbrand.com/shipping)", + title="Shipping to {}".format(data["country"]), + description=description, color="#FFBB00", + fields=fields, + url=self.base_url + "shipping/" + country, + ) + embed.set_thumbnail(url=self.base_url + data["country_flag"][1:]) + embed.set_footer( + text="dbrand.com", + icon_url="https://dev.zevaryx.com/db_logo.png", + ) + await ctx.send(embed=embed) + else: + embed = build_embed( + title="Check Shipping Times", + description="Country not found.\nYou can [view all shipping " + + "destinations here](https://dbrand.com/shipping)", fields=[], - url=link, + url="https://dbrand.com/shipping", + color="#FFBB00", ) - embed.set_image( - "https://upload.wikimedia.org/wikipedia/commons/thumb" - + "/b/b4/Dbrand_logo.svg/2560px-Dbrand_logo.svg.png" + embed.set_thumbnail(url="https://dev.zevaryx.com/db_logo.png") + embed.set_footer( + text="dbrand.com", + icon_url="https://dev.zevaryx.com/db_logo.png", ) - embed.set_thumbnail("https://dev.zevaryx.com/db_logo.png") await ctx.send(embed=embed) diff --git a/jarvis/config.py b/jarvis/config.py index 690b935..52dabb9 100644 --- a/jarvis/config.py +++ b/jarvis/config.py @@ -14,6 +14,7 @@ class Config: admins: list logo: str mongo: dict + urls: dict @classmethod def from_yaml(cls, y): diff --git a/jarvis/data/dbrand.py b/jarvis/data/dbrand.py new file mode 100644 index 0000000..77b877b --- /dev/null +++ b/jarvis/data/dbrand.py @@ -0,0 +1,497 @@ +shipping_array = [ + "afghanistan", + "aland-islands", + "albania", + "algeria", + "american-samoa", + "andorra", + "angola", + "anguilla", + "antarctica", + "antigua-and-barbuda", + "argentina", + "armenia", + "aruba", + "australia", + "austria", + "azerbaijan", + "bahamas", + "bahrain", + "bangladesh", + "barbados", + "belarus", + "belgium", + "belize", + "benin", + "bermuda", + "bhutan", + "bolivia", + "bosnia-and-herzegovina", + "botswana", + "bouvet-island", + "brazil", + "british-indian-ocean-territory", + "british-virgin-islands", + "brunei", + "bulgaria", + "burkina-faso", + "burundi", + "cambodia", + "cameroon", + "canada", + "cape-verde", + "caribbean-netherlands", + "cayman-islands", + "central-african-republic", + "chad", + "chile", + "china", + "christmas-island", + "cocos-keeling-islands", + "colombia", + "comoros", + "congo-brazzaville", + "congo-kinshasa", + "cook-islands", + "costa-rica", + "croatia", + "cuba", + "cura%C3%A7ao", + "cyprus", + "czech-republic", + "denmark", + "djibouti", + "dominica", + "dominican-republic", + "ecuador", + "egypt", + "el-salvador", + "equatorial-guinea", + "eritrea", + "estonia", + "ethiopia", + "falkland-islands", + "faroe-islands", + "fiji", + "finland", + "france", + "french-guiana", + "french-polynesia", + "french-southern-territories", + "gabon", + "gambia", + "georgia", + "germany", + "ghana", + "gibraltar", + "greece", + "greenland", + "grenada", + "guadeloupe", + "guam", + "guatemala", + "guernsey", + "guinea", + "guinea-bissau", + "guyana", + "haiti", + "heard-island-and-mcdonald-islands", + "honduras", + "hong-kong-sar-china", + "hungary", + "iceland", + "india", + "indonesia", + "iran", + "iraq", + "ireland", + "isle-of-man", + "israel", + "italy", + "ivory-coast", + "jamaica", + "japan", + "jersey", + "jordan", + "kazakhstan", + "kenya", + "kiribati", + "kuwait", + "kyrgyzstan", + "laos", + "latvia", + "lebanon", + "lesotho", + "liberia", + "libya", + "liechtenstein", + "lithuania", + "luxembourg", + "macao-sar-china", + "macedonia", + "madagascar", + "malawi", + "malaysia", + "maldives", + "mali", + "malta", + "marshall-islands", + "martinique", + "mauritania", + "mauritius", + "mayotte", + "mexico", + "micronesia", + "moldova", + "monaco", + "mongolia", + "montenegro", + "montserrat", + "morocco", + "mozambique", + "myanmar", + "namibia", + "nauru", + "nepal", + "netherlands", + "netherlands-antilles", + "new-caledonia", + "new-zealand", + "nicaragua", + "niger", + "nigeria", + "niue", + "norfolk-island", + "northern-mariana-islands", + "north-korea", + "norway", + "oman", + "pakistan", + "palau", + "palestinian-territory", + "panama", + "papua-new-guinea", + "paraguay", + "peru", + "philippines", + "pitcairn", + "poland", + "portugal", + "puerto-rico", + "qatar", + "reunion", + "romania", + "russia", + "rwanda", + "saint-barth%C3%A9lemy", + "saint-helena", + "saint-kitts-and-nevis", + "saint-lucia", + "saint-martin-french-part", + "saint-pierre-and-miquelon", + "saint-vincent-and-the-grenadines", + "samoa", + "san-marino", + "sao-tome-and-principe", + "saudi-arabia", + "senegal", + "serbia", + "seychelles", + "sierra-leone", + "singapore", + "sint-maarten", + "slovakia", + "slovenia", + "solomon-islands", + "somalia", + "south-africa", + "south-georgia-and-the-south-sandwich-islands", + "south-korea", + "south-sudan", + "spain", + "sri-lanka", + "sudan", + "suriname", + "svalbard-and-jan-mayen", + "swaziland", + "sweden", + "switzerland", + "syria", + "taiwan", + "tajikistan", + "tanzania", + "thailand", + "timor-leste", + "togo", + "tokelau", + "tonga", + "trinidad-and-tobago", + "tunisia", + "turkey", + "turkmenistan", + "turks-and-caicos-islands", + "tuvalu", + "uganda", + "ukraine", + "united-arab-emirates", + "united-kingdom", + "united-states", + "united-states-minor-outlying-islands", + "uruguay", + "us-virgin-islands", + "uzbekistan", + "vanuatu", + "vatican", + "venezuela", + "vietnam", + "wallis-and-futuna", + "western-sahara", + "yemen", + "zambia", + "zimbabwe", +] +how_to_array = [ + "https://dbrand.com/how-to-apply/airpower", + "https://dbrand.com/how-to-apply/alienware-13-r3", + "https://dbrand.com/how-to-apply/alienware-15-r3", + "https://dbrand.com/how-to-apply/alienware-17-r4-eye-tracking", + "https://dbrand.com/how-to-apply/alienware-17-r4-no-eye-tracking", + "https://dbrand.com/how-to-apply/alienware-17-r5-eye-tracking", + "https://dbrand.com/how-to-apply/alienware-17-r5-no-eye-tracking", + "https://dbrand.com/how-to-apply/anker-powercore-13000-usb-c", + "https://dbrand.com/how-to-apply/anker-powercore-plus-20100-usb-c", + "https://dbrand.com/how-to-apply/anker-powercore-plus-26800-pd", + "https://dbrand.com/how-to-apply/anker-powercore-slim-10000-pd", + "https://dbrand.com/how-to-apply/apple-18w-usb-c-power-adapter", + "https://dbrand.com/how-to-apply/apple-5w-usb-power-adapter", + "https://dbrand.com/how-to-apply/apple-airpods-gen-1", + "https://dbrand.com/how-to-apply/apple-airpods-gen-2-no-wireless-charging", + "https://dbrand.com/how-to-apply/apple-airpods-gen-2-wireless-charging", + "https://dbrand.com/how-to-apply/apple-airpods-pro", + "https://dbrand.com/how-to-apply/apple-card", + "https://dbrand.com/how-to-apply/apple-pencil", + "https://dbrand.com/how-to-apply/apple-pencil-2", + "https://dbrand.com/how-to-apply/axon-7", + "https://dbrand.com/how-to-apply/blade-14-2014-2016-gtx-970m", + "https://dbrand.com/how-to-apply/blade-14-2016-2017-gtx-1060", + "https://dbrand.com/how-to-apply/blade-stealth-125-early-2016-skylake", + "https://dbrand.com/how-to-apply/blade-stealth-125-late-2016-2017-kaby-lake", + "https://dbrand.com/how-to-apply/blade-stealth-13.3-2017-2018", + "https://dbrand.com/how-to-apply/blade-stealth-13.3-early-2019", + "https://dbrand.com/how-to-apply/blade-stealth-13.3-late-2019", + "https://dbrand.com/how-to-apply/dell-xps-13-2-in-1-7390", + "https://dbrand.com/how-to-apply/dell-xps-13-2-in-1-9365", + "https://dbrand.com/how-to-apply/dell-xps-13-7390", + "https://dbrand.com/how-to-apply/dell-xps-13-9350-9360", + "https://dbrand.com/how-to-apply/dell-xps-15-9550", + "https://dbrand.com/how-to-apply/dell-xps-15-9560", + "https://dbrand.com/how-to-apply/eluktronics-mag-15", + "https://dbrand.com/how-to-apply/essential-phone", + "https://dbrand.com/how-to-apply/eve-v", + "https://dbrand.com/how-to-apply/galaxy-a50", + "https://dbrand.com/how-to-apply/galaxy-a70", + "https://dbrand.com/how-to-apply/galaxy-buds", + "https://dbrand.com/how-to-apply/galaxy-fold", + "https://dbrand.com/how-to-apply/galaxy-note-10", + "https://dbrand.com/how-to-apply/galaxy-note-10-plus", + "https://dbrand.com/how-to-apply/galaxy-note-10-plus-5g", + "https://dbrand.com/how-to-apply/galaxy-note-4", + "https://dbrand.com/how-to-apply/galaxy-note-5", + "https://dbrand.com/how-to-apply/galaxy-note-7", + "https://dbrand.com/how-to-apply/galaxy-note-8", + "https://dbrand.com/how-to-apply/galaxy-note-9", + "https://dbrand.com/how-to-apply/galaxy-note-fe", + "https://dbrand.com/how-to-apply/galaxy-s10", + "https://dbrand.com/how-to-apply/galaxy-s10-5g", + "https://dbrand.com/how-to-apply/galaxy-s10e", + "https://dbrand.com/how-to-apply/galaxy-s10-plus", + "https://dbrand.com/how-to-apply/galaxy-s6", + "https://dbrand.com/how-to-apply/galaxy-s6-active", + "https://dbrand.com/how-to-apply/galaxy-s6-edge", + "https://dbrand.com/how-to-apply/galaxy-s6-edge-plus", + "https://dbrand.com/how-to-apply/galaxy-s7", + "https://dbrand.com/how-to-apply/galaxy-s7-active", + "https://dbrand.com/how-to-apply/galaxy-s7-edge", + "https://dbrand.com/how-to-apply/galaxy-s8", + "https://dbrand.com/how-to-apply/galaxy-s8-active", + "https://dbrand.com/how-to-apply/galaxy-s8-plus", + "https://dbrand.com/how-to-apply/galaxy-s9", + "https://dbrand.com/how-to-apply/galaxy-s9-plus", + "https://dbrand.com/how-to-apply/google-home", + "https://dbrand.com/how-to-apply/honor-8", + "https://dbrand.com/how-to-apply/htc-10", + "https://dbrand.com/how-to-apply/htc-one-m7", + "https://dbrand.com/how-to-apply/htc-one-m8", + "https://dbrand.com/how-to-apply/htc-one-m9", + "https://dbrand.com/how-to-apply/htc-u-ultra", + "https://dbrand.com/how-to-apply/huawei-mate-10", + "https://dbrand.com/how-to-apply/huawei-mate-10-pro", + "https://dbrand.com/how-to-apply/huawei-mate-20", + "https://dbrand.com/how-to-apply/huawei-mate-20-pro", + "https://dbrand.com/how-to-apply/huawei-mate-30-pro", + "https://dbrand.com/how-to-apply/huawei-matebook-x-pro-2018", + "https://dbrand.com/how-to-apply/huawei-matebook-x-pro-2019", + "https://dbrand.com/how-to-apply/huawei-p10", + "https://dbrand.com/how-to-apply/huawei-p10-plus", + "https://dbrand.com/how-to-apply/huawei-p20", + "https://dbrand.com/how-to-apply/huawei-p20-pro", + "https://dbrand.com/how-to-apply/huawei-p30", + "https://dbrand.com/how-to-apply/huawei-p30-pro", + "https://dbrand.com/how-to-apply/huawei-p9", + "https://dbrand.com/how-to-apply/intel-nuc-mainstream-mini-pc", + "https://dbrand.com/how-to-apply/ipad-10.2-2019-gen-7", + "https://dbrand.com/how-to-apply/ipad-9.7-skins-2017-2018", + "https://dbrand.com/how-to-apply/ipad-air-2", + "https://dbrand.com/how-to-apply/ipad-air-3", + "https://dbrand.com/how-to-apply/ipad-mini-4", + "https://dbrand.com/how-to-apply/ipad-mini-5", + "https://dbrand.com/how-to-apply/ipad-pro-105", + "https://dbrand.com/how-to-apply/ipad-pro-11", + "https://dbrand.com/how-to-apply/ipad-pro-12.9-2018-gen-3", + "https://dbrand.com/how-to-apply/ipad-pro-129-2016-gen-1", + "https://dbrand.com/how-to-apply/ipad-pro-129-2017-gen-2", + "https://dbrand.com/how-to-apply/ipad-pro-97-2016", + "https://dbrand.com/how-to-apply/iphone-11", + "https://dbrand.com/how-to-apply/iphone-11-pro", + "https://dbrand.com/how-to-apply/iphone-11-pro-max", + "https://dbrand.com/how-to-apply/iphone-4-4s", + "https://dbrand.com/how-to-apply/iphone-5", + "https://dbrand.com/how-to-apply/iphone-5s", + "https://dbrand.com/how-to-apply/iphone-6", + "https://dbrand.com/how-to-apply/iphone-6-plus", + "https://dbrand.com/how-to-apply/iphone-6s", + "https://dbrand.com/how-to-apply/iphone-6s-plus", + "https://dbrand.com/how-to-apply/iphone-7", + "https://dbrand.com/how-to-apply/iphone-7-plus", + "https://dbrand.com/how-to-apply/iphone-8", + "https://dbrand.com/how-to-apply/iphone-8-plus", + "https://dbrand.com/how-to-apply/iphone-se", + "https://dbrand.com/how-to-apply/iphone-x", + "https://dbrand.com/how-to-apply/iphone-xr", + "https://dbrand.com/how-to-apply/iphone-xs", + "https://dbrand.com/how-to-apply/iphone-xs-max", + "https://dbrand.com/how-to-apply/juul", + "https://dbrand.com/how-to-apply/juul-c1", + "https://dbrand.com/how-to-apply/lenovo-thinkpad-x1-carbon-6th-gen", + "https://dbrand.com/how-to-apply/lenovo-thinkpad-x1-carbon-7th-gen", + "https://dbrand.com/how-to-apply/lg-g3", + "https://dbrand.com/how-to-apply/lg-g4", + "https://dbrand.com/how-to-apply/lg-g5", + "https://dbrand.com/how-to-apply/lg-g6", + "https://dbrand.com/how-to-apply/lg-g7", + "https://dbrand.com/how-to-apply/lg-v20", + "https://dbrand.com/how-to-apply/lg-v30", + "https://dbrand.com/how-to-apply/m40x", + "https://dbrand.com/how-to-apply/m50", + "https://dbrand.com/how-to-apply/m50x", + "https://dbrand.com/how-to-apply/macbook-12-2015-2018-retina", + "https://dbrand.com/how-to-apply/macbook-air-11", + "https://dbrand.com/how-to-apply/macbook-air-13", + "https://dbrand.com/how-to-apply/macbook-air-13-2018-2019", + "https://dbrand.com/how-to-apply/macbook-pro-13-2013-2015-retina", + "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2016-2018-four-thunderbolt", + "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2016-2018-two-thunderbolt", + "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2019-four-thunderbolt", + "https://dbrand.com/how-to-apply/macbook-pro-13-skins-2019-two-thunderbolt", + "https://dbrand.com/how-to-apply/macbook-pro-15-2013-2015-retina", + "https://dbrand.com/how-to-apply/macbook-pro-15-touch-bar", + "https://dbrand.com/how-to-apply/macbook-pro-16-2019", + "https://dbrand.com/how-to-apply/mac-pro-and-pro-display-xdr", + "https://dbrand.com/how-to-apply/maingear-element", + "https://dbrand.com/how-to-apply/moto-g-2013", + "https://dbrand.com/how-to-apply/moto-g-2014", + "https://dbrand.com/how-to-apply/moto-x-2013", + "https://dbrand.com/how-to-apply/moto-x-2014", + "https://dbrand.com/how-to-apply/moto-x4", + "https://dbrand.com/how-to-apply/moto-x-play", + "https://dbrand.com/how-to-apply/moto-x-style-pure", + "https://dbrand.com/how-to-apply/moto-z", + "https://dbrand.com/how-to-apply/moto-z-force", + "https://dbrand.com/how-to-apply/nextbit-robin", + "https://dbrand.com/how-to-apply/nexus-4", + "https://dbrand.com/how-to-apply/nexus-5", + "https://dbrand.com/how-to-apply/nexus-5x", + "https://dbrand.com/how-to-apply/nexus-6", + "https://dbrand.com/how-to-apply/nexus-6p", + "https://dbrand.com/how-to-apply/nexus-7-2012", + "https://dbrand.com/how-to-apply/nexus-7-2013", + "https://dbrand.com/how-to-apply/nexus-9", + "https://dbrand.com/how-to-apply/nintendo-switch", + "https://dbrand.com/how-to-apply/nintendo-switch-lite", + "https://dbrand.com/how-to-apply/nintendo-switch-pro-controller", + "https://dbrand.com/how-to-apply/oneplus-2", + "https://dbrand.com/how-to-apply/oneplus-3", + "https://dbrand.com/how-to-apply/oneplus-3t", + "https://dbrand.com/how-to-apply/oneplus-5", + "https://dbrand.com/how-to-apply/oneplus-5t", + "https://dbrand.com/how-to-apply/oneplus-6", + "https://dbrand.com/how-to-apply/oneplus-6t", + "https://dbrand.com/how-to-apply/oneplus-7", + "https://dbrand.com/how-to-apply/oneplus-7-pro", + "https://dbrand.com/how-to-apply/oneplus-7t", + "https://dbrand.com/how-to-apply/oneplus-7t-pro", + "https://dbrand.com/how-to-apply/oneplus-one", + "https://dbrand.com/how-to-apply/oneplus-x", + "https://dbrand.com/how-to-apply/pebble-time", + "https://dbrand.com/how-to-apply/pebble-watch", + "https://dbrand.com/how-to-apply/pixel", + "https://dbrand.com/how-to-apply/pixel-2", + "https://dbrand.com/how-to-apply/pixel-2-xl", + "https://dbrand.com/how-to-apply/pixel-3", + "https://dbrand.com/how-to-apply/pixel-3a", + "https://dbrand.com/how-to-apply/pixel-3a-xl", + "https://dbrand.com/how-to-apply/pixel-3-xl", + "https://dbrand.com/how-to-apply/pixel-4", + "https://dbrand.com/how-to-apply/pixel-4-xl", + "https://dbrand.com/how-to-apply/pixelbook", + "https://dbrand.com/how-to-apply/pixelbook-go", + "https://dbrand.com/how-to-apply/pixel-xl", + "https://dbrand.com/how-to-apply/playstation-3", + "https://dbrand.com/how-to-apply/playstation-4", + "https://dbrand.com/how-to-apply/playstation-4-pro", + "https://dbrand.com/how-to-apply/playstation-4-slim", + "https://dbrand.com/how-to-apply/playstation-vita", + "https://dbrand.com/how-to-apply/pocophone-f1", + "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2018-advanced-no-ethernet-gtx", + "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2018-base-with-ethernet-gtx", + "https://dbrand.com/how-to-apply/razer-blade-15.6-skins-2019-advanced-no-ethernet-rtx", + "https://dbrand.com/how-to-apply/razer-blade-pro-17-2019", + "https://dbrand.com/how-to-apply/razer-phone", + "https://dbrand.com/how-to-apply/razer-phone-2", + "https://dbrand.com/how-to-apply/redmi-k20", + "https://dbrand.com/how-to-apply/redmi-k20-pro", + "https://dbrand.com/how-to-apply/surface-book", + "https://dbrand.com/how-to-apply/surface-book-2-13", + "https://dbrand.com/how-to-apply/surface-book-2-15", + "https://dbrand.com/how-to-apply/surface-go", + "https://dbrand.com/how-to-apply/surface-laptop", + "https://dbrand.com/how-to-apply/surface-laptop-2", + "https://dbrand.com/how-to-apply/surface-laptop-3-13", + "https://dbrand.com/how-to-apply/surface-laptop-3-15", + "https://dbrand.com/how-to-apply/surface-pro-2017", + "https://dbrand.com/how-to-apply/surface-pro-4", + "https://dbrand.com/how-to-apply/surface-pro-6", + "https://dbrand.com/how-to-apply/surface-pro-7", + "https://dbrand.com/how-to-apply/surface-pro-x", + "https://dbrand.com/how-to-apply/tesla-cybertruck", + "https://dbrand.com/how-to-apply/xbox-360", + "https://dbrand.com/how-to-apply/xbox-one", + "https://dbrand.com/how-to-apply/xbox-one-s", + "https://dbrand.com/how-to-apply/xbox-one-x", + "https://dbrand.com/how-to-apply/xiaomi-mi-9t", + "https://dbrand.com/how-to-apply/xiaomi-mi-9t-pro", + "https://dbrand.com/how-to-apply/xperia-z1", + "https://dbrand.com/how-to-apply/xperia-z2", + "https://dbrand.com/how-to-apply/xperia-z3", + "https://dbrand.com/how-to-apply/xperia-z3-compact", + "https://dbrand.com/how-to-apply/xperia-z5", + "https://dbrand.com/how-to-apply/xperia-z5-compact", + "https://dbrand.com/how-to-apply/xperia-z5-premium", + "https://dbrand.com/how-to-apply/xperia-z-ultra", + "https://dbrand.com/how-to-apply/xps-13-9370", + "https://dbrand.com/how-to-apply/xps-13-9380", + "https://dbrand.com/how-to-apply/xps-15-2-in-1-9575", + "https://dbrand.com/how-to-apply/xps-15-7590", + "https://dbrand.com/how-to-apply/xps-15-9570", + "https://dbrand.com/how-to-apply/zenfone-2", +] diff --git a/jarvis/utils/__init__.py b/jarvis/utils/__init__.py index 83d9f74..881b8ab 100644 --- a/jarvis/utils/__init__.py +++ b/jarvis/utils/__init__.py @@ -1,6 +1,7 @@ from discord.ext import commands from discord import Embed, Color from pkgutil import iter_modules +from datetime import datetime import jarvis.cogs import jarvis.utils.db import git @@ -47,13 +48,20 @@ def parse_color_hex(hex: str) -> Color: def build_embed( title: str, - desc: str, + description: str, fields: list, color: str = "#FF0000", + timestamp: datetime = None, **kwargs, ) -> Embed: + if not timestamp: + timestamp = datetime.now() embed = Embed( - title=title, desc=desc, color=parse_color_hex(color), **kwargs + title=title, + description=description, + color=parse_color_hex(color), + timestamp=timestamp, + **kwargs, ) for field in fields: embed.add_field(**field.to_dict())