diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index 884de2b..cb7e722 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -2,26 +2,31 @@ import re import aiohttp -from discord.ext import commands -from discord_slash import SlashContext, cog_ext -from discord_slash.utils.manage_commands import create_option +from dis_snek import InteractionContext, Scale, Snek +from dis_snek.models.discord.embed import EmbedField +from dis_snek.models.snek.application_commands import ( + OptionTypes, + slash_command, + slash_option, +) +from dis_snek.models.snek.command import cooldown +from dis_snek.models.snek.cooldowns import Buckets from jarvis.config import get_config from jarvis.data.dbrand import shipping_lookup from jarvis.utils import build_embed -from jarvis.utils.field import Field guild_ids = [578757004059738142, 520021794380447745, 862402786116763668] -class DbrandCog(commands.Cog): +class DbrandCog(Scale): """ dbrand functions for J.A.R.V.I.S. Mostly support functions. Credit @cpixl for the shipping API """ - def __init__(self, bot: commands.Bot): + def __init__(self, bot: Snek): self.bot = bot self.base_url = "https://dbrand.com/" self._session = aiohttp.ClientSession() @@ -32,134 +37,130 @@ class DbrandCog(commands.Cog): def __del__(self): self._session.close() - @cog_ext.cog_subcommand( - base="db", - name="skin", - guild_ids=guild_ids, - description="See what skins are available", + @slash_command( + name="db", + sub_cmd_name="skin", + scopes=guild_ids, + sub_cmd_description="See what skins are available", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _skin(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _skin(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "/skins") - @cog_ext.cog_subcommand( - base="db", - name="robotcamo", - guild_ids=guild_ids, - description="Get some robot camo. Make Tony Stark proud", + @slash_command( + name="db", + sub_cmd_name="robotcamo", + scopes=guild_ids, + sub_cmd_description="Get some robot camo. Make Tony Stark proud", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _camo(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _camo(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "robot-camo") - @cog_ext.cog_subcommand( - base="db", - name="grip", - guild_ids=guild_ids, - description="See devices with Grip support", + @slash_command( + name="db", + sub_cmd_name="grip", + scopes=guild_ids, + sub_cmd_description="See devices with Grip support", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _grip(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _grip(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "grip") - @cog_ext.cog_subcommand( - base="db", - name="contact", - guild_ids=guild_ids, - description="Contact support", + @slash_command( + name="db", + sub_cmd_name="contact", + scopes=guild_ids, + sub_cmd_description="Contact support", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _contact(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _contact(self, ctx: InteractionContext) -> None: await ctx.send("Contact dbrand support here: " + self.base_url + "contact") - @cog_ext.cog_subcommand( - base="db", - name="support", - guild_ids=guild_ids, - description="Contact support", + @slash_command( + name="db", + sub_cmd_name="support", + scopes=guild_ids, + sub_cmd_description="Contact support", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _support(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _support(self, ctx: InteractionContext) -> None: await ctx.send("Contact dbrand support here: " + self.base_url + "contact") - @cog_ext.cog_subcommand( - base="db", - name="orderstat", - guild_ids=guild_ids, - description="Get your order status", + @slash_command( + name="db", + sub_cmd_name="orderstat", + scopes=guild_ids, + sub_cmd_description="Get your order status", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _orderstat(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _orderstat(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "order-status") - @cog_ext.cog_subcommand( - base="db", - name="orders", - guild_ids=guild_ids, - description="Get your order status", + @slash_command( + name="db", + sub_cmd_name="orders", + scopes=guild_ids, + sub_cmd_description="Get your order status", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _orders(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _orders(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "order-status") - @cog_ext.cog_subcommand( - base="db", - name="status", - guild_ids=guild_ids, - description="dbrand status", + @slash_command( + name="db", + sub_cmd_name="status", + scopes=guild_ids, + sub_cmd_description="dbrand status", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _status(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _status(self, ctx: InteractionContext) -> None: await ctx.send(self.base_url + "status") - @cog_ext.cog_subcommand( - base="db", - name="buy", - guild_ids=guild_ids, - description="Give us your money!", + @slash_command( + name="db", + sub_cmd_name="buy", + scopes=guild_ids, + sub_cmd_description="Give us your money!", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _buy(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _buy(self, ctx: InteractionContext) -> None: await ctx.send("Give us your money! " + self.base_url + "shop") - @cog_ext.cog_subcommand( - base="db", - name="extortion", - guild_ids=guild_ids, - description="(not) extortion", + @slash_command( + name="db", + sub_cmd_name="extortion", + scopes=guild_ids, + sub_cmd_description="(not) extortion", ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _extort(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _extort(self, ctx: InteractionContext) -> None: await ctx.send("Be (not) extorted here: " + self.base_url + "not-extortion") - @cog_ext.cog_subcommand( - base="db", - name="wallpapers", - description="Robot Camo Wallpapers", - guild_ids=guild_ids, + @slash_command( + name="db", + sub_cmd_name="wallpapers", + sub_cmd_description="Robot Camo Wallpapers", + scopes=guild_ids, ) - @commands.cooldown(1, 30, commands.BucketType.channel) - async def _wallpapers(self, ctx: SlashContext) -> None: + @cooldown(bucket=Buckets.USER, rate=1, interval=30) + async def _wallpapers(self, ctx: InteractionContext) -> None: await ctx.send("Get robot camo wallpapers here: https://db.io/wallpapers") - @cog_ext.cog_subcommand( - base="db", - name="ship", - description="Get shipping information for your country", - guild_ids=guild_ids, - options=[ - ( - create_option( - name="search", - description="Country search query (2 character code, country name, emoji)", - option_type=3, - required=True, - ) - ) - ], + @slash_command( + name="db", + sub_cmd_name="ship", + sub_cmd_description="Get shipping information for your country", + scopes=guild_ids, ) - @commands.cooldown(1, 2, commands.BucketType.user) - async def _shipping(self, ctx: SlashContext, search: str) -> None: + @slash_option( + name="search", + description="Country search query (2 character code, country name, flag emoji)", + option_type=OptionTypes.STRING, + required=True, + ) + @cooldown(bucket=Buckets.USER, rate=1, interval=2) + async def _shipping(self, ctx: InteractionContext, search: str) -> None: await ctx.defer() if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE): if re.match( @@ -193,14 +194,14 @@ class DbrandCog(commands.Cog): fields = None if data is not None and data["is_valid"] and data["shipping_available"]: fields = [] - fields.append(Field(data["short-name"], data["time-title"])) + fields.append(EmbedField(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( + EmbedField( service_data["short-name"], service_data["time-title"], ) @@ -215,7 +216,7 @@ class DbrandCog(commands.Cog): ) embed = build_embed( title="Shipping to {}".format(data["country"]), - description=description, + sub_cmd_description=description, color="#FFBB00", fields=fields, url=self.base_url + "shipping/" + country, @@ -229,7 +230,7 @@ class DbrandCog(commands.Cog): elif not data["is_valid"]: embed = build_embed( title="Check Shipping Times", - description=( + sub_cmd_description=( "Country not found.\nYou can [view all shipping " "destinations here](https://dbrand.com/shipping)" ), @@ -246,7 +247,7 @@ class DbrandCog(commands.Cog): elif not data["shipping_available"]: embed = build_embed( title="Shipping to {}".format(data["country"]), - description=( + sub_cmd_description=( "No shipping available.\nTime to move to a country" " that has shipping available.\nYou can [find a new country " "to live in here](https://dbrand.com/shipping)" @@ -263,6 +264,6 @@ class DbrandCog(commands.Cog): await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: +def setup(bot: Snek) -> None: """Add dbrandcog to J.A.R.V.I.S.""" bot.add_cog(DbrandCog(bot))