From dfbd6c30ab26713e313b48e15a13c077fb519cfb Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Mon, 3 Jun 2024 08:39:30 -0700 Subject: [PATCH] Implement bot PoC using slack-machine --- .github/workflows/ci-cd.yaml | 28 ++++++++++++++++++++++++++++ .gitignore | 7 ++++++- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ .secrets.sample | 2 ++ README.md | 7 +++++++ manifest.yaml | 25 +++++++++++++++++++++++++ poetry.lock | 32 ++++++++++++++++++++++++++++++-- pyproject.toml | 3 +++ src/__init__.py | 0 src/local_settings.py | 8 ++++++++ src/sammich/__init__.py | 0 src/sammich/plugins/__init__.py | 0 src/sammich/plugins/demo.py | 10 ++++++++++ 13 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci-cd.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .secrets.sample create mode 100644 manifest.yaml create mode 100644 src/__init__.py create mode 100644 src/local_settings.py create mode 100644 src/sammich/__init__.py create mode 100644 src/sammich/plugins/__init__.py create mode 100644 src/sammich/plugins/demo.py diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml new file mode 100644 index 0000000..88a4b2b --- /dev/null +++ b/.github/workflows/ci-cd.yaml @@ -0,0 +1,28 @@ +name: CI/CD +on: + - merge_group + - pull_request + - push + - workflow_dispatch + +env: + FORCE_COLOR: 1 + +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + +jobs: + pre-commit: + name: Run pre-commit + runs-on: ubuntu-latest + steps: + - name: Check out Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index 745d717..b782ec5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ -local_settings.py \ No newline at end of file +__pycache__ +.env +.ruff_cache +.secrets +.venv +*.code-workspace diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..fe64b05 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-ast + - id: check-builtin-literals + - id: check-yaml + - id: fix-encoding-pragma + args: + - --remove + - id: mixed-line-ending + args: + - --fix=lf + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + exclude: ^(docs) + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.13 + hooks: + - id: ruff + args: + - --fix + - id: ruff-format diff --git a/.secrets.sample b/.secrets.sample new file mode 100644 index 0000000..ad46f8e --- /dev/null +++ b/.secrets.sample @@ -0,0 +1,2 @@ +SLACK_APP_TOKEN=xapp-token +SLACK_BOT_TOKEN=xoxb-token \ No newline at end of file diff --git a/README.md b/README.md index f227ee3..5a6ec26 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # BLT-Sammich + The Slack bot for BLT + +## Development + +`poetry install` + +`poetry run slack-machine` diff --git a/manifest.yaml b/manifest.yaml new file mode 100644 index 0000000..607e113 --- /dev/null +++ b/manifest.yaml @@ -0,0 +1,25 @@ +display_information: + name: Sammich Dev +features: + bot_user: + display_name: Sammich Dev + always_online: false + slash_commands: + - command: /demo + description: Show demo output + should_escape: false +oauth_config: + scopes: + bot: + - channels:read + - commands + - groups:read + - im:read + - mpim:read + - users:read +settings: + interactivity: + is_enabled: true + org_deploy_enabled: false + socket_mode_enabled: true + token_rotation_enabled: false diff --git a/poetry.lock b/poetry.lock index 1c76008..57f750a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohttp" @@ -400,6 +400,20 @@ files = [ {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, ] +[[package]] +name = "holidays" +version = "0.49" +description = "Generate and work with holidays in Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "holidays-0.49-py3-none-any.whl", hash = "sha256:7e7ae47477d675c093bd77ae64c13f8e8d0027db5803b19cba446ede285d59f6"}, + {file = "holidays-0.49.tar.gz", hash = "sha256:c8209d8b7815fbe1e6b95c87b944115f787f6ad3496e11c242ff0b447425539c"}, +] + +[package.dependencies] +python-dateutil = "*" + [[package]] name = "httpcore" version = "1.0.5" @@ -779,6 +793,20 @@ typing-extensions = "*" [package.extras] dev = ["black", "build", "flake8", "flake8-black", "isort", "jupyter-console", "mkdocs", "mkdocs-include-markdown-plugin", "mkdocstrings[python]", "pytest", "pytest-asyncio", "pytest-trio", "sphinx", "toml", "tox", "trio", "trio", "trio-typing", "twine", "twisted", "validate-pyproject[all]"] +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, + {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "python-dotenv" version = "1.0.1" @@ -1073,4 +1101,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "33c9851ed2844d453cbb8be03f9c2e33e747628b97192874d5035fe11624aa2a" +content-hash = "a611b229c26036e449ab57174b7cab950d12ff1650bf81d3fc469d4bbcb0e5ab" diff --git a/pyproject.toml b/pyproject.toml index 97bc538..67262b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,8 @@ description = "" authors = ["Sarthak5598 "] readme = "README.md" +packages = [{ include = "sammich", from = "src" }] + [tool.poetry.dependencies] python = "^3.11" slack-machine = "^0.37.0" @@ -12,6 +14,7 @@ python-dotenv = "^1.0.1" gitpython = "^3.1.43" slack-sdk = "^3.27.2" slackeventsapi = "^3.0.1" +holidays = "^0.49" [build-system] diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/local_settings.py b/src/local_settings.py new file mode 100644 index 0000000..97ff9bc --- /dev/null +++ b/src/local_settings.py @@ -0,0 +1,8 @@ +from dotenv import dotenv_values + +secrets = dotenv_values(".secrets") + +SLACK_APP_TOKEN = secrets["SLACK_APP_TOKEN"] +SLACK_BOT_TOKEN = secrets["SLACK_BOT_TOKEN"] + +PLUGINS = ("sammich.plugins.demo.DemoPlugin",) diff --git a/src/sammich/__init__.py b/src/sammich/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/sammich/plugins/__init__.py b/src/sammich/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/sammich/plugins/demo.py b/src/sammich/plugins/demo.py new file mode 100644 index 0000000..f175a9e --- /dev/null +++ b/src/sammich/plugins/demo.py @@ -0,0 +1,10 @@ +from machine.plugins.base import MachineBasePlugin +from machine.plugins.decorators import command + + +class DemoPlugin(MachineBasePlugin): + """Demo plugin""" + + @command("/demo") + async def demo(self, command): + await command.say("This is a demo response!")