commit b25cd86314cea803b537c559a1a4f844513354d3 Author: Benjamyn Love Date: Fri Sep 29 18:28:01 2023 +1000 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e90a40 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*secret diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d99f2f3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..0757494 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.11" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..54a7078 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "ed6d5d614626ae28e274e453164affb26694755170ccab3aa5866f093d51d3e4" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.11" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/images/lmao.png b/images/lmao.png new file mode 100644 index 0000000..0fccc9d Binary files /dev/null and b/images/lmao.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..9761bdf --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +import slack +from flask import Flask +from slackeventsapi import SlackEventAdapter +from pprint import pprint + +with open(".slacksecret") as f: + SLACK_TOKEN = f.read().strip() + +with open(".slacksigningsecret") as f: + SIGNING_SECRET = f.read().strip() + +app = Flask(__name__) +slack_event_adapter = SlackEventAdapter(SIGNING_SECRET, "/slack/events", app) + +client = slack.WebClient(token=SLACK_TOKEN) + + +@slack_event_adapter.on("message") +def message(payload): + pprint(payload) + event = payload.get("event", {}) + channel_id = event.get("channel") + user_id = event.get("uesr") + text = event.get("text") + + if text == "cn": + client.chat_postMessage( + channel=channel_id, + text="Don't get me started on them! :coff:", + ) + + # if text == "image": + # try: + # response = client.files_upload( + # file="./images/lmao.png", + # initial_comment="I can read the chat messages", + # channels=channel_id, + # ) + # except slack.SlackApiError as e: + # assert e.response["ok"] is False + # assert e.response["error"] + # print(f"Got an error: {e.response['error']}") + + +if __name__ == "__main__": + app.run(debug=True, host="0.0.0.0")