From 00da6356bae9b53e045af6f0d2c5e2f4331f2e65 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 22 Jul 2021 08:44:31 -0600 Subject: [PATCH 1/4] Add avatar command, closes #64 --- jarvis/cogs/util.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/jarvis/cogs/util.py b/jarvis/cogs/util.py index a081b40..9282ec1 100644 --- a/jarvis/cogs/util.py +++ b/jarvis/cogs/util.py @@ -1,5 +1,6 @@ import re +from discord import User from discord.ext import commands from discord_slash import SlashContext, cog_ext from discord_slash.utils.manage_commands import create_option @@ -88,6 +89,33 @@ class UtilCog(commands.Cog): else: await ctx.send(to_send) + @cog_ext.cog_slash( + name="avatar", + description="Get a user avatar", + guild_ids=[862402786116763668], + options=[ + create_option( + name="user", + description="User to view avatar of", + option_type=6, + required=False, + ) + ], + ) + async def _avatar(self, ctx, user: User = None): + if not user: + user = ctx.author + + avatar = user.avatar_url + embed = build_embed( + title="Avatar", description="", fields=[], color="#00FFEE" + ) + embed.set_image(url=avatar) + embed.set_author( + name=f"{user.name}#{user.discriminator}", icon_url=avatar + ) + await ctx.send(embed=embed) + def setup(bot): bot.add_cog(UtilCog(bot)) From 5cd524f30e22194ddadb4763701b78b4b37b2d6d Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 22 Jul 2021 08:48:20 -0600 Subject: [PATCH 2/4] Add /db wallpapers, closes #63 --- jarvis/cogs/dbrand.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index 1aa63e8..86d6216 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -124,6 +124,17 @@ class DbrandCog(commands.Cog): "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, + ) + async def _wallpapers(self, ctx): + await ctx.send( + "Get robot camo wallpapers here: https://db.io/wallpapers" + ) + @cog_ext.cog_subcommand( base="db", name="ship", From 55fe2b5e0572b075c3b86e5ecfe82c8b76758f78 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 22 Jul 2021 09:04:03 -0600 Subject: [PATCH 3/4] Add restrictions to most commands, fix starboard to take url or id, closes #62 --- jarvis/cogs/ctc2.py | 2 ++ jarvis/cogs/dbrand.py | 12 ++++++++++++ jarvis/cogs/dev.py | 18 ++++++++++++++++++ jarvis/cogs/image.py | 1 + jarvis/cogs/jokes.py | 1 + jarvis/cogs/starboard.py | 3 +++ jarvis/cogs/util.py | 4 +++- jarvis/cogs/verify.py | 1 + 8 files changed, 41 insertions(+), 1 deletion(-) diff --git a/jarvis/cogs/ctc2.py b/jarvis/cogs/ctc2.py index bcd8fda..a3c195a 100644 --- a/jarvis/cogs/ctc2.py +++ b/jarvis/cogs/ctc2.py @@ -22,6 +22,7 @@ class CTCCog(commands.Cog): description="CTC2 related commands", guild_ids=guild_ids, ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _about(self, ctx): await ctx.send("See https://completethecode.com for more information") @@ -31,6 +32,7 @@ class CTCCog(commands.Cog): description="Guess a password for https://completethecodetwo.cards", guild_ids=guild_ids, ) + @commands.cooldown(1, 2, commands.BucketType.uer) async def _pw(self, ctx, guess: str): guessed = self.db.ctc2.guesses.find_one({"guess": guess}) if guessed: diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index 86d6216..6a4c22b 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -34,6 +34,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="See what skins are available", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _skin(self, ctx): await ctx.send(self.base_url + "shop/skins") @@ -43,6 +44,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Get some robot camo. Make Tony Stark proud", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _camo(self, ctx): await ctx.send(self.base_url + "shop/special-edition/robot-camo") @@ -52,6 +54,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="See devices with Grip support", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _grip(self, ctx): await ctx.send(self.base_url + "shop/grip/#grip-devices") @@ -61,6 +64,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Contact support", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _contact(self, ctx): await ctx.send( "Contact dbrand support here: " + self.base_url + "contact" @@ -72,6 +76,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Contact support", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _support(self, ctx): await ctx.send( "Contact dbrand support here: " + self.base_url + "contact" @@ -83,6 +88,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Get your order status", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _orderstat(self, ctx): await ctx.send(self.base_url + "order-status") @@ -92,6 +98,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Get your order status", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _orders(self, ctx): await ctx.send(self.base_url + "order-status") @@ -101,6 +108,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="dbrand status", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _status(self, ctx): await ctx.send(self.base_url + "status") @@ -110,6 +118,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="Give us your money!", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _buy(self, ctx): await ctx.send("Give us your money! " + self.base_url + "shop") @@ -119,6 +128,7 @@ class DbrandCog(commands.Cog): guild_ids=guild_ids, description="(not) extortion", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _extort(self, ctx): await ctx.send( "Be (not) extorted here: " + self.base_url + "not-extortion" @@ -130,6 +140,7 @@ class DbrandCog(commands.Cog): description="Robot Camo Wallpapers", guild_ids=guild_ids, ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _wallpapers(self, ctx): await ctx.send( "Get robot camo wallpapers here: https://db.io/wallpapers" @@ -152,6 +163,7 @@ class DbrandCog(commands.Cog): ) ], ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _shipping(self, ctx, *, search: str): await ctx.defer() if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE): diff --git a/jarvis/cogs/dev.py b/jarvis/cogs/dev.py index 9c02717..88a1c08 100644 --- a/jarvis/cogs/dev.py +++ b/jarvis/cogs/dev.py @@ -99,6 +99,7 @@ class DevCog(commands.Cog): await ctx.send(embed=embed) @commands.command(name="hash") + @commands.cooldown(1, 2, commands.BucketType.user) async def _hash_pref(self, ctx, method: str, *, data: str = None): await self._hash(ctx, method, data=data) @@ -106,6 +107,7 @@ class DevCog(commands.Cog): name="hash", description="Hash some data", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _hash_slash(self, ctx, method: str, *, data: str = None): await self._hash(ctx, method, data=data) @@ -135,6 +137,7 @@ class DevCog(commands.Cog): await ctx.send(f"UUID{version}: `{to_send}`") @commands.command(name="uuid") + @commands.cooldown(1, 2, commands.BucketType.user) async def _uuid_pref(self, ctx, version: str = None, data: str = None): await self._uuid(ctx, version, data) @@ -142,6 +145,7 @@ class DevCog(commands.Cog): name="uuid", description="Generate a UUID", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _uuid_slash(self, ctx, version: str = None, data: str = None): await self._uuid(ctx, version, data) @@ -150,6 +154,7 @@ class DevCog(commands.Cog): await ctx.send(f"ObjectId: `{str(ObjectId())}`") @commands.command(name="objectid") + @commands.cooldown(1, 2, commands.BucketType.user) async def _objectid_pref(self, ctx): await self._objectid(ctx) @@ -157,6 +162,7 @@ class DevCog(commands.Cog): name="objectid", description="Generate an ObjectID", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _objectid_slash(self, ctx): await self._objectid(ctx) @@ -165,6 +171,7 @@ class DevCog(commands.Cog): await ctx.send(f"ULID: `{ulid.new().str}`") @commands.command(name="ulid") + @commands.cooldown(1, 2, commands.BucketType.user) async def _ulid_pref(self, ctx): await self._ulid(ctx) @@ -172,6 +179,7 @@ class DevCog(commands.Cog): name="ulid", description="Generate a ULID", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _ulid_slash(self, ctx): await self._ulid(ctx) @@ -184,6 +192,7 @@ class DevCog(commands.Cog): await ctx.send("Invalid UUID") @commands.command(name="uuid2ulid") + @commands.cooldown(1, 2, commands.BucketType.user) async def _uuid2ulid_pref(self, ctx, u: str): await self._uuid2ulid(ctx, u) @@ -191,6 +200,7 @@ class DevCog(commands.Cog): name="uuid2ulid", description="Convert a UUID to a ULID", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _uuid2ulid_slash(self, ctx, u: str): await self._uuid2ulid(ctx, u) @@ -203,6 +213,7 @@ class DevCog(commands.Cog): await ctx.send("Invalid ULID.") @commands.command(name="ulid2uuid") + @commands.cooldown(1, 2, commands.BucketType.user) async def _ulid2uuid_pref(self, ctx, u): await self._ulid2uuid(ctx, u) @@ -210,6 +221,7 @@ class DevCog(commands.Cog): name="ulid2uuid", description="Convert a ULID to a UUID", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _ulid2uuid_slash(self, ctx, u): await self._ulid2uuid(ctx, u) @@ -229,6 +241,7 @@ class DevCog(commands.Cog): await ctx.send(f"`{method(data.encode('UTF-8')).decode('UTF-8')}`") @commands.command(name="encode") + @commands.cooldown(1, 2, commands.BucketType.user) async def _encode_pref(self, ctx, method: str, *, data: str): await self._encode(ctx, method, data) @@ -236,6 +249,7 @@ class DevCog(commands.Cog): name="encode", description="Encode using the base64 module", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _encode_slash(self, ctx, method: str, *, data: str): await self._encode(ctx, method, data) @@ -253,6 +267,7 @@ class DevCog(commands.Cog): await ctx.send(f"`{method(data.encode('UTF-8')).decode('UTF-8')}`") @commands.command(name="decode") + @commands.cooldown(1, 2, commands.BucketType.user) async def _decode_pref(self, ctx, method: str, *, data: str): await self._decode(ctx, method, data) @@ -260,6 +275,7 @@ class DevCog(commands.Cog): name="decode", description="Decode using the base64 module", ) + @commands.cooldown(1, 2, commands.BucketType.user) async def _decode_slash(self, ctx, method: str, *, data: str): await self._decode(ctx, method, data) @@ -270,6 +286,7 @@ class DevCog(commands.Cog): await ctx.send(f"```\n{output}\n```") @commands.command(name="cloc", help="Get J.A.R.V.I.S. lines of code") + @commands.cooldown(1, 30, commands.BucketType.channel) async def _cloc_pref(self, ctx): await self._cloc(ctx) @@ -277,6 +294,7 @@ class DevCog(commands.Cog): name="cloc", description="Get J.A.R.V.I.S. lines of code", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _cloc_slash(self, ctx): await ctx.defer() await self._cloc(ctx) diff --git a/jarvis/cogs/image.py b/jarvis/cogs/image.py index fc69cdb..b4ed580 100644 --- a/jarvis/cogs/image.py +++ b/jarvis/cogs/image.py @@ -104,6 +104,7 @@ class ImageCog(commands.Cog): ) @commands.command(name="resize", help="Resize an image") + @commands.cooldown(1, 60, commands.BucketType.user) async def _resize_pref(self, ctx, target: str, url: str = None): await self._resize(ctx, target, url) diff --git a/jarvis/cogs/jokes.py b/jarvis/cogs/jokes.py index f3b1fd7..c5db5ed 100644 --- a/jarvis/cogs/jokes.py +++ b/jarvis/cogs/jokes.py @@ -127,6 +127,7 @@ class JokeCog(commands.Cog): name="joke", description="Hear a joke", ) + @commands.cooldown(1, 10, commands.BucketType.channel) async def _joke_slash(self, ctx, id: str = None): await self._joke(ctx, id) diff --git a/jarvis/cogs/starboard.py b/jarvis/cogs/starboard.py index d2a95e3..a4b44f4 100644 --- a/jarvis/cogs/starboard.py +++ b/jarvis/cogs/starboard.py @@ -148,6 +148,9 @@ class StarboardCog(commands.Cog): ) return + if message.startswith("https://"): + message = message.split("/")[-1] + message = await channel.fetch_message(int(message)) exists = Star.get( diff --git a/jarvis/cogs/util.py b/jarvis/cogs/util.py index 9282ec1..809791f 100644 --- a/jarvis/cogs/util.py +++ b/jarvis/cogs/util.py @@ -27,6 +27,7 @@ class UtilCog(commands.Cog): name="status", description="Retrieve J.A.R.V.I.S. status", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _status(self, ctx): title = "J.A.R.V.I.S. Status" desc = "All systems online" @@ -52,6 +53,7 @@ class UtilCog(commands.Cog): name="logo", description="Get the current logo", ) + @commands.cooldown(1, 30, commands.BucketType.channel) async def _logo(self, ctx): lo = logo.get_logo(self.config.logo) await ctx.send(f"```\n{lo}\n```") @@ -92,7 +94,6 @@ class UtilCog(commands.Cog): @cog_ext.cog_slash( name="avatar", description="Get a user avatar", - guild_ids=[862402786116763668], options=[ create_option( name="user", @@ -102,6 +103,7 @@ class UtilCog(commands.Cog): ) ], ) + @commands.cooldown(1, 5, commands.BucketType.user) async def _avatar(self, ctx, user: User = None): if not user: user = ctx.author diff --git a/jarvis/cogs/verify.py b/jarvis/cogs/verify.py index 8391218..2465b4a 100644 --- a/jarvis/cogs/verify.py +++ b/jarvis/cogs/verify.py @@ -34,6 +34,7 @@ class VerifyCog(commands.Cog): name="verify", description="Verify that you've read the rules", ) + @commands.cooldown(1, 15, commands.BucketType.user) async def _verify(self, ctx: SlashContext): await ctx.defer() role = Setting.get(guild=ctx.guild.id, setting="verified") From f7289e82beddaa226737530be07844c59657466f Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 22 Jul 2021 09:06:31 -0600 Subject: [PATCH 4/4] Bump version to 1.2.0 --- jarvis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 7b47be6..37b1ff5 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -36,7 +36,7 @@ jarvis = commands.Bot( ) slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True) jarvis_self = Process() -__version__ = "1.1.1" +__version__ = "1.2.0" db = DBManager(get_config().mongo).mongo