From 40ab60fdf85f44b08f0a9316a22e1b0bef6e0646 Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 25 Jul 2022 23:14:27 +0100 Subject: Allow referencing message as argument to `!remind edit content` --- bot/exts/utils/reminders.py | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 45cddd7a2..f33a9f448 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -209,6 +209,29 @@ class Reminders(Cog): log.debug(f"Deleting reminder #{reminder['id']} (the user has been reminded).") await self.bot.api_client.delete(f"bot/reminders/{reminder['id']}") + @staticmethod + async def try_get_content_from_reply(ctx: Context) -> t.Optional[str]: + """ + Attempts to get content from the referenced message, if applicable. + + Differs from botcore.utils.commands.clean_text_or_reply as allows for embeds. + """ + content = None + if reference := ctx.message.reference: + if isinstance((resolved_message := reference.resolved), discord.Message): + content = resolved_message.content + + # If we weren't able to get the content of a replied message + if content is None: + await send_denial(ctx, "Your reminder must have a content and/or reply to a message.") + return + + # If the replied message has no content (e.g. only attachments/embeds) + if content == "": + content = "See referenced message." + + return content + @group(name="remind", aliases=("reminder", "reminders", "remindme"), invoke_without_command=True) async def remind_group( self, ctx: Context, mentions: Greedy[ReminderMention], expiration: Duration, *, content: t.Optional[str] = None @@ -282,18 +305,11 @@ class Reminders(Cog): # If `content` isn't provided then we try to get message content of a replied message if not content: - if reference := ctx.message.reference: - if isinstance((resolved_message := reference.resolved), discord.Message): - content = resolved_message.content - # If we weren't able to get the content of a replied message - if content is None: - await send_denial(ctx, "Your reminder must have a content and/or reply to a message.") + content = await self.try_get_content_from_reply(ctx) + if not content: + # Couldn't get content from reply return - # If the replied message has no content (e.g. only attachments/embeds) - if content == "": - content = "See referenced message." - # Now we can attempt to actually set the reminder. reminder = await self.bot.api_client.post( 'bot/reminders', @@ -417,8 +433,13 @@ class Reminders(Cog): await self.edit_reminder(ctx, id_, {'expiration': expiration.isoformat()}) @edit_reminder_group.command(name="content", aliases=("reason",)) - async def edit_reminder_content(self, ctx: Context, id_: int, *, content: str) -> None: + async def edit_reminder_content(self, ctx: Context, id_: int, *, content: t.Optional[str] = None) -> None: """Edit one of your reminder's content.""" + if not content: + content = await self.try_get_content_from_reply(ctx) + if not content: + # Couldn't get content from reply + return await self.edit_reminder(ctx, id_, {"content": content}) @edit_reminder_group.command(name="mentions", aliases=("pings",)) -- cgit v1.2.3 From 0f4bc18ceb5ef5e55e003da409a3da8e3e1d9cf8 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 4 Aug 2022 14:54:09 +0100 Subject: Disable nose plugin in pytest This fixes an issue with pytest running functions called setup in test files when they shouldn't be run --- pyproject.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 77d8ee3d4..255710386 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,3 +84,9 @@ case_sensitive = true combine_as_imports = true line_length = 120 atomic = true + +[tool.pytest.ini_options] +# We don't use nose style tests so disable them in pytest. +# This stops pytest from running functions named `setup` in test files. +# See https://github.com/python-discord/bot/pull/2229#issuecomment-1204436420 +addopts = "-p no:nose" -- cgit v1.2.3 From 29d882065e12f9a042b14d6dfaf3161af215c953 Mon Sep 17 00:00:00 2001 From: Izan Date: Sat, 6 Aug 2022 15:49:02 +0100 Subject: Make reference message in reminders italic. --- bot/exts/utils/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index f33a9f448..f0da37f3b 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -228,7 +228,7 @@ class Reminders(Cog): # If the replied message has no content (e.g. only attachments/embeds) if content == "": - content = "See referenced message." + content = "*See referenced message.*" return content -- cgit v1.2.3 From 350df44731875c4e8b28fc509d83b431cfefbc5c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 1 Sep 2022 21:31:33 +0100 Subject: Use venvs with poetry in Dockerfile This is required due to a regression in poetry, see https://github.com/HassanAbouelela/actions/pull/7 --- Dockerfile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5bb400658..20b099a0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,26 @@ FROM --platform=linux/amd64 python:3.10-slim # Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=false \ - POETRY_VIRTUALENVS_CREATE=false +ENV PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + POETRY_VERSION=1.1.15 \ + POETRY_HOME="/opt/poetry" \ + POETRY_VIRTUALENVS_IN_PROJECT=true \ + POETRY_NO_INTERACTION=1 \ + INSTALL_DIR="/opt/dependencies" \ + APP_DIR="/bot" +ENV PATH="$POETRY_HOME/bin:/$INSTALL_DIR/.venv/bin:$PATH" -# Install poetry -RUN pip install -U poetry +RUN apt-get update \ + && apt-get -y upgrade \ + && apt-get install --no-install-recommends -y curl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* -# Create the working directory -WORKDIR /bot +RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies +WORKDIR $INSTALL_DIR COPY pyproject.toml poetry.lock ./ RUN poetry install --no-dev @@ -22,6 +31,7 @@ ARG git_sha="development" ENV GIT_SHA=$git_sha # Copy the source code in last to optimize rebuilding the image +WORKDIR $APP_DIR COPY . . ENTRYPOINT ["python3"] -- cgit v1.2.3 From e12e5911f971beae0c07c12f9cf632bbaf4e6629 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 1 Sep 2022 21:31:59 +0100 Subject: Use HassanAbouelela/setup-python for CI --- .github/workflows/lint-test.yml | 62 ++++------------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 2b3dd5b4f..a331659e6 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -33,57 +33,16 @@ jobs: REDDIT_SECRET: ham REDIS_PASSWORD: '' - # Configure pip to cache dependencies and do a user install - PIP_NO_CACHE_DIR: false - PIP_USER: 1 - - # Make sure package manager does not use virtualenv - POETRY_VIRTUALENVS_CREATE: false - - # Specify explicit paths for python dependencies and the pre-commit - # environment so we know which directories to cache - POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base - PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base - PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache - - # See https://github.com/pre-commit/pre-commit/issues/2178#issuecomment-1002163763 - # for why we set this. - SETUPTOOLS_USE_DISTUTILS: stdlib - steps: - - name: Add custom PYTHONUSERBASE to PATH - run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH - - name: Checkout repository uses: actions/checkout@v2 - - name: Setup python - id: python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - # This step caches our Python dependencies. To make sure we - # only restore a cache when the dependencies, the python version, - # the runner operating system, and the dependency location haven't - # changed, we create a cache key that is a composite of those states. - # - # Only when the context is exactly the same, we will restore the cache. - - name: Python Dependency Caching - uses: actions/cache@v2 - id: python_cache + - name: Install Python Dependencies + uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1 with: - path: ${{ env.PYTHONUSERBASE }} - key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\ - ${{ steps.python.outputs.python-version }}-\ - ${{ hashFiles('./pyproject.toml', './poetry.lock') }}" - - # Install our dependencies if we did not restore a dependency cache - - name: Install dependencies using poetry - if: steps.python_cache.outputs.cache-hit != 'true' - run: | - pip install poetry - poetry install + # Set dev=true to install flake8 extensions, which are dev dependencies + dev: true + python_version: '3.10' # Check all of our non-dev dependencies are compatible with the MIT license. # If you added a new dependencies that is being rejected, @@ -94,17 +53,6 @@ jobs: pip-licenses --allow-only="$ALLOWED_LICENSE" \ --package $(poetry export -f requirements.txt --without-hashes | sed "s/==.*//g" | tr "\n" " ") - # This step caches our pre-commit environment. To make sure we - # do create a new environment when our pre-commit setup changes, - # we create a cache key based on relevant factors. - - name: Pre-commit Environment Caching - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\ - ${{ steps.python.outputs.python-version }}-\ - ${{ hashFiles('./.pre-commit-config.yaml') }}" - # We will not run `flake8` here, as we will use a separate flake8 # action. As pre-commit does not support user installs, we set # PIP_USER=0 to not do a user install. -- cgit v1.2.3 From 0b495e757c909d6a5802ffa729cdc9d3e4069978 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 10 Sep 2022 19:57:16 +0100 Subject: Bump poetry in Docker and lint to 1.2.0 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 20b099a0b..d0687475e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM --platform=linux/amd64 python:3.10-slim # Set pip to have no saved cache ENV PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=on \ - POETRY_VERSION=1.1.15 \ + POETRY_VERSION=1.2.0 \ POETRY_HOME="/opt/poetry" \ POETRY_VIRTUALENVS_IN_PROJECT=true \ POETRY_NO_INTERACTION=1 \ -- cgit v1.2.3 From 03a3a03d39099b09ed62337b075a9ada43353144 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 12 Sep 2022 21:37:04 +0100 Subject: Don't use fake in-project venvs for poetry Instead let poetry install the venv for the project in the right place, leading to a more 'traditional' poetry setup. --- Dockerfile | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0687475e..9cf9c7b27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,15 @@ FROM --platform=linux/amd64 python:3.10-slim -# Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=1 \ - PIP_DISABLE_PIP_VERSION_CHECK=on \ - POETRY_VERSION=1.2.0 \ - POETRY_HOME="/opt/poetry" \ - POETRY_VIRTUALENVS_IN_PROJECT=true \ - POETRY_NO_INTERACTION=1 \ - INSTALL_DIR="/opt/dependencies" \ - APP_DIR="/bot" - -ENV PATH="$POETRY_HOME/bin:/$INSTALL_DIR/.venv/bin:$PATH" +# Define Git SHA build argument for sentry +ARG git_sha="development" + +ENV POETRY_VERSION=1.2.0 \ + POETRY_HOME="/opt/poetry" \ + POETRY_NO_INTERACTION=1 \ + APP_DIR="/bot" \ + GIT_SHA=$git_sha + +ENV PATH="$POETRY_HOME/bin:$PATH" RUN apt-get update \ && apt-get -y upgrade \ @@ -20,19 +19,12 @@ RUN apt-get update \ RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies -WORKDIR $INSTALL_DIR +WORKDIR $APP_DIR COPY pyproject.toml poetry.lock ./ RUN poetry install --no-dev -# Define Git SHA build argument -ARG git_sha="development" - -# Set Git SHA environment variable for Sentry -ENV GIT_SHA=$git_sha - # Copy the source code in last to optimize rebuilding the image -WORKDIR $APP_DIR COPY . . -ENTRYPOINT ["python3"] -CMD ["-m", "bot"] +ENTRYPOINT ["poetry"] +CMD ["run", "python", "-m", "bot"] -- cgit v1.2.3 From 71b1802b0f91b855443fa5ed01d9134944fd6f38 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 13 Sep 2022 00:25:36 +0100 Subject: Ignore mounted in-project venvs on startup Poetry's virtualenvs.in-project config deafults to None, meaning it will use in-project venvs if it finds one, otherwise it will use the cache dir. In dev we mount the entire root project directory to /bot. This means if the host's venv in in the project dir, this will get mounted and prioritised by poetry run. If the host is on a non-linux OS this will cause poetry to fail to boot. --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9cf9c7b27..da65bbf3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,12 @@ FROM --platform=linux/amd64 python:3.10-slim # Define Git SHA build argument for sentry ARG git_sha="development" +# POETRY_VIRTUALENVS_IN_PROJECT is required to ensure in-projects venvs mounted from the host in dev +# don't get prioritised by `poetry run` ENV POETRY_VERSION=1.2.0 \ POETRY_HOME="/opt/poetry" \ POETRY_NO_INTERACTION=1 \ + POETRY_VIRTUALENVS_IN_PROJECT=false \ APP_DIR="/bot" \ GIT_SHA=$git_sha @@ -21,7 +24,7 @@ RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies WORKDIR $APP_DIR COPY pyproject.toml poetry.lock ./ -RUN poetry install --no-dev +RUN poetry install --without dev # Copy the source code in last to optimize rebuilding the image COPY . . -- cgit v1.2.3 From 2db6a241bde75e6cd36f3fe0f32a3530187a827a Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 13 Sep 2022 00:27:53 +0100 Subject: Specify the path for poetry venvs Without this the venv would be created in /root/.cache and the nonn-root user that prod runs under would not have access to it. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index da65bbf3b..65ca8ce51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ ARG git_sha="development" # POETRY_VIRTUALENVS_IN_PROJECT is required to ensure in-projects venvs mounted from the host in dev # don't get prioritised by `poetry run` ENV POETRY_VERSION=1.2.0 \ - POETRY_HOME="/opt/poetry" \ + POETRY_HOME="/opt/poetry/home" \ + POETRY_CACHE_DIR="/opt/poetry/cache" \ POETRY_NO_INTERACTION=1 \ POETRY_VIRTUALENVS_IN_PROJECT=false \ APP_DIR="/bot" \ -- cgit v1.2.3 From 9c85342f4449f2116fb36ee1500ad06a94c1e14c Mon Sep 17 00:00:00 2001 From: Izan Date: Wed, 14 Sep 2022 20:56:30 +0100 Subject: Update docstrings & comment. --- bot/exts/utils/reminders.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index f0da37f3b..c65785314 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -214,7 +214,7 @@ class Reminders(Cog): """ Attempts to get content from the referenced message, if applicable. - Differs from botcore.utils.commands.clean_text_or_reply as allows for embeds. + Differs from botcore.utils.commands.clean_text_or_reply as allows for messages with no content. """ content = None if reference := ctx.message.reference: @@ -398,20 +398,7 @@ class Reminders(Cog): @remind_group.group(name="edit", aliases=("change", "modify"), invoke_without_command=True) async def edit_reminder_group(self, ctx: Context) -> None: - """ - Commands for modifying your current reminders. - - The `expiration` duration supports the following symbols for each unit of time: - - years: `Y`, `y`, `year`, `years` - - months: `m`, `month`, `months` - - weeks: `w`, `W`, `week`, `weeks` - - days: `d`, `D`, `day`, `days` - - hours: `H`, `h`, `hour`, `hours` - - minutes: `M`, `minute`, `minutes` - - seconds: `S`, `s`, `second`, `seconds` - - For example, to edit a reminder to expire in 3 days and 1 minute, you can do `!remind edit duration 1234 3d1M`. - """ + """Commands for modifying your current reminders.""" await ctx.send_help(ctx.command) @edit_reminder_group.command(name="duration", aliases=("time",)) @@ -434,11 +421,15 @@ class Reminders(Cog): @edit_reminder_group.command(name="content", aliases=("reason",)) async def edit_reminder_content(self, ctx: Context, id_: int, *, content: t.Optional[str] = None) -> None: - """Edit one of your reminder's content.""" + """ + Edit one of your reminder's content. + + You can either supply the new content yourself, or reply to a message to use its content. + """ if not content: content = await self.try_get_content_from_reply(ctx) if not content: - # Couldn't get content from reply + # Message doesn't have a reply to get content from return await self.edit_reminder(ctx, id_, {"content": content}) -- cgit v1.2.3 From 8028690d4eae27e57dfe1429b8067eabaa94eef9 Mon Sep 17 00:00:00 2001 From: Aleksey Zasorin Date: Fri, 16 Sep 2022 10:42:16 -0700 Subject: Removed "redis_ready" from additional_spec_asyncs in MockBot (#2275) The attribute was removed from Bot in fc05849 --- tests/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/helpers.py b/tests/helpers.py index 687e15b96..a4b919dcb 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -317,7 +317,7 @@ class MockBot(CustomMockMixin, unittest.mock.MagicMock): guild_id=1, intents=discord.Intents.all(), ) - additional_spec_asyncs = ("wait_for", "redis_ready") + additional_spec_asyncs = ("wait_for",) def __init__(self, **kwargs) -> None: super().__init__(**kwargs) -- cgit v1.2.3 From 343858f55ab8cbb482c70b8ffd3c8e48ab35d3b1 Mon Sep 17 00:00:00 2001 From: Mohammad Ibrahim <74553450+Ibrahim2750mi@users.noreply.github.com> Date: Sat, 17 Sep 2022 18:28:48 +0530 Subject: Removed italics from the help command (#2272) * removed asterisk from embed description * removed italics from line 334, 375 and 415 * pagination.py, L239 added italics --- bot/exts/info/help.py | 8 ++++---- bot/pagination.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/exts/info/help.py b/bot/exts/info/help.py index 282f8c97a..48f840e51 100644 --- a/bot/exts/info/help.py +++ b/bot/exts/info/help.py @@ -307,7 +307,7 @@ class CustomHelpCommand(HelpCommand): # Remove line breaks from docstrings, if not used to separate paragraphs. # Allow overriding this behaviour via putting \u2003 at the start of a line. formatted_doc = re.sub("(? Date: Sun, 18 Sep 2022 02:07:12 +0400 Subject: Use Python Poetry Base Action (#2277) --- Dockerfile | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65ca8ce51..205b66209 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,11 @@ -FROM --platform=linux/amd64 python:3.10-slim +FROM --platform=linux/amd64 ghcr.io/chrislovering/python-poetry-base:3.10-slim # Define Git SHA build argument for sentry ARG git_sha="development" - -# POETRY_VIRTUALENVS_IN_PROJECT is required to ensure in-projects venvs mounted from the host in dev -# don't get prioritised by `poetry run` -ENV POETRY_VERSION=1.2.0 \ - POETRY_HOME="/opt/poetry/home" \ - POETRY_CACHE_DIR="/opt/poetry/cache" \ - POETRY_NO_INTERACTION=1 \ - POETRY_VIRTUALENVS_IN_PROJECT=false \ - APP_DIR="/bot" \ - GIT_SHA=$git_sha - -ENV PATH="$POETRY_HOME/bin:$PATH" - -RUN apt-get update \ - && apt-get -y upgrade \ - && apt-get install --no-install-recommends -y curl \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -RUN curl -sSL https://install.python-poetry.org | python +ENV GIT_SHA=$git_sha # Install project dependencies -WORKDIR $APP_DIR +WORKDIR /bot COPY pyproject.toml poetry.lock ./ RUN poetry install --without dev -- cgit v1.2.3