Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Groundwork for list submissions command (#483)
Browse files Browse the repository at this point in the history
* ⬆️ update dependencies

* 🚧 add first stages of submission list command
  • Loading branch information
itsthejoker authored May 14, 2023
1 parent 092fc2b commit a97f1e0
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ clean:

shiv:
mkdir -p build
poetry run shiv -c blossom -o build/blossom.pyz . --compressed
poetry run shiv --preamble blossom/preamble.py -c blossom -o build/blossom.pyz . --compressed
3 changes: 3 additions & 0 deletions blossom/api/slack/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from blossom.api.slack import client
from blossom.api.slack.actions.report import process_submission_report_update
from blossom.api.slack.actions.unclaim import process_unclaim_action
from blossom.api.slack.commands.list_submissions import _process_submission_list
from blossom.api.slack.commands.migrate_user import process_migrate_user
from blossom.api.slack.transcription_check.actions import process_check_action
from blossom.strings import translation
Expand All @@ -33,6 +34,8 @@ def process_action(data: Dict) -> None:
elif "migration" in value:
# buttons related to account gamma migrations
process_migrate_user(data)
elif "submission_list_" in value:
_process_submission_list(data)
else:
client.chat_postMessage(
channel=data["channel"]["id"],
Expand Down
2 changes: 2 additions & 0 deletions blossom/api/slack/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from blossom.api.slack.commands.dadjoke import dadjoke_cmd
from blossom.api.slack.commands.help import help_cmd
from blossom.api.slack.commands.info import info_cmd
from blossom.api.slack.commands.list_submissions import submissions_cmd
from blossom.api.slack.commands.migrate_user import migrate_user_cmd
from blossom.api.slack.commands.ping import ping_cmd
from blossom.api.slack.commands.reset import reset_cmd
Expand Down Expand Up @@ -69,6 +70,7 @@ def process_command(data: Dict) -> None:
"watchlist": watchlist_cmd,
"watchstatus": watchstatus_cmd,
"unclaim": unclaim_cmd,
"submissions": submissions_cmd,
}

tokens = message.split()
Expand Down
74 changes: 74 additions & 0 deletions blossom/api/slack/commands/list_submissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import zoneinfo
from datetime import datetime
from uuid import uuid4

from slack.web.classes.blocks import *
from slack.web.classes.elements import *
from slack.web.classes.views import View

from blossom.api.slack import client
from blossom.strings import translation

i18n = translation()


def _build_message() -> View:
"""Create the modal view that will display in Slack.
Action IDs:
* submission_list_username_input
* submission_list_select_start_date
* submission_list_select_end_date
"""
return View(
type="modal",
title="Get Submissions",
submit=PlainTextObject(text="Submit"),
close=PlainTextObject(text="Close"),
blocks=[
SectionBlock(
fields=[
TextObject(
type="mrkdwn",
text=(
"Select the date range to search for transcriptions in. Keep in mind"
" that if your date range is too big, there might be a lot of returned"
" transcriptions."
),
)
]
),
InputBlock(
label="Username",
element=PlainTextInputElement(
placeholder="itsthejoker", action_id="submission_list_username_input"
),
),
SectionBlock(
accessory=DatePickerElement(
initial_date="2017-04-01",
placeholder=PlainTextObject(text="Start Date:"),
action_id="submission_list_select_start_date",
)
),
SectionBlock(
accessory=DatePickerElement(
initial_date=datetime.now(tz=zoneinfo.ZoneInfo("UTC")).strftime("%Y-%m-%d"),
placeholder=PlainTextObject(text="End Date:"),
action_id="submission_list_select_end_date",
)
),
],
)


def _process_submission_list(data: dict) -> None:
from pprint import pprint

pprint(data)


def submissions_cmd(channel: str, _message: str) -> None:
"""Get information from a date range about submissions of a user."""
client.views_open(trigger_id=uuid4(), view=_build_message())
25 changes: 25 additions & 0 deletions blossom/preamble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
# https://shiv.readthedocs.io/en/latest/#preamble
import os
import shutil
from pathlib import Path

# These variables are injected by shiv.bootstrap
site_packages: Path
env: "shiv.bootstrap.environment.Environment"

# Get a handle of the current PYZ's site_packages directory
current = site_packages.parent

# The parent directory of the site_packages directory is our shiv cache
cache_path = current.parent


name, build_id = current.name.split("_")

if __name__ == "__main__":
for path in cache_path.iterdir():
if path.name.startswith(f"{name}_") and not path.name.endswith(build_id):
shutil.rmtree(path)
if path.name.startswith(f".{name}") and not path.name.endswith(f"{build_id}_lock"):
os.remove(path)
1 change: 1 addition & 0 deletions blossom/strings/en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Help is on the way!
`@Blossom info <username>`: Get information about a user.
`@Blossom migrate <source> <target>`: Creates a request to migrate the gamma count of the source to the target. Needs verification.
`@Blossom reset <username>`: Toggle CoC status of user.
`@Blossom submissions`: Get all submissions from a given date range.
`@Blossom unclaim <url>`: Forcibly unclaim the post with the given Reddit URL from the user.
`@Blossom unwatch <username>`: Reset check percentage.
`@Blossom warnings <username>`: Get the warnings of a given user.
Expand Down
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a97f1e0

Please sign in to comment.