diff --git a/screenshot/common/utils.py b/screenshot/common/utils.py index 10504e4..2d4932e 100644 --- a/screenshot/common/utils.py +++ b/screenshot/common/utils.py @@ -50,8 +50,8 @@ async def send_notification(cog: "Screenshot") -> None: "If you already have a tor browser install and wish to use a separate instance of the tor protocol " "you can do so by leveraging the docker file given below.\n\n" "Finally to activate the tor protocol within the cog run the following commands if needed -\n" - "- `[p]screenshot tor ` to make the cog actually use the tor protocol.\n" - "- `[p]screenshot tor port ` to change the default port to use the one configured by you.\n\n" + "- `[p]screenset tor ` to make the cog actually use the tor protocol.\n" + "- `[p]screenset tor port ` to change the default port to use the one configured by you.\n\n" "-# *You'll keep receiving this message everytime you load/reload the cog if you don't configure tor.*" ).format( ( diff --git a/screenshot/core.py b/screenshot/core.py index b6f3267..b18c0b5 100644 --- a/screenshot/core.py +++ b/screenshot/core.py @@ -59,7 +59,7 @@ class Screenshot(commands.Cog): __author__: Final[List[str]] = ["inthedark.org"] CACHE: Dict[str, Union[bool, int, Optional[str]]] = { - "toggle": True, + "toggle": False, "port": 9050, "updated": False, } @@ -108,6 +108,7 @@ async def update_counter_api(self) -> None: self.__class__.__name__.lower() ) ) + await self.config.updated.set(True) @tasks.loop(minutes=5.0, reconnect=True, name="red:seina:screenshot") async def bg_task(self) -> None: @@ -117,6 +118,37 @@ async def bg_task(self) -> None: async def bg_task_before_loop(self) -> None: await self.manager.wait_until_driver_downloaded() + @commands.is_owner() + @commands.group(name="screenshotset", aliases=["screenset"]) + async def screenshot_set(self, _: commands.Context): + """Configuration commands for screenshot.""" + + @screenshot_set.group(name="tor", invoke_without_command=True) # type: ignore + async def screenshot_set_tor(self, ctx: commands.Context, toggle: bool): + """ + Enable or disable tor proxy when taking screenshots. + """ + if not ctx.invoked_subcommand: + await self.config.toggle.set(toggle) + await ctx.tick() + + @screenshot_set_tor.command(name="port") # type: ignore + async def screenshot_set_tor_port( + self, ctx: commands.Context, port: commands.Range[int, 1, 5] + ): + """ + Change the default port of the tor protocol. + """ + if port > 65535: + await ctx.send( + "The maximum supported port is '65535' got '{}' instead.".format(port), + reference=ctx.message.to_reference(fail_if_not_exists=False), + allowed_mentions=discord.AllowedMentions(replied_user=False), + ) + raise commands.CheckFailure() + await self.config.port(port) + await ctx.tick() + @commands.command() @commands.cooldown(1, 60, commands.BucketType.user) @commands.has_permissions(attach_files=True, embed_links=True)