Skip to content

Commit

Permalink
[Screenshot] add config commands and fix counter
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Sep 19, 2024
1 parent 6a2a8c0 commit 6249f62
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions screenshot/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <true_or_false>` to make the cog actually use the tor protocol.\n"
"- `[p]screenshot tor port <YOUR-PORT>` to change the default port to use the one configured by you.\n\n"
"- `[p]screenset tor <true_or_false>` to make the cog actually use the tor protocol.\n"
"- `[p]screenset tor port <YOUR-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(
(
Expand Down
34 changes: 33 additions & 1 deletion screenshot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 6249f62

Please sign in to comment.